aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/x509
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2018-11-22 17:47:20 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2018-11-23 07:47:20 +0800
commiteda8a4156fbf66b29eb99fecc62cb2f55602d0fa (patch)
treeef2e3216be40892bf3e3a34641cce739f6a48e4a /src/cryptography/x509
parent3bd6159893cc8325f54a41d4108a6f4131aa65c4 (diff)
downloadcryptography-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.
Diffstat (limited to 'src/cryptography/x509')
-rw-r--r--src/cryptography/x509/general_name.py14
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 = (