'Upload a file to Pootle'

def upload(self, lang_code, filename):

    import mechanize
    import re
    br = mechanize.Browser()
    br.addheaders = [('User-agent', 'Firefox')]
    br.set_handle_equiv(False)
    br.set_handle_robots(False)
    br.set_handle_referer(False)
    settings = current.deployment_settings
    username = settings.get_L10n_pootle_username()
    if (username is False):
        current.log.error('No    login    information    found')
        return
    pootle_url = settings.get_L10n_pootle_url()
    login_url = ('%saccounts/login' % pootle_url)
    try:
        br.open(login_url)
    except:
        current.log.error('Connecton    Error')
        return
    br.select_form('loginform')
    br.form['username'] = username
    br.form['password'] = settings.get_L10n_pootle_password()
    br.submit()
    current_url = br.geturl()
    if current_url.endswith('login/'):
        current.log.error('Login    Error')
        return
    pattern = ('<option    value=(.+?)>%s.po' % lang_code)
    if (len(lang_code) > 2):
        lang_code = ('%s_%s' % (lang_code[:2], lang_code[(-2):].upper()))
    link = ('%s%s/eden/' % (pootle_url, lang_code))
    page_source = br.open(link).read()
    regex = re.search(pattern, page_source)
    result = regex.group(0)
    result = re.split('[="]', result)
    upload_code = result[2]
    try:
        br.select_form('uploadform')
        br.form.find_control(name='overwrite').value = ['overwrite']
        br.form.find_control(name='upload_to').value = [upload_code]
        br.form.add_file(open(filename), 'text/plain', file_name)
        br.submit()
    except:
        current.log.error('Error    in    Uploading    form')
        return
