From ade951360ff909f9174803623b52855bf5693965 Mon Sep 17 00:00:00 2001 From: HomeWorld Date: Fri, 23 Dec 2011 20:17:36 +0200 Subject: [PATCH] Added proxy autodetection stuff to service.settings.ProxySettings --- .../pyfaGlobalPreferences.py | 24 +++-------------- service/settings.py | 26 ++++++++++++++++++- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gui/builtinPreferenceViews/pyfaGlobalPreferences.py b/gui/builtinPreferenceViews/pyfaGlobalPreferences.py index b9b0f5647..45ac97509 100644 --- a/gui/builtinPreferenceViews/pyfaGlobalPreferences.py +++ b/gui/builtinPreferenceViews/pyfaGlobalPreferences.py @@ -123,29 +123,13 @@ class PFGlobalPref ( PreferenceView): mainSizer.Add(btnSizer, 0, wx.EXPAND,5) - proxy = None - proxAddr = proxPort = "" - proxydict = urllib2.ProxyHandler().proxies + proxy = self.proxySettings.autodetect() + txt = "Auto-detected: " - - validPrefixes = ("https", "http") - - for prefix in validPrefixes: - if not prefix in proxydict: - continue - proxyline = proxydict[prefix] - proto = "{0}://".format(prefix) - if proxyline[:len(proto)] == proto: - proxyline = proxyline[len(proto):] - proxAddr, proxPort = proxyline.split(":") - proxPort = int(proxPort.rstrip("/")) - proxy = (proxAddr, proxPort) - break - - if len(proxAddr) == 0: + if len(proxy) == 0: txt += "None" else: - txt += proto + proxAddr + ":" + str(proxPort) + txt += proxy self.stPSAutoDetected.SetLabel(txt) self.stPSAutoDetected.Disable() diff --git a/service/settings.py b/service/settings.py index d502dafef..ed1e170ab 100644 --- a/service/settings.py +++ b/service/settings.py @@ -20,6 +20,7 @@ import cPickle import os.path import config +import urllib2 class SettingsProvider(): BASE_PATH = os.path.join(config.savePath, "settings") @@ -146,4 +147,27 @@ class ProxySettings(): self.serviceProxySettings["port"] = port def setType(self, type): - self.serviceProxySettings["type"] = type \ No newline at end of file + self.serviceProxySettings["type"] = type + + def autodetect(self): + + proxy = None + proxAddr = proxPort = "" + proxydict = urllib2.ProxyHandler().proxies + txt = "Auto-detected: " + + validPrefixes = ("https", "http") + + for prefix in validPrefixes: + if not prefix in proxydict: + continue + proxyline = proxydict[prefix] + proto = "{0}://".format(prefix) + if proxyline[:len(proto)] == proto: + proxyline = proxyline[len(proto):] + proxAddr, proxPort = proxyline.split(":") + proxPort = proxPort.rstrip("/") + proxy = proto + proxAddr + proxPort + break + + return proxy \ No newline at end of file