Commit 88e3f70b authored by Laurent Bachelier's avatar Laurent Bachelier 🐧 Committed by Vincent A

backends: Get proxies using stdlib functions

parent 485bf250
Pipeline #1605 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.contact import CapContact, Advisor
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 @@ class Boobank(ReplApplication):
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 @@ class Repositories(object):
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 threading import RLock
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 @@ class Module(object):
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 @@ class AbstractModule(Module):
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