Merge pull request #1065 from slingamn/certs.release
Before adoption: this commit came in with the history the project adopted, so no landing records it.
clean up code support for OS certificate bundles
authored by Kenneth Reitz · committed by Kenneth Reitz · parents f1d51aa, bbea679 · Browse files · 2 files·+16 added−44 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+16 added−44 removed
- other:+16 added−44 removed
Provenance
- Commit
81c18c7- Tree
d6cfee6- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
f1d51aa- Parent 2
bbea679
2 files changed+16 added−44 removed
modified:requests/certs.py+14 added-10 removed
1 #!/usr/bin/env python2 # -*- coding: utf-8 -*-3 4 """5-ceritfi.py6-~~~~~~~~~~5+certs.py6+~~~~~~~~7 8-This module returns the installation location of cacert.pem.8+This module returns the preferred default CA certificate bundle.9+10+If you are packaging Requests, e.g., for a Linux distribution or a managed11+environment, you can change the definition of where() to return a separately12+packaged CA bundle.13 """14 11-import os15+import os.path16+17+certifi = None18 try:19 import certifi20 except ImportError:15- certifi = None21+ pass22 17-23 def where():19-24+ """Return the preferred certificate bundle."""25 if certifi:26 return certifi.where()22- else:23- f = os.path.split(__file__)[0]24- return os.path.join(f, 'cacert.pem')27 28+ return os.path.join(os.path.dirname(__file__), 'cacert.pem')29+30 if __name__ == '__main__':31 print(where())modified:requests/utils.py+2 added-34 removed
17 unmodified lines18 import zlib19 from netrc import netrc, NetrcParseError20 21 from . import __version__22+from . import certs23 from .compat import parse_http_list as _parse_list_header24 from .compat import quote, urlparse, bytes, str, OrderedDict25 from .cookies import RequestsCookieJar, cookiejar_from_dict26 27 _hush_pyflakes = (RequestsCookieJar,)28 28-CERTIFI_BUNDLE_PATH = None29-try:30- # see if requests's own CA certificate bundle is installed31- from . import certs32- path = certs.where()33- if os.path.exists(path):34- CERTIFI_BUNDLE_PATH = certs.where()35-except ImportError:36- pass37-29 NETRC_FILES = ('.netrc', '_netrc')30 40-# common paths for the OS's CA certificate bundle41-POSSIBLE_CA_BUNDLE_PATHS = [42- # Red Hat, CentOS, Fedora and friends (provided by the ca-certificates package):43- '/etc/pki/tls/certs/ca-bundle.crt',44- # Ubuntu, Debian, and friends (provided by the ca-certificates package):45- '/etc/ssl/certs/ca-certificates.crt',46- # FreeBSD (provided by the ca_root_nss package):47- '/usr/local/share/certs/ca-root-nss.crt',48- # openSUSE (provided by the ca-certificates package), the 'certs' directory is the49- # preferred way but may not be supported by the SSL module, thus it has 'ca-bundle.pem'50- # as a fallback (which is generated from pem files in the 'certs' directory):51- '/etc/ssl/ca-bundle.pem',52-]53-54-55-def get_os_ca_bundle_path():56- """Try to pick an available CA certificate bundle provided by the OS."""57- for path in POSSIBLE_CA_BUNDLE_PATHS:58- if os.path.exists(path):59- return path60- return None61-31 # if certifi is installed, use its CA bundle;32 # otherwise, try and use the OS bundle64-DEFAULT_CA_BUNDLE_PATH = CERTIFI_BUNDLE_PATH or get_os_ca_bundle_path()33+DEFAULT_CA_BUNDLE_PATH = certs.where()34 66-35 def dict_to_sequence(d):36 """Returns an internal sequence dictionary update."""37 38 if hasattr(d, 'items'):525 unmodified lines