diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2018-11-22 17:47:20 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2018-11-23 07:47:20 +0800 |
commit | eda8a4156fbf66b29eb99fecc62cb2f55602d0fa (patch) | |
tree | ef2e3216be40892bf3e3a34641cce739f6a48e4a | |
parent | 3bd6159893cc8325f54a41d4108a6f4131aa65c4 (diff) | |
download | cryptography-eda8a4156fbf66b29eb99fecc62cb2f55602d0fa.tar.gz cryptography-eda8a4156fbf66b29eb99fecc62cb2f55602d0fa.tar.bz2 cryptography-eda8a4156fbf66b29eb99fecc62cb2f55602d0fa.zip |
Import idna lazily to reduce our memory consumption (#4601)
We only use idna in deprecated paths at this point, so we shouldn't make people pay for it.
-rw-r--r-- | src/cryptography/x509/general_name.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/cryptography/x509/general_name.py b/src/cryptography/x509/general_name.py index 26f389a5..42082746 100644 --- a/src/cryptography/x509/general_name.py +++ b/src/cryptography/x509/general_name.py @@ -9,8 +9,6 @@ import ipaddress import warnings from email.utils import parseaddr -import idna - import six from six.moves import urllib_parse @@ -83,6 +81,10 @@ 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 + _, address = parseaddr(value) parts = address.split(u"@") return parts[0] + "@" + idna.encode(parts[1]).decode("ascii") @@ -104,6 +106,10 @@ 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 + # Retain prefixes '*.' for common/alt names and '.' for name constraints for prefix in ['*.', '.']: if value.startswith(prefix): @@ -187,6 +193,10 @@ 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 + parsed = urllib_parse.urlparse(value) if parsed.port: netloc = ( |