Commit 88e3f70b authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by hydrargyrum
Browse files

backends: Get proxies using stdlib functions

parent 485bf250
Pipeline #278635891 failed with stages
in 62 minutes and 14 seconds
......@@ -4,8 +4,7 @@ detailed-errors = 1
with-doctest = 1
with-coverage = 1
where = weboob
tests = weboob.tools.backend,
weboob.tools.capabilities.bank.iban,
tests = weboob.tools.capabilities.bank.iban,
weboob.tools.capabilities.bank.transactions,
weboob.tools.capabilities.paste,
weboob.tools.application.formatters.json,
......
......@@ -41,7 +41,7 @@
from weboob.capabilities.profile import CapProfile
from weboob.tools.application.repl import ReplApplication, defaultcount
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
from weboob.tools.backend import env_proxies
from weboob.tools.compat import getproxies
from weboob.tools.log import getLogger
from weboob.tools.misc import to_unicode
......@@ -788,7 +788,7 @@ def do_budgea(self, line):
username, password = self.parse_command_args(line, 2, 2)
client = APIBrowser(baseurl='https://budgea.biapi.pro/2.0/',
proxy=env_proxies(),
proxy=getproxies(),
logger=getLogger('apibrowser', self.logger))
client.set_profile(Weboob(self.VERSION))
client.TIMEOUT = 60
......
......@@ -474,14 +474,14 @@ def __init__(self, workdir, datadir, version):
def load_browser(self):
from weboob.browser.browsers import Browser
from weboob.browser.profiles import Weboob as WeboobProfile
from weboob.tools.backend import env_proxies
from weboob.tools.compat import getproxies
class WeboobBrowser(Browser):
PROFILE = WeboobProfile(self.version)
if self.browser is None:
self.browser = WeboobBrowser(
logger=getLogger('browser', parent=self.logger),
proxy=env_proxies())
proxy=getproxies())
def create_dir(self, name):
if not os.path.exists(name):
......
......@@ -23,7 +23,7 @@
from weboob.capabilities.base import BaseObject, Capability, FieldNotFound, NotAvailable, NotLoaded
from weboob.exceptions import ModuleInstallError
from weboob.tools.compat import basestring
from weboob.tools.compat import basestring, getproxies
from weboob.tools.log import getLogger
from weboob.tools.misc import iter_fields
from weboob.tools.value import ValuesDict
......@@ -353,7 +353,7 @@ def create_browser(self, *args, **kwargs):
def get_proxy(self):
# Get proxies from environment variables
proxies = env_proxies(environ=os.environ)
proxies = getproxies()
# Override them with backend-specific config
if '_proxy' in self._private_config:
proxies['http'] = self._private_config['_proxy']
......@@ -486,19 +486,3 @@ def __new__(cls, weboob, name, config=None, storage=None, logger=None, nofail=Fa
cls.__bases__ = tuple([parent] + list(cls.iter_caps()))
return object.__new__(cls)
def env_proxies(environ=os.environ):
proxies = {}
proxies['http'] = environ.get('http_proxy', environ.get('HTTP_PROXY'))
proxies['https'] = environ.get('https_proxy', environ.get('HTTPS_PROXY'))
return proxies
def test():
assert env_proxies({}) == {'http': None, 'https': None}
assert env_proxies({'http_proxy': 'a'}) == {'http': 'a', 'https': None}
assert env_proxies({'HTTP_PROXY': 'a'}) == {'http': 'a', 'https': None}
assert env_proxies({'https_proxy': 'b'}) == {'http': None, 'https': 'b'}
assert env_proxies({'HTTPS_PROXY': 'b'}) == {'http': None, 'https': 'b'}
assert env_proxies({'https_proxy': 'c', 'HTTPS_PROXY': 'd'}) == {'http': None, 'https': 'c'}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment