misc: remove unused proxy support (#6225)

This commit is contained in:
Frédéric Péters 2015-01-01 20:20:11 +01:00
parent 813a66a2c8
commit b90932e366
2 changed files with 15 additions and 72 deletions

View File

@ -94,37 +94,6 @@ class SettingsDirectory(AccessControlled, Directory):
cfg_submit(form, 'language', ['language'])
return redirect('.')
def proxy(self):
form = Form(enctype='multipart/form-data')
proxy_cfg = get_cfg('proxy', {})
form.add(CheckboxWidget, 'enabled', title = _('Use a web proxy'),
value = proxy_cfg.get(str('enabled'), False))
form.add(StringWidget, 'ip', title = _('Proxy IP address or domain name'),
value = proxy_cfg.get(str('ip')))
form.add(StringWidget, 'port', title = _('Proxy port'),
value = proxy_cfg.get(str('port')))
form.add(StringWidget, 'user', title = _('User name'),
value = proxy_cfg.get(str('user')))
form.add(PasswordWidget, 'password', title = _('User password'),
value = proxy_cfg.get(str('password')))
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect('.')
if not form.is_submitted() or form.has_errors():
get_response().breadcrumb.append(('proxy', _('Proxy')))
html_top('settings', title = _('Proxy'))
r = TemplateIO(html=True)
r += htmltext('<h2>%s</h2>') % _('Proxy')
r += form.render()
return r.getvalue()
else:
cfg_submit(form, 'proxy', ['enabled', 'ip', 'port', 'user', 'password'])
return redirect('.')
def debug_options(self):
form = Form(enctype="multipart/form-data")
debug_cfg = get_cfg('debug', {})

View File

@ -358,8 +358,7 @@ def format_time(datetime, formatstring, gmtime = False):
return formatstring % locals()
def _http_request(url, method='GET', body=None, headers={}, use_proxy=True,
timeout=None):
def _http_request(url, method='GET', body=None, headers={}, timeout=None):
get_publisher().reload_cfg()
if url.startswith('http://'):
@ -367,40 +366,17 @@ def _http_request(url, method='GET', body=None, headers={}, use_proxy=True,
else:
hostname, query = urllib.splithost(url[6:])
proxy = False
proxy_cfg = get_cfg('proxy', {})
if use_proxy is True and proxy_cfg.get('enabled'):
proxy_ip = proxy_cfg.get('ip')
proxy_port = proxy_cfg.get('port')
proxy_user = proxy_cfg.get('user')
proxy_password = proxy_cfg.get('password')
if proxy_ip and proxy_port:
proxy = True
if timeout is None:
conn = httplib.HTTPConnection('%s:%s' % (proxy_ip, proxy_port))
else:
conn = httplib.HTTPConnection('%s:%s' % (proxy_ip, proxy_port),
timeout=timeout)
query = url
if proxy_user and proxy_password:
credentials = base64.encodestring('%s:%s' % (proxy_user, proxy_password))[:-1]
auth = 'Basic %s' % credentials
headers['Proxy-Authorization'] = auth
headers['Proxy-Connection'] = 'keep-alive'
headers['Keep-Alive'] = '300'
if not proxy:
if url.startswith('http://'):
if timeout is None:
conn = httplib.HTTPConnection(hostname)
else:
conn = httplib.HTTPConnection(hostname, timeout=timeout)
if url.startswith('http://'):
if timeout is None:
conn = httplib.HTTPConnection(hostname)
else:
if timeout is None:
conn = httplib.HTTPSConnection(hostname)
else:
conn = httplib.HTTPSConnection(hostname, timeout=timeout)
query = query.replace('&amp;', '&')
conn = httplib.HTTPConnection(hostname, timeout=timeout)
else:
if timeout is None:
conn = httplib.HTTPSConnection(hostname)
else:
conn = httplib.HTTPSConnection(hostname, timeout=timeout)
query = query.replace('&amp;', '&')
try:
conn.request(method, query, body, headers)
@ -422,13 +398,11 @@ def _http_request(url, method='GET', body=None, headers={}, use_proxy=True,
return response, status, data, auth_header
def http_get_page(url, headers={}, use_proxy=True, timeout=None):
return _http_request(url, headers=headers, use_proxy=use_proxy,
timeout=timeout)
def http_get_page(url, headers={}, timeout=None):
return _http_request(url, headers=headers, timeout=timeout)
def http_post_request(url, body=None, headers={}, use_proxy=True, timeout=None):
return _http_request(url, 'POST', body, headers, use_proxy=use_proxy,
timeout=timeout)
def http_post_request(url, body=None, headers={}, timeout=None):
return _http_request(url, 'POST', body, headers, timeout=timeout)
def is_user_admin():
session = get_session()