diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2016-11-15 07:34:55 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2016-11-14 18:34:55 -0500 |
commit | 9977786b56294292fb7da9eabc0f3b94d638e8a7 (patch) | |
tree | ebab975a1fb5006d2e7be6e5921b7513739caf55 /src | |
parent | 3a15b03e92c9fdeadff04ddd2ce505028b279b86 (diff) | |
download | cryptography-9977786b56294292fb7da9eabc0f3b94d638e8a7.tar.gz cryptography-9977786b56294292fb7da9eabc0f3b94d638e8a7.tar.bz2 cryptography-9977786b56294292fb7da9eabc0f3b94d638e8a7.zip |
workaround for application bundling tools (#3235)
* cx_freeze support for default_backend
* updated tabing to spaces
* corrected spacing
* moved finding backend to backends __init__
* update to check to see if sys is frozen
* corrected pep8 issues
* update based on comments
* changes to simplify, support testing, and improve comments
* add changelog entry
* right, coverage. I remember now. Time for some contortions.
* updated with review feedback
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptography/hazmat/backends/__init__.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/cryptography/hazmat/backends/__init__.py b/src/cryptography/hazmat/backends/__init__.py index e66f9e10..161a1879 100644 --- a/src/cryptography/hazmat/backends/__init__.py +++ b/src/cryptography/hazmat/backends/__init__.py @@ -16,7 +16,7 @@ def _available_backends(): global _available_backends_list if _available_backends_list is None: - _available_backends_list = [ + entry_point_backends = [ # DeprecatedIn16 # setuptools 11.3 deprecated support for the require parameter to # load(), and introduced the new resolve() method instead. @@ -29,8 +29,38 @@ def _available_backends(): ) ] + _available_backends_list = _backend_import_fallback( + entry_point_backends + ) + return _available_backends_list + +def _backend_import_fallback(backends): + # If backends already exist just return them. This branch is here + # to get full line coverage from our tests. + if backends: + return backends + + # if iter_entry_points fails to find any backends then manually try to + # import our current backends as a workaround for issues with application + # bundlers like pyinstaller, cx_freeze, etc + + # OpenSSL is guaranteed to be present until we unbundle the backends. + from cryptography.hazmat.backends.openssl.backend import backend as be_ossl + backends = [be_ossl] + try: + from cryptography.hazmat.backends.commoncrypto.backend import ( + backend as be_cc + ) + except ImportError: + pass + else: + backends.append(be_cc) + + return backends + + _default_backend = None |