Add proxy login/pass fields to NetworkSettings class.
Use named "constants" instead of hardcoded numbers for proxy "mode" parameter
This commit is contained in:
@@ -113,6 +113,12 @@ class Settings():
|
|||||||
|
|
||||||
class NetworkSettings():
|
class NetworkSettings():
|
||||||
_instance = None
|
_instance = None
|
||||||
|
|
||||||
|
# constants for serviceNetworkDefaultSettings["mode"] parameter
|
||||||
|
PROXY_MODE_NONE = 0 # 0 - No proxy
|
||||||
|
PROXY_MODE_AUTODETECT = 1 # 1 - Auto-detected proxy settings
|
||||||
|
PROXY_MODE_MANUAL = 2 # 2 - Manual proxy settings
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getInstance(cls):
|
def getInstance(cls):
|
||||||
if cls._instance == None:
|
if cls._instance == None:
|
||||||
@@ -122,13 +128,18 @@ class NetworkSettings():
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
# mode
|
serviceNetworkDefaultSettings = {
|
||||||
# 0 - No proxy
|
"mode": self.PROXY_MODE_AUTODETECT,
|
||||||
# 1 - Auto-detected proxy settings
|
"type": "https",
|
||||||
# 2 - Manual proxy settings
|
"address": "",
|
||||||
serviceNetworkDefaultSettings = {"mode": 1, "type": "https", "address": "", "port": "", "access": 15}
|
"port": "",
|
||||||
|
"access": 15,
|
||||||
|
"login": None,
|
||||||
|
"password": None
|
||||||
|
}
|
||||||
|
|
||||||
self.serviceNetworkSettings = SettingsProvider.getInstance().getSettings("pyfaServiceNetworkSettings", serviceNetworkDefaultSettings)
|
self.serviceNetworkSettings = SettingsProvider.getInstance().getSettings(
|
||||||
|
"pyfaServiceNetworkSettings", serviceNetworkDefaultSettings)
|
||||||
|
|
||||||
def isEnabled(self, type):
|
def isEnabled(self, type):
|
||||||
if type & self.serviceNetworkSettings["access"]:
|
if type & self.serviceNetworkSettings["access"]:
|
||||||
@@ -198,13 +209,21 @@ class NetworkSettings():
|
|||||||
|
|
||||||
def getProxySettings(self):
|
def getProxySettings(self):
|
||||||
|
|
||||||
if self.getMode() == 0:
|
if self.getMode() == self.PROXY_MODE_NONE:
|
||||||
return None
|
return None
|
||||||
if self.getMode() == 1:
|
if self.getMode() == self.PROXY_MODE_AUTODETECT:
|
||||||
return self.autodetect()
|
return self.autodetect()
|
||||||
if self.getMode() == 2:
|
if self.getMode() == self.PROXY_MODE_MANUAL:
|
||||||
return (self.getAddress(), int(self.getPort()))
|
return (self.getAddress(), int(self.getPort()))
|
||||||
|
|
||||||
|
def getProxyAuthDetails(self):
|
||||||
|
if self.getMode() == self.PROXY_MODE_NONE:
|
||||||
|
return None
|
||||||
|
if (self.serviceNetworkSettings["login"] is None) or (self.serviceNetworkSettings["password"] is None):
|
||||||
|
return None
|
||||||
|
# in all other cases, return tuple of (login, password)
|
||||||
|
return (self.serviceNetworkSettings["login"], self.serviceNetworkSettings["password"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user