diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2018-12-07 11:43:38 +0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2018-12-06 22:43:38 -0500 |
commit | 7e422821b9f800f5345c37011c510dc9e76f552c (patch) | |
tree | 684836bedeb4ae9d898a014068f1555cd25c58aa /src/cryptography/x509 | |
parent | fec719b60441b1e69bcca26446b8025bb69ee1fd (diff) | |
download | cryptography-7e422821b9f800f5345c37011c510dc9e76f552c.tar.gz cryptography-7e422821b9f800f5345c37011c510dc9e76f552c.tar.bz2 cryptography-7e422821b9f800f5345c37011c510dc9e76f552c.zip |
remove idna as a primary dependency (#4624)
* remove idna as a primary dependency
* empty commit
* dynamodb test fix (thanks to Matt Bullock)
* review feedback
Diffstat (limited to 'src/cryptography/x509')
-rw-r--r-- | src/cryptography/x509/general_name.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/cryptography/x509/general_name.py b/src/cryptography/x509/general_name.py index 42082746..1b0f8c8f 100644 --- a/src/cryptography/x509/general_name.py +++ b/src/cryptography/x509/general_name.py @@ -30,6 +30,20 @@ _GENERAL_NAMES = { } +def _lazy_import_idna(): + # Import idna lazily becase it allocates a decent amount of memory, and + # we're only using it in deprecated paths. + try: + import idna + return idna + except ImportError: + raise ImportError( + "idna is not installed, but a deprecated feature that requires it" + " was used. See: https://cryptography.io/en/latest/faq/#importe" + "rror-idna-is-not-installed" + ) + + class UnsupportedGeneralNameType(Exception): def __init__(self, msg, type): super(UnsupportedGeneralNameType, self).__init__(msg) @@ -81,10 +95,7 @@ class RFC822Name(object): return instance def _idna_encode(self, value): - # Import idna lazily becase it allocates a decent amoutn of memory, and - # we're only using it in deprecated paths. - import idna - + idna = _lazy_import_idna() _, address = parseaddr(value) parts = address.split(u"@") return parts[0] + "@" + idna.encode(parts[1]).decode("ascii") @@ -106,10 +117,7 @@ class RFC822Name(object): def _idna_encode(value): - # Import idna lazily becase it allocates a decent amoutn of memory, and - # we're only using it in deprecated paths. - import idna - + idna = _lazy_import_idna() # Retain prefixes '*.' for common/alt names and '.' for name constraints for prefix in ['*.', '.']: if value.startswith(prefix): @@ -193,10 +201,7 @@ class UniformResourceIdentifier(object): return instance def _idna_encode(self, value): - # Import idna lazily becase it allocates a decent amoutn of memory, and - # we're only using it in deprecated paths. - import idna - + idna = _lazy_import_idna() parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( |