Proxy configuration containing proxy type and necessary proxy settings.
| 72 | |
| 73 | |
| 74 | class Proxy: |
| 75 | """Proxy configuration containing proxy type and necessary proxy settings.""" |
| 76 | |
| 77 | proxyType = ProxyType.UNSPECIFIED |
| 78 | autodetect = False |
| 79 | httpProxy = "" |
| 80 | noProxy = "" |
| 81 | proxyAutoconfigUrl = "" |
| 82 | sslProxy = "" |
| 83 | socksProxy = "" |
| 84 | socksUsername = "" |
| 85 | socksPassword = "" |
| 86 | socksVersion = None |
| 87 | |
| 88 | # create descriptor type objects |
| 89 | auto_detect = _ProxyTypeDescriptor("autodetect", ProxyType.AUTODETECT) |
| 90 | """Proxy autodetection setting (boolean).""" |
| 91 | |
| 92 | http_proxy = _ProxyTypeDescriptor("httpProxy", ProxyType.MANUAL) |
| 93 | """HTTP proxy address.""" |
| 94 | |
| 95 | no_proxy = _ProxyTypeDescriptor("noProxy", ProxyType.MANUAL) |
| 96 | """Addresses to bypass proxy.""" |
| 97 | |
| 98 | proxy_autoconfig_url = _ProxyTypeDescriptor("proxyAutoconfigUrl", ProxyType.PAC) |
| 99 | """Proxy autoconfiguration URL.""" |
| 100 | |
| 101 | ssl_proxy = _ProxyTypeDescriptor("sslProxy", ProxyType.MANUAL) |
| 102 | """SSL proxy address.""" |
| 103 | |
| 104 | socks_proxy = _ProxyTypeDescriptor("socksProxy", ProxyType.MANUAL) |
| 105 | """SOCKS proxy address.""" |
| 106 | |
| 107 | socks_username = _ProxyTypeDescriptor("socksUsername", ProxyType.MANUAL) |
| 108 | """SOCKS proxy username.""" |
| 109 | |
| 110 | socks_password = _ProxyTypeDescriptor("socksPassword", ProxyType.MANUAL) |
| 111 | """SOCKS proxy password.""" |
| 112 | |
| 113 | socks_version = _ProxyTypeDescriptor("socksVersion", ProxyType.MANUAL) |
| 114 | """SOCKS proxy version.""" |
| 115 | |
| 116 | def __init__(self, raw: dict | None = None): |
| 117 | """Creates a new Proxy. |
| 118 | |
| 119 | Args: |
| 120 | raw: Raw proxy data. If None, default class values are used. |
| 121 | """ |
| 122 | if raw is None: |
| 123 | return |
| 124 | if not isinstance(raw, dict): |
| 125 | raise TypeError(f"`raw` must be a dict, got {type(raw)}") |
| 126 | if raw.get("proxyType"): |
| 127 | self.proxy_type = ProxyType.load(raw["proxyType"]) |
| 128 | if raw.get("httpProxy"): |
| 129 | self.http_proxy = raw["httpProxy"] |
| 130 | if raw.get("noProxy"): |
| 131 | self.no_proxy = raw["noProxy"] |