mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
gh-109653: Improve the import time of email.utils
(#109824)
This commit is contained in:
parent
e7331365b4
commit
aa3f419acb
2 changed files with 11 additions and 5 deletions
|
@ -25,8 +25,6 @@ __all__ = [
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import random
|
|
||||||
import socket
|
|
||||||
import datetime
|
import datetime
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
@ -36,9 +34,6 @@ from email._parseaddr import mktime_tz
|
||||||
|
|
||||||
from email._parseaddr import parsedate, parsedate_tz, _parsedate_tz
|
from email._parseaddr import parsedate, parsedate_tz, _parsedate_tz
|
||||||
|
|
||||||
# Intrapackage imports
|
|
||||||
from email.charset import Charset
|
|
||||||
|
|
||||||
COMMASPACE = ', '
|
COMMASPACE = ', '
|
||||||
EMPTYSTRING = ''
|
EMPTYSTRING = ''
|
||||||
UEMPTYSTRING = ''
|
UEMPTYSTRING = ''
|
||||||
|
@ -94,6 +89,8 @@ def formataddr(pair, charset='utf-8'):
|
||||||
name.encode('ascii')
|
name.encode('ascii')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
if isinstance(charset, str):
|
if isinstance(charset, str):
|
||||||
|
# lazy import to improve module import time
|
||||||
|
from email.charset import Charset
|
||||||
charset = Charset(charset)
|
charset = Charset(charset)
|
||||||
encoded_name = charset.header_encode(name)
|
encoded_name = charset.header_encode(name)
|
||||||
return "%s <%s>" % (encoded_name, address)
|
return "%s <%s>" % (encoded_name, address)
|
||||||
|
@ -181,6 +178,11 @@ def make_msgid(idstring=None, domain=None):
|
||||||
portion of the message id after the '@'. It defaults to the locally
|
portion of the message id after the '@'. It defaults to the locally
|
||||||
defined hostname.
|
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)
|
timeval = int(time.time()*100)
|
||||||
pid = os.getpid()
|
pid = os.getpid()
|
||||||
randint = random.getrandbits(64)
|
randint = random.getrandbits(64)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
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.
|
Loading…
Add table
Add a link
Reference in a new issue