971c2ad024d24b8425bad8eef7bb08a8e935fe1c
[sdc/sdc-distribution-client.git] /
1 '''
2 Debian and other distributions "unbundle" requests' vendored dependencies, and
3 rewrite all imports to use the global versions of ``urllib3`` and ``chardet``.
4 The problem with this is that not only requests itself imports those
5 dependencies, but third-party code outside of the distros' control too.
6
7 In reaction to these problems, the distro maintainers replaced
8 ``requests.packages`` with a magical "stub module" that imports the correct
9 modules. The implementations were varying in quality and all had severe
10 problems. For example, a symlink (or hardlink) that links the correct modules
11 into place introduces problems regarding object identity, since you now have
12 two modules in `sys.modules` with the same API, but different identities::
13
14     requests.packages.urllib3 is not urllib3
15
16 With version ``2.5.2``, requests started to maintain its own stub, so that
17 distro-specific breakage would be reduced to a minimum, even though the whole
18 issue is not requests' fault in the first place. See
19 https://github.com/kennethreitz/requests/pull/2375 for the corresponding pull
20 request.
21 '''
22
23 from __future__ import absolute_import
24 import sys
25
26 try:
27     from . import urllib3
28 except ImportError:
29     import urllib3
30     sys.modules['%s.urllib3' % __name__] = urllib3
31
32 try:
33     from . import chardet
34 except ImportError:
35     import chardet
36     sys.modules['%s.chardet' % __name__] = chardet