Skip to content
Myr

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

2 files+16 added−44 removed

modified:requests/certs.py+14 added-10 removed
1#!/usr/bin/env python2# -*- coding: utf-8 -*-34"""5ceritfi.py6~~~~~~~~~~5certs.py6~~~~~~~~78This module returns the installation location of cacert.pem.8This module returns the preferred default CA certificate bundle.910If you are packaging Requests, e.g., for a Linux distribution or a managed11environment, you can change the definition of where() to return a separately12packaged CA bundle.13"""1411import os15import os.path1617certifi = None18try:19 import certifi20except ImportError:15 certifi = None21 pass221723def where():1924 """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')2728 return os.path.join(os.path.dirname(__file__), 'cacert.pem')2930if __name__ == '__main__':31 print(where())
modified:requests/utils.py+2 added-34 removed
17 unmodified lines
18import zlib19from netrc import netrc, NetrcParseError2021from . import __version__22from . import certs23from .compat import parse_http_list as _parse_list_header24from .compat import quote, urlparse, bytes, str, OrderedDict25from .cookies import RequestsCookieJar, cookiejar_from_dict2627_hush_pyflakes = (RequestsCookieJar,)2828CERTIFI_BUNDLE_PATH = None29try: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()35except ImportError:36 pass3729NETRC_FILES = ('.netrc', '_netrc')3040# common paths for the OS's CA certificate bundle41POSSIBLE_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]535455def 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 None6131# if certifi is installed, use its CA bundle;32# otherwise, try and use the OS bundle64DEFAULT_CA_BUNDLE_PATH = CERTIFI_BUNDLE_PATH or get_os_ca_bundle_path()33DEFAULT_CA_BUNDLE_PATH = certs.where()346635def dict_to_sequence(d):36 """Returns an internal sequence dictionary update."""3738 if hasattr(d, 'items'):
525 unmodified lines