blob: 6b8a0d9c07edc8ba3d59fde31381a9ccc774a65e [file] [log] [blame]
class ProxyTypeFactory:
def make(ff_value, string):
return {'ff_value': ff_value, 'string': string}
class ProxyType:
DIRECT = ProxyTypeFactory.make(0, 'DIRECT') # Direct connection, no proxy (default on Windows).
MANUAL = ProxyTypeFactory.make(1, 'MANUAL') # Manual proxy settings (e.g., for httpProxy).
PAC = ProxyTypeFactory.make(2, 'PAC') # Proxy autoconfiguration from URL.
RESERVED_1 = ProxyTypeFactory.make(3, 'RESERVED1') # Never used.
AUTODETECT = ProxyTypeFactory.make(4, 'AUTODETECT') # Proxy autodetection (presumably with WPAD).
SYSTEM = ProxyTypeFactory.make(5, 'SYSTEM') # Use system settings (default on Linux).
UNSPECIFIED = ProxyTypeFactory.make(6, 'UNSPECIFIED')
class Proxy(object):
proxyType = ProxyType.UNSPECIFIED
autodetect = False
ftpProxy = ''
httpProxy = ''
noProxy = ''
proxyAutoconfigUrl = ''
sslProxy = ''
def __init__(self, raw=None):
if raw is not None:
if raw.has_key('proxyType') and raw['proxyType'] is not None:
self.proxy_type = raw['proxyType']
if raw.has_key('ftpProxy') and raw['ftpProxy'] is not None:
self.ftp_proxy = raw['ftpProxy']
if raw.has_key('httpProxy') and raw['httpProxy'] is not None:
self.http_proxy = raw['httpProxy']
if raw.has_key('noProxy') and raw['noProxy'] is not None:
self.no_proxy = raw['noProxy']
if raw.has_key('proxyAutoconfigUrl') and raw['proxyAutoconfigUrl'] is not None:
self.proxy_autoconfig_url = raw['proxyAutoconfigUrl']
if raw.has_key('sslProxy') and raw['sslProxy'] is not None:
self.sslProxy = raw['sslProxy']
if raw.has_key('autodetect') and raw['autodetect'] is not None:
self.auto_detect = raw['autodetect']
def proxy_type(self):
return self.proxyType
def proxy_type(self, value):
self.proxyType = value
def auto_detect(self):
return self.autodetect
def auto_detect(self, value):
if isinstance(value, bool):
if self.autodetect is not value:
self.proxyType = ProxyType.AUTODETECT
self.autodetect = value
raise ValueError("value needs to be a boolean")
def ftp_proxy(self):
return self.ftpProxy
def ftp_proxy(self, value):
self.proxyType = ProxyType.MANUAL
self.ftpProxy = value
def http_proxy(self):
return self.httpProxy
def http_proxy(self, value):
self.proxyType = ProxyType.MANUAL
self.httpProxy = value
def no_proxy(self):
return self.noProxy
def no_proxy(self, value):
self.proxyType = ProxyType.MANUAL
self.noProxy = value
def proxy_autoconfig_url(self):
return self.proxyAutoconfigUrl
def proxy_autoconfig_url(self, value):
self.proxyType = ProxyType.PAC
self.proxyAutoconfigUrl = value
def ssl_proxy(self):
return self.sslProxy
def ssl_proxy(self, value):
self.proxyType = ProxyType.MANUAL
self.sslProxy = value
def _verify_proxy_type_compatilibily(self, compatibleProxy):
if self.proxyType != ProxyType.UNSPECIFIED and self.proxyType != compatibleProxy:
raise Exception(" Specified proxy type (%s) not compatible with current setting (%s)" % \
(compatibleProxy, self.proxyType))
def add_to_capabilities(self, capabilities):
proxy_caps = {}
proxy_caps['proxyType'] = self.proxyType['string']
if self.autodetect:
proxy_caps['autodetect'] = self.autodetect
if self.ftpProxy:
proxy_caps['ftpProxy'] = self.ftpProxy
if self.httpProxy:
proxy_caps['httpProxy'] = self.httpProxy
if self.proxyAutoconfigUrl:
proxy_caps['proxyAutoconfigUrl'] = self.proxyAutoconfigUrl
if self.sslProxy:
proxy_caps['sslProxy'] = self.sslProxy
capabilities['proxy'] = proxy_caps