def request(self, url, type, data=None): # URL is required to be https as of right now #print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: raise Error("Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers={"User-Agent" : "pyfa {0} (Python-urllib2)".format(versionString)} proxy = NetworkSettings.getInstance().getProxySettings() if proxy is not None: proxy = urllib2.ProxyHandler({'https': "{0}:{1}".format(*proxy)}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) request = urllib2.Request(url, headers=headers, data=urllib.urlencode(data) if data else None) try: return urllib2.urlopen(request) except urllib2.HTTPError, error: if error.code == 404: raise RequestError() elif error.code == 403: raise AuthenticationError() elif error.code >= 500: raise ServerError()
def __init__(self): self.settings = EsiSettings.getInstance() self.server_base: ApiBase = supported_servers[self.settings.get("server")] # session request stuff self._session = Session() self._basicHeaders = { 'Accept': 'application/json', 'User-Agent': ( 'pyfa v{}'.format(config.version) ) } self._session.headers.update(self._basicHeaders) self._session.proxies = NetworkSettings.getInstance().getProxySettingsInRequestsFormat() # Set up cached session. This is only used for SSO meta data for now, but can be expanded to actually handle # various ESI caching (using ETag, for example) in the future cached_session = CachedSession( os.path.join(config.savePath, config.ESI_CACHE), backend="sqlite", cache_control=True, # Use Cache-Control headers for expiration, if available expire_after=timedelta(days=1), # Otherwise expire responses after one day stale_if_error=True, # In case of request errors, use stale cache data if possible ) cached_session.headers.update(self._basicHeaders) cached_session.proxies = NetworkSettings.getInstance().getProxySettingsInRequestsFormat() meta_call = cached_session.get("https://%s/.well-known/oauth-authorization-server" % self.server_base.sso) meta_call.raise_for_status() self.server_meta = meta_call.json() jwks_call = cached_session.get(self.server_meta["jwks_uri"]) jwks_call.raise_for_status() self.jwks = jwks_call.json()
def request(self, url, type, data=None): # URL is required to be https as of right now # print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: raise Error("Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = {"User-Agent": "pyfa {0} (Python-urllib2)".format(versionString)} proxy = NetworkSettings.getInstance().getProxySettings() if proxy is not None: # proxy is a tuple of (host, port): (u'192.168.20.1', 3128) proxy_auth = NetworkSettings.getInstance().getProxyAuthDetails() # proxy_auth is a tuple of (login, password) or None if proxy_auth is not None: # add login:password@ in front of proxy address proxy_handler = urllib2.ProxyHandler({'https': '{0}:{1}@{2}:{3}'.format( proxy_auth[0], proxy_auth[1], proxy[0], proxy[1])}) else: # build proxy handler with no login/pass info proxy_handler = urllib2.ProxyHandler({'https': "{0}:{1}".format(proxy[0], proxy[1])}) opener = urllib2.build_opener(proxy_handler) urllib2.install_opener(opener) else: # This is a bug fix, explicitly disable possibly previously installed # opener with proxy, by urllib2.install_opener() a few lines above in code. # Now this explicitly disables proxy handler, "uninstalling" opener. # This is used in case when user had proxy enabled, so proxy_handler was already # installed globally, and then user had disabled the proxy, so we should clear that opener urllib2.install_opener(None) # another option could be installing a default opener: # urllib2.install_opener(urllib2.build_opener()) request = urllib2.Request(url, headers=headers, data=urllib.urlencode(data) if data else None) try: return urllib2.urlopen(request) except urllib2.HTTPError as error: if error.code == 404: raise RequestError() elif error.code == 403: raise AuthenticationError() elif error.code >= 500: raise ServerError() except urllib2.URLError as error: if "timed out" in error.reason: raise TimeoutError() else: raise Error(error)
def request(self, url, type, *args, **kwargs): # URL is required to be https as of right now # print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: pyfalog.warning( "Access not enabled - please enable in Preferences > Network") raise Error( "Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = { "User-Agent": "pyfa {0} (python-requests {1})".format(versionString, requests.__version__) } # user-agent: pyfa 2.0.0b4 git -YC120.2 1.2 (python-requests 2.18.4) # python-requests supports setting proxy for request as parameter to get() / post() # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } # or with HTTP Basic auth support: proxies = {'http': 'http://*****:*****@10.10.1.10:3128/'} # then you do: requests.get('http://example.org', proxies=proxies) proxies = NetworkSettings.getInstance( ).getProxySettingsInRequestsFormat() try: resp = requests.get(url, headers=headers, proxies=proxies, **kwargs) resp.raise_for_status() return resp except requests.exceptions.HTTPError as error: pyfalog.warning("HTTPError:") pyfalog.warning(error) if error.response.status_code == 404: raise RequestError() elif error.response.status_code == 403: raise AuthenticationError() elif error.response.status_code >= 500: raise ServerError() raise Error(error) except requests.exceptions.Timeout: raise TimeoutError() except Exception as error: raise Error(error)
def request(self, url, type, data=None): # URL is required to be https as of right now #print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: raise Error("Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = {"User-Agent" : "pyfa {0} (Python-urllib2)".format(versionString)} proxy = NetworkSettings.getInstance().getProxySettings() if proxy is not None: # proxy is a tuple of (host, port): (u'192.168.20.1', 3128) proxy_auth = NetworkSettings.getInstance().getProxyAuthDetails() # proxy_auth is a tuple of (login, password) or None if proxy_auth is not None: # add login:password@ in front of proxy address proxy_handler = urllib2.ProxyHandler({'https': '{0}:{1}@{2}:{3}'.format( proxy_auth[0], proxy_auth[1], proxy[0], proxy[1])}) else: # build proxy handler with no login/pass info proxy_handler = urllib2.ProxyHandler({'https': "{0}:{1}".format(proxy[0], proxy[1])}) opener = urllib2.build_opener(proxy_handler) urllib2.install_opener(opener) else: # This is a bug fix, explicitly disable possibly previously installed # opener with proxy, by urllib2.install_opener() a few lines above in code. # Now this explicitly disables proxy handler, "uninstalling" opener. # This is used in case when user had proxy enabled, so proxy_handler was already # installed globally, and then user had disabled the proxy, so we should clear that opener urllib2.install_opener(None) # another option could be installing a default opener: # urllib2.install_opener(urllib2.build_opener()) request = urllib2.Request(url, headers=headers, data=urllib.urlencode(data) if data else None) try: return urllib2.urlopen(request) except urllib2.HTTPError, error: if error.code == 404: raise RequestError() elif error.code == 403: raise AuthenticationError() elif error.code >= 500: raise ServerError()
def __networkAccessCheck(self, type): # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: pyfalog.warning( 'Access not enabled - please enable in Preferences > Network') raise Error( 'Access not enabled - please enable in Preferences > Network')
def request(self, url, type, *args, **kwargs): # URL is required to be https as of right now # print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: pyfalog.warning("Access not enabled - please enable in Preferences > Network") raise Error("Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = {"User-Agent": "pyfa {0} (python-requests {1})".format(versionString, requests.__version__)} # user-agent: pyfa 2.0.0b4 git -YC120.2 1.2 (python-requests 2.18.4) # python-requests supports setting proxy for request as parameter to get() / post() # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } # or with HTTP Basic auth support: proxies = {'http': 'http://*****:*****@10.10.1.10:3128/'} # then you do: requests.get('http://example.org', proxies=proxies) proxies = NetworkSettings.getInstance().getProxySettingsInRequestsFormat() try: resp = requests.get(url, headers=headers, proxies=proxies, **kwargs) resp.raise_for_status() return resp except requests.exceptions.HTTPError as error: pyfalog.warning("HTTPError:") pyfalog.warning(error) if error.response.status_code == 404: raise RequestError() elif error.response.status_code == 403: raise AuthenticationError() elif error.response.status_code >= 500: raise ServerError() raise Error(error) except requests.exceptions.Timeout: raise TimeoutError() except Exception as error: raise Error(error)
def __init__(self): self.settings = EsiSettings.getInstance() # session request stuff self._session = Session() self._session.headers.update({ 'Accept': 'application/json', 'User-Agent': ( 'pyfa v{}'.format(config.version) ) }) self._session.proxies = NetworkSettings.getInstance().getProxySettingsInRequestsFormat()
def __init__(self): self.settings = EsiSettings.getInstance() # session request stuff self._session = Session() self._session.headers.update({ 'Accept': 'application/json', 'User-Agent': ('pyfa v{}'.format(config.version)) }) self._session.proxies = NetworkSettings.getInstance( ).getProxySettingsInRequestsFormat()
def request(self, url, type, data=None): # URL is required to be https as of right now #print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: raise Error( "Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = { "User-Agent": "pyfa {0} (Python-urllib2)".format(versionString) } proxy = NetworkSettings.getInstance().getProxySettings() if proxy is not None: proxy = urllib2.ProxyHandler({'https': "{0}:{1}".format(*proxy)}) opener = urllib2.build_opener(proxy) urllib2.install_opener(opener) request = urllib2.Request( url, headers=headers, data=urllib.urlencode(data) if data else None) try: return urllib2.urlopen(request) except urllib2.HTTPError, error: if error.code == 404: raise RequestError() elif error.code == 403: raise AuthenticationError() elif error.code >= 500: raise ServerError()
def __init__(self): self.settings = EsiSettings.getInstance() # session request stuff self._session = Session() self._session.headers.update({ 'Accept': 'application/json', 'Origin': 'https://esi.evepc.163.com', 'Content-Type': 'application/x-www-form-urlencoded' }) self._session.proxies = NetworkSettings.getInstance( ).getProxySettingsInRequestsFormat()
def request(self, url, type, *args, **kwargs): # URL is required to be https as of right now # print "Starting request: %s\n\tType: %s\n\tPost Data: %s"%(url,type,data) # Make sure request is enabled access = NetworkSettings.getInstance().getAccess() if not self.ENABLED & access or not type & access: pyfalog.warning( "Access not enabled - please enable in Preferences > Network") raise Error( "Access not enabled - please enable in Preferences > Network") # Set up some things for the request versionString = "{0} {1} - {2} {3}".format(config.version, config.tag, config.expansionName, config.expansionVersion) headers = { "User-Agent": "pyfa {0} (python-requests {1})".format(versionString, requests.__version__) } # user-agent: pyfa 2.0.0b4 git -YC120.2 1.2 (python-requests 2.18.4) # python-requests supports setting proxy for request as parameter to get() / post() # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } # or with HTTP Basic auth support: proxies = {'http': 'http://*****:*****@10.10.1.10:3128/'} # then you do: requests.get('http://example.org', proxies=proxies) proxies = None proxy_settings = NetworkSettings.getInstance().getProxySettings() # proxy_settings is a tuple of (host, port), like ('192.168.20.1', 3128), or None if proxy_settings is not None: # form proxy address in format "http://*****:*****@" user_pass = '******'.format(proxy_auth_details[0], proxy_auth_details[1]) proxies = { 'http': 'http://' + user_pass + proxy_host_port, 'https': 'http://' + user_pass + proxy_host_port } # final form: { 'http': 'http://*****:*****@host:port', ... }, or # { 'http': 'http://host:port', ... } if no auth info. try: resp = requests.get(url, headers=headers, proxies=proxies, **kwargs) resp.raise_for_status() return resp except requests.exceptions.HTTPError as error: pyfalog.warning("HTTPError:") pyfalog.warning(error) if error.response.status_code == 404: raise RequestError() elif error.response.status_code == 403: raise AuthenticationError() elif error.response.status_code >= 500: raise ServerError() raise Error(error) except requests.exceptions.Timeout: raise TimeoutError() except Exception as error: raise Error(error)
def populatePanel(self, panel): self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.settings = NetworkSettings.getInstance() self.network = Network.getInstance() self.dirtySettings = False mainSizer = wx.BoxSizer(wx.VERTICAL) self.stTitle = wx.StaticText(panel, wx.ID_ANY, self.title, wx.DefaultPosition, wx.DefaultSize, 0) self.stTitle.Wrap(-1) self.stTitle.SetFont(wx.Font(12, 70, 90, 90, False, wx.EmptyString)) mainSizer.Add(self.stTitle, 0, wx.ALL, 5) self.m_staticline1 = wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) mainSizer.Add(self.m_staticline1, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) self.cbEnableNetwork = wx.CheckBox(panel, wx.ID_ANY, "Enable Network", wx.DefaultPosition, wx.DefaultSize, 0) mainSizer.Add(self.cbEnableNetwork, 0, wx.ALL | wx.EXPAND, 5) subSizer = wx.BoxSizer(wx.VERTICAL) self.cbEve = wx.CheckBox(panel, wx.ID_ANY, "EVE Servers (API && CREST import)", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbEve, 0, wx.ALL | wx.EXPAND, 5) self.cbPricing = wx.CheckBox(panel, wx.ID_ANY, "Pricing updates", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbPricing, 0, wx.ALL | wx.EXPAND, 5) self.cbPyfaUpdate = wx.CheckBox(panel, wx.ID_ANY, "Pyfa Update checks", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbPyfaUpdate, 0, wx.ALL | wx.EXPAND, 5) mainSizer.Add(subSizer, 0, wx.LEFT | wx.EXPAND, 30) proxyTitle = wx.StaticText(panel, wx.ID_ANY, "Proxy settings", wx.DefaultPosition, wx.DefaultSize, 0) proxyTitle.Wrap(-1) proxyTitle.SetFont(wx.Font(12, 70, 90, 90, False, wx.EmptyString)) mainSizer.Add(proxyTitle, 0, wx.ALL, 5) mainSizer.Add(wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL), 0, wx.EXPAND, 5) self.cbEnableNetwork.SetValue(self.settings.isEnabled(self.network.ENABLED)) self.cbEve.SetValue(self.settings.isEnabled(self.network.EVE)) self.cbPricing.SetValue(self.settings.isEnabled(self.network.PRICES)) self.cbPyfaUpdate.SetValue(self.settings.isEnabled(self.network.UPDATE)) self.cbEnableNetwork.Bind(wx.EVT_CHECKBOX, self.OnCBEnableChange) self.cbEve.Bind(wx.EVT_CHECKBOX, self.OnCBEveChange) self.cbPricing.Bind(wx.EVT_CHECKBOX, self.OnCBPricingChange) self.cbPyfaUpdate.Bind(wx.EVT_CHECKBOX, self.OnCBUpdateChange) self.toggleNetworks(self.cbEnableNetwork.GetValue()) # --------------- # Proxy # --------------- self.nMode = self.settings.getMode() self.nAddr = self.settings.getAddress() self.nPort = self.settings.getPort() self.nType = self.settings.getType() self.nAuth = self.settings.getProxyAuthDetails() # tuple of (login, password) if self.nAuth is None: self.nAuth = ("", "") # we don't want None here, it should be a tuple ptypeSizer = wx.BoxSizer(wx.HORIZONTAL) self.stPType = wx.StaticText(panel, wx.ID_ANY, "Mode:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPType.Wrap(-1) ptypeSizer.Add(self.stPType, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.chProxyTypeChoices = ["No proxy", "Auto-detected proxy settings", "Manual proxy settings"] self.chProxyType = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.chProxyTypeChoices, 0) self.chProxyType.SetSelection(self.nMode) ptypeSizer.Add(self.chProxyType, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) mainSizer.Add(ptypeSizer, 0, wx.EXPAND, 5) fgAddrSizer = wx.FlexGridSizer(2, 2, 0, 0) fgAddrSizer.AddGrowableCol(1) fgAddrSizer.SetFlexibleDirection(wx.BOTH) fgAddrSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.stPSetAddr = wx.StaticText(panel, wx.ID_ANY, "Addr:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSetAddr.Wrap(-1) fgAddrSizer.Add(self.stPSetAddr, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.editProxySettingsAddr = wx.TextCtrl(panel, wx.ID_ANY, self.nAddr, wx.DefaultPosition, wx.DefaultSize, 0) fgAddrSizer.Add(self.editProxySettingsAddr, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5) self.stPSetPort = wx.StaticText(panel, wx.ID_ANY, "Port:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSetPort.Wrap(-1) fgAddrSizer.Add(self.stPSetPort, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.editProxySettingsPort = wx.TextCtrl(panel, wx.ID_ANY, self.nPort, wx.DefaultPosition, wx.DefaultSize, 0) fgAddrSizer.Add(self.editProxySettingsPort, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5) mainSizer.Add(fgAddrSizer, 0, wx.EXPAND, 5) # proxy auth information: login and pass self.stPSetLogin = wx.StaticText(panel, wx.ID_ANY, "Username:"******"Password:"******"Auto-detected: ", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSAutoDetected.Wrap(-1) mainSizer.Add(self.stPSAutoDetected, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.AddStretchSpacer() self.btnApply = wx.Button(panel, wx.ID_ANY, "Apply Proxy Settings", wx.DefaultPosition, wx.DefaultSize, 0) btnSizer.Add(self.btnApply, 0, wx.ALL, 5) mainSizer.Add(btnSizer, 0, wx.EXPAND, 5) proxy = self.settings.autodetect() if proxy is not None: addr, port = proxy txt = addr + ":" + str(port) else: txt = "None" self.stPSAutoDetected.SetLabel("Auto-detected: " + txt) self.stPSAutoDetected.Disable() self.chProxyType.Bind(wx.EVT_CHOICE, self.OnCHProxyTypeSelect) self.editProxySettingsAddr.Bind(wx.EVT_TEXT, self.OnEditPSAddrText) self.editProxySettingsPort.Bind(wx.EVT_TEXT, self.OnEditPSPortText) self.editProxySettingsLogin.Bind(wx.EVT_TEXT, self.OnEditPSLoginText) self.editProxySettingsPassword.Bind(wx.EVT_TEXT, self.OnEditPSPasswordText) self.btnApply.Bind(wx.EVT_BUTTON, self.OnBtnApply) self.UpdateApplyButtonState() if self.nMode is not NetworkSettings.PROXY_MODE_MANUAL: # == 2 self.ToggleProxySettings(False) else: self.ToggleProxySettings(True) panel.SetSizer(mainSizer) panel.Layout()
def populatePanel(self, panel): self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.settings = NetworkSettings.getInstance() self.network = Network.getInstance() self.dirtySettings = False mainSizer = wx.BoxSizer(wx.VERTICAL) self.stTitle = wx.StaticText(panel, wx.ID_ANY, self.title, wx.DefaultPosition, wx.DefaultSize, 0) self.stTitle.Wrap(-1) self.stTitle.SetFont(wx.Font(12, 70, 90, 90, False, wx.EmptyString)) mainSizer.Add(self.stTitle, 0, wx.EXPAND | wx.ALL, 5) self.m_staticline1 = wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) mainSizer.Add(self.m_staticline1, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5) self.cbEnableNetwork = wx.CheckBox(panel, wx.ID_ANY, "Enable Network", wx.DefaultPosition, wx.DefaultSize, 0) mainSizer.Add(self.cbEnableNetwork, 0, wx.ALL | wx.EXPAND, 5) subSizer = wx.BoxSizer(wx.VERTICAL) self.cbEve = wx.CheckBox(panel, wx.ID_ANY, "EVE Servers (API && CREST import)", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbEve, 0, wx.ALL | wx.EXPAND, 5) self.cbPricing = wx.CheckBox(panel, wx.ID_ANY, "Pricing updates", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbPricing, 0, wx.ALL | wx.EXPAND, 5) self.cbPyfaUpdate = wx.CheckBox(panel, wx.ID_ANY, "Pyfa Update checks", wx.DefaultPosition, wx.DefaultSize, 0) subSizer.Add(self.cbPyfaUpdate, 0, wx.ALL | wx.EXPAND, 5) mainSizer.Add(subSizer, 0, wx.LEFT | wx.EXPAND, 30) proxyTitle = wx.StaticText(panel, wx.ID_ANY, "Proxy settings", wx.DefaultPosition, wx.DefaultSize, 0) proxyTitle.Wrap(-1) proxyTitle.SetFont(wx.Font(12, 70, 90, 90, False, wx.EmptyString)) mainSizer.Add(proxyTitle, 0, wx.ALL, 5) mainSizer.Add( wx.StaticLine(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL), 0, wx.EXPAND, 5) self.cbEnableNetwork.SetValue( self.settings.isEnabled(self.network.ENABLED)) self.cbEve.SetValue(self.settings.isEnabled(self.network.EVE)) self.cbPricing.SetValue(self.settings.isEnabled(self.network.PRICES)) self.cbPyfaUpdate.SetValue(self.settings.isEnabled( self.network.UPDATE)) self.cbEnableNetwork.Bind(wx.EVT_CHECKBOX, self.OnCBEnableChange) self.cbEve.Bind(wx.EVT_CHECKBOX, self.OnCBEveChange) self.cbPricing.Bind(wx.EVT_CHECKBOX, self.OnCBPricingChange) self.cbPyfaUpdate.Bind(wx.EVT_CHECKBOX, self.OnCBUpdateChange) self.toggleNetworks(self.cbEnableNetwork.GetValue()) # --------------- # Proxy # --------------- self.nMode = self.settings.getMode() self.nAddr = self.settings.getAddress() self.nPort = self.settings.getPort() self.nType = self.settings.getType() self.nAuth = self.settings.getProxyAuthDetails( ) # tuple of (login, password) if self.nAuth is None: self.nAuth = ("", "" ) # we don't want None here, it should be a tuple ptypeSizer = wx.BoxSizer(wx.HORIZONTAL) self.stPType = wx.StaticText(panel, wx.ID_ANY, "Mode:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPType.Wrap(-1) ptypeSizer.Add(self.stPType, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.chProxyTypeChoices = [ "No proxy", "Auto-detected proxy settings", "Manual proxy settings" ] self.chProxyType = wx.Choice(panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, self.chProxyTypeChoices, 0) self.chProxyType.SetSelection(self.nMode) ptypeSizer.Add(self.chProxyType, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) mainSizer.Add(ptypeSizer, 0, wx.EXPAND, 5) fgAddrSizer = wx.FlexGridSizer(2, 2, 0, 0) fgAddrSizer.AddGrowableCol(1) fgAddrSizer.SetFlexibleDirection(wx.BOTH) fgAddrSizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.stPSetAddr = wx.StaticText(panel, wx.ID_ANY, "Addr:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSetAddr.Wrap(-1) fgAddrSizer.Add(self.stPSetAddr, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.editProxySettingsAddr = wx.TextCtrl(panel, wx.ID_ANY, self.nAddr, wx.DefaultPosition, wx.DefaultSize, 0) fgAddrSizer.Add(self.editProxySettingsAddr, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5) self.stPSetPort = wx.StaticText(panel, wx.ID_ANY, "Port:", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSetPort.Wrap(-1) fgAddrSizer.Add(self.stPSetPort, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.editProxySettingsPort = wx.TextCtrl(panel, wx.ID_ANY, self.nPort, wx.DefaultPosition, wx.DefaultSize, 0) fgAddrSizer.Add(self.editProxySettingsPort, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5) mainSizer.Add(fgAddrSizer, 0, wx.EXPAND, 5) # proxy auth information: login and pass self.stPSetLogin = wx.StaticText(panel, wx.ID_ANY, "Username:"******"Password:"******"Auto-detected: ", wx.DefaultPosition, wx.DefaultSize, 0) self.stPSAutoDetected.Wrap(-1) mainSizer.Add(self.stPSAutoDetected, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) btnSizer = wx.BoxSizer(wx.HORIZONTAL) btnSizer.AddStretchSpacer() self.btnApply = wx.Button(panel, wx.ID_ANY, "Apply Proxy Settings", wx.DefaultPosition, wx.DefaultSize, 0) btnSizer.Add(self.btnApply, 0, wx.ALL, 5) mainSizer.Add(btnSizer, 0, wx.EXPAND, 5) proxy = self.settings.autodetect() if proxy is not None: addr, port = proxy txt = addr + ":" + str(port) else: txt = "None" self.stPSAutoDetected.SetLabel("Auto-detected: " + txt) self.stPSAutoDetected.Disable() self.chProxyType.Bind(wx.EVT_CHOICE, self.OnCHProxyTypeSelect) self.editProxySettingsAddr.Bind(wx.EVT_TEXT, self.OnEditPSAddrText) self.editProxySettingsPort.Bind(wx.EVT_TEXT, self.OnEditPSPortText) self.editProxySettingsLogin.Bind(wx.EVT_TEXT, self.OnEditPSLoginText) self.editProxySettingsPassword.Bind(wx.EVT_TEXT, self.OnEditPSPasswordText) self.btnApply.Bind(wx.EVT_BUTTON, self.OnBtnApply) self.UpdateApplyButtonState() if self.nMode is not NetworkSettings.PROXY_MODE_MANUAL: # == 2 self.ToggleProxySettings(False) else: self.ToggleProxySettings(True) panel.SetSizer(mainSizer) panel.Layout()
def __getProxies(self): # python-requests supports setting proxy for request as parameter to get() / post() # in a form like: proxies = { 'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080' } # or with HTTP Basic auth support: proxies = {'http': 'http://*****:*****@10.10.1.10:3128/'} # then you do: requests.get('http://example.org', proxies=proxies) return NetworkSettings.getInstance().getProxySettingsInRequestsFormat()