import os
import re
import time
-import random
-import socket
import datetime
import urllib.parse
from email._parseaddr import parsedate, parsedate_tz, _parsedate_tz
-# Intrapackage imports
-from email.charset import Charset
-
COMMASPACE = ', '
EMPTYSTRING = ''
UEMPTYSTRING = ''
name.encode('ascii')
except UnicodeEncodeError:
if isinstance(charset, str):
+ # lazy import to improve module import time
+ from email.charset import Charset
charset = Charset(charset)
encoded_name = charset.header_encode(name)
return "%s <%s>" % (encoded_name, address)
portion of the message id after the '@'. It defaults to the locally
defined hostname.
"""
+ # Lazy imports to speedup module import time
+ # (no other functions in email.utils need these modules)
+ import random
+ import socket
+
timeval = int(time.time()*100)
pid = os.getpid()
randint = random.getrandbits(64)
--- /dev/null
+Reduce the import time of :mod:`email.utils` by around 43%. This results in
+the import time of :mod:`email.message` falling by around 18%, which in turn
+reduces the import time of :mod:`importlib.metadata` by around 6%. Patch by
+Alex Waygood.