Improved HttpProxy validation routine

Validation routine for HttpProxy updated to use the newly introduced isSocketAddress() function
This commit is contained in:
Junaid Loonat 2016-04-26 23:32:48 +02:00
parent 3e72aa5da5
commit 3a2b603f2f

View File

@ -35,6 +35,7 @@ import socket
from . import ircutils, registry, utils from . import ircutils, registry, utils
from .utils import minisix from .utils import minisix
from .utils.net import isSocketAddress
from .version import version from .version import version
from .i18n import PluginInternationalization from .i18n import PluginInternationalization
_ = PluginInternationalization() _ = PluginInternationalization()
@ -1179,17 +1180,13 @@ class HttpProxy(registry.String):
def setValue(self, v): def setValue(self, v):
proxies = {} proxies = {}
if v != "": if v != "":
# TODO: improve checks if isSocketAddress(v):
if ':' not in v:
self.error()
try:
int(v.rsplit(':', 1)[1])
except ValueError:
self.error()
proxies = { proxies = {
'http': v, 'http': v,
'https': v 'https': v
} }
else:
self.error()
proxyHandler = ProxyHandler(proxies) proxyHandler = ProxyHandler(proxies)
proxyOpenerDirector = build_opener(proxyHandler) proxyOpenerDirector = build_opener(proxyHandler)
install_opener(proxyOpenerDirector) install_opener(proxyOpenerDirector)