Update conf.py

This commit is contained in:
Junaid Loonat 2016-04-25 22:03:00 +02:00
parent 8d2da9aa3a
commit 14e5c490e6

View File

@ -38,6 +38,10 @@ from .utils import minisix
from .version import version from .version import version
from .i18n import PluginInternationalization from .i18n import PluginInternationalization
_ = PluginInternationalization() _ = PluginInternationalization()
if minisix.PY2:
from urllib2 import build_opener, install_opener, ProxyHandler
else:
from urllib.request import build_opener, install_opener, ProxyHandler
### ###
# *** The following variables are affected by command-line options. They are # *** The following variables are affected by command-line options. They are
@ -1171,25 +1175,21 @@ registerGlobalValue(supybot.protocols.http, 'peekSize',
found what it was looking for."""))) found what it was looking for.""")))
class HttpProxy(registry.String): class HttpProxy(registry.String):
"""Value must be a valid hostname:port string.""" """Value must be a valid hostname:port string."""
def setValue(self, v): def setValue(self, v):
if minisix.PY2: proxies = {}
from urllib2 import build_opener, install_opener, ProxyHandler if v != "":
else: # TODO: improve checks
from urllib.request import build_opener, install_opener, ProxyHandler if ':' not in v:
proxies = {} self.error()
if v != "": try:
# TODO: improve checks int(v.rsplit(':', 1)[1])
if ':' not in v: except ValueError:
self.error() self.error()
try: proxies = {
int(v.rsplit(':', 1)[1]) 'http': v,
except ValueError: 'https': v
self.error() }
proxies = {
'http': v,
'https': v
}
proxyHandler = ProxyHandler(proxies) proxyHandler = ProxyHandler(proxies)
proxyOpenerDirector = build_opener(proxyHandler) proxyOpenerDirector = build_opener(proxyHandler)
install_opener(proxyOpenerDirector) install_opener(proxyOpenerDirector)