Skip to content

Instantly share code, notes, and snippets.

@methane
Last active September 5, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save methane/1ab97181e74a33592314c7619bf34233 to your computer and use it in GitHub Desktop.
Save methane/1ab97181e74a33592314c7619bf34233 to your computer and use it in GitHub Desktop.
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index cdfa3729ad..60b16cbb38 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -13,7 +13,7 @@ __all__ = [
'quote',
]
-import time, calendar
+import time
SPACE = ' '
EMPTYSTRING = ''
@@ -186,6 +186,7 @@ def mktime_tz(data):
# No zone info, so localtime is better assumption than GMT
return time.mktime(data[:8] + (-1,))
else:
+ import calendar
t = calendar.timegm(data)
return t - data[9]
diff --git a/Lib/email/utils.py b/Lib/email/utils.py
index a759d23308..9474263ed7 100644
--- a/Lib/email/utils.py
+++ b/Lib/email/utils.py
@@ -25,8 +25,6 @@ __all__ = [
import os
import re
import time
-import random
-import socket
import datetime
import urllib.parse
@@ -193,6 +191,8 @@ def make_msgid(idstring=None, domain=None):
portion of the message id after the '@'. It defaults to the locally
defined hostname.
"""
+ import random
+ import socket
timeval = int(time.time()*100)
pid = os.getpid()
randint = random.getrandbits(64)
diff --git a/Lib/linecache.py b/Lib/linecache.py
index 3afcce1f0a..bbbc1b952f 100644
--- a/Lib/linecache.py
+++ b/Lib/linecache.py
@@ -8,7 +8,6 @@ that name.
import functools
import sys
import os
-import tokenize
__all__ = ["getline", "clearcache", "checkcache"]
@@ -133,6 +132,7 @@ def updatecache(filename, module_globals=None):
else:
return []
try:
+ import tokenize
with tokenize.open(fullname) as fp:
lines = fp.readlines()
except OSError:
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 8ad4a339a9..cda15f5207 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -90,8 +90,6 @@ ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE
ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY
"""
-import ipaddress
-import textwrap
import re
import sys
import os
@@ -272,6 +270,7 @@ def _ipaddress_match(ipname, host_ip):
(section 1.7.2 - "Out of Scope").
"""
# OpenSSL may add a trailing newline to a subjectAltName's IP address
+ import ipaddress
ip = ipaddress.ip_address(ipname.rstrip())
return ip == host_ip
@@ -288,6 +287,7 @@ def match_hostname(cert, hostname):
raise ValueError("empty or no certificate, match_hostname needs a "
"SSL socket or SSL context with either "
"CERT_OPTIONAL or CERT_REQUIRED")
+ import ipaddress
try:
host_ip = ipaddress.ip_address(hostname)
except ValueError:
@@ -1179,6 +1179,7 @@ PEM_FOOTER = "-----END CERTIFICATE-----"
def DER_cert_to_PEM_cert(der_cert_bytes):
"""Takes a certificate in binary DER format and returns the
PEM version of it as a string."""
+ import textwrap
f = str(base64.standard_b64encode(der_cert_bytes), 'ASCII', 'strict')
return (PEM_HEADER + '\n' +
$ ./python -c 'import logging'
- _frozen_importlib_external 0.601 [ms]
- zipimport 0.082 [ms]
- _codecs 0.070 [ms]
- codecs 0.637 [ms]
- encodings.aliases 0.402 [ms]
- encodings 1.620 [ms]
- encodings.utf_8 0.245 [ms]
- _signal 0.117 [ms]
- encodings.latin_1 0.279 [ms]
- _weakrefset 0.294 [ms]
- abc 0.585 [ms]
- io 1.016 [ms]
- errno 0.090 [ms]
- _stat 0.073 [ms]
- stat 0.326 [ms]
- genericpath 0.165 [ms]
- posixpath 0.389 [ms]
- _collections_abc 1.829 [ms]
- os 3.292 [ms]
- _sitebuiltins 0.219 [ms]
- sitecustomize 0.381 [ms]
- usercustomize 0.161 [ms]
- site 4.867 [ms]
- time 0.116 [ms]
- _operator 0.144 [ms]
- operator 0.492 [ms]
- keyword 0.174 [ms]
- _heapq 0.189 [ms]
- heapq 0.396 [ms]
- itertools 0.140 [ms]
- reprlib 0.224 [ms]
- _collections 0.081 [ms]
- collections 3.008 [ms]
- _functools 0.071 [ms]
- collections.abc 0.182 [ms]
- types 0.500 [ms]
- weakref 0.550 [ms]
- functools 2.014 [ms]
- enum 0.852 [ms]
- _sre 0.088 [ms]
- sre_constants 0.428 [ms]
- sre_parse 0.829 [ms]
- sre_compile 1.236 [ms]
- _locale 0.095 [ms]
- copyreg 0.204 [ms]
- re 3.056 [ms]
- token 0.217 [ms]
- tokenize 5.013 [ms]
- linecache 7.232 [ms]
- traceback 10.559 [ms]
- warnings 0.313 [ms]
- _string 0.126 [ms]
- string 2.149 [ms]
- threading 0.603 [ms]
- atexit 0.055 [ms]
- logging 14.921 [ms]
$ ./python -c 'import logging'
- _frozen_importlib_external 0.575 [ms]
- zipimport 0.082 [ms]
- _codecs 0.069 [ms]
- codecs 0.634 [ms]
- encodings.aliases 0.397 [ms]
- encodings 1.608 [ms]
- encodings.utf_8 0.243 [ms]
- _signal 0.117 [ms]
- encodings.latin_1 0.276 [ms]
- _weakrefset 0.293 [ms]
- abc 0.578 [ms]
- io 1.006 [ms]
- errno 0.097 [ms]
- _stat 0.074 [ms]
- stat 0.323 [ms]
- genericpath 0.162 [ms]
- posixpath 0.384 [ms]
- _collections_abc 1.803 [ms]
- os 3.269 [ms]
- _sitebuiltins 0.220 [ms]
- sitecustomize 0.386 [ms]
- usercustomize 0.165 [ms]
- site 4.845 [ms]
- time 0.114 [ms]
- _operator 0.135 [ms]
- operator 0.483 [ms]
- keyword 0.172 [ms]
- _heapq 0.189 [ms]
- heapq 0.393 [ms]
- itertools 0.140 [ms]
- reprlib 0.225 [ms]
- _collections 0.082 [ms]
- collections 2.990 [ms]
- _functools 0.073 [ms]
- collections.abc 0.179 [ms]
- types 0.496 [ms]
- weakref 0.553 [ms]
- functools 2.011 [ms]
- linecache 2.199 [ms]
- traceback 5.509 [ms]
- warnings 0.305 [ms]
- _string 0.049 [ms]
- enum 0.867 [ms]
- _sre 0.088 [ms]
- sre_constants 0.423 [ms]
- sre_parse 0.822 [ms]
- sre_compile 1.221 [ms]
- _locale 0.098 [ms]
- copyreg 0.201 [ms]
- re 3.048 [ms]
- string 5.192 [ms]
- threading 0.658 [ms]
- atexit 0.053 [ms]
- logging 12.884 [ms]
- _frozen_importlib_external 0.574 [ms]
- zipimport 0.084 [ms]
- _codecs 0.070 [ms]
- codecs 0.633 [ms]
- encodings.aliases 0.402 [ms]
- encodings 1.612 [ms]
- encodings.utf_8 0.241 [ms]
- _signal 0.121 [ms]
- encodings.latin_1 0.272 [ms]
- _weakrefset 0.287 [ms]
- abc 0.568 [ms]
- io 0.993 [ms]
- errno 0.091 [ms]
- _stat 0.075 [ms]
- stat 0.327 [ms]
- genericpath 0.161 [ms]
- posixpath 0.384 [ms]
- _collections_abc 1.798 [ms]
- os 3.257 [ms]
- _sitebuiltins 0.216 [ms]
- sitecustomize 0.377 [ms]
- usercustomize 0.161 [ms]
- site 4.817 [ms]
- asyncio.selectors 0.126 [ms]
- _operator 0.099 [ms]
- operator 0.864 [ms]
- keyword 0.173 [ms]
- _heapq 0.187 [ms]
- heapq 0.395 [ms]
- itertools 0.135 [ms]
- reprlib 0.229 [ms]
- _collections 0.084 [ms]
- collections 2.967 [ms]
- collections.abc 0.188 [ms]
- math 0.209 [ms]
- select 0.195 [ms]
- selectors 4.791 [ms]
- concurrent 0.164 [ms]
- time 0.117 [ms]
- _functools 0.072 [ms]
- types 0.308 [ms]
- weakref 0.483 [ms]
- functools 1.854 [ms]
- enum 0.788 [ms]
- _sre 0.161 [ms]
- sre_constants 0.361 [ms]
- sre_parse 0.752 [ms]
- sre_compile 1.224 [ms]
- _locale 0.097 [ms]
- copyreg 0.193 [ms]
- re 2.961 [ms]
- token 0.216 [ms]
- tokenize 4.976 [ms]
- linecache 7.017 [ms]
- traceback 7.356 [ms]
- warnings 0.319 [ms]
- _string 0.049 [ms]
- string 2.058 [ms]
- threading 0.666 [ms]
- atexit 0.052 [ms]
- logging 11.520 [ms]
- concurrent.futures._base 12.453 [ms]
- queue 0.283 [ms]
- signal 1.319 [ms]
- multiprocessing.process 1.659 [ms]
- _struct 0.231 [ms]
- struct 0.397 [ms]
- _compat_pickle 0.368 [ms]
- org 0.203 [ms]
- org.python 0.229 [ms]
- org.python.core 0.251 [ms]
- _pickle 0.296 [ms]
- pickle 2.265 [ms]
- _socket 0.364 [ms]
- socket 3.429 [ms]
- array 0.226 [ms]
- multiprocessing.reduction 6.288 [ms]
- multiprocessing.context 8.570 [ms]
- multiprocessing 8.795 [ms]
- fnmatch 0.190 [ms]
- zlib 0.263 [ms]
- _compression 0.274 [ms]
- _bz2 0.226 [ms]
- bz2 0.793 [ms]
- _lzma 0.274 [ms]
- lzma 0.623 [ms]
- pwd 0.066 [ms]
- grp 0.170 [ms]
- shutil 3.076 [ms]
- _hashlib 1.356 [ms]
- _blake2 0.199 [ms]
- _sha3 0.278 [ms]
- hashlib 2.123 [ms]
- _bisect 0.156 [ms]
- bisect 0.330 [ms]
- _random 0.167 [ms]
- random 3.038 [ms]
- tempfile 6.613 [ms]
- _multiprocessing 0.181 [ms]
- _posixsubprocess 0.168 [ms]
- subprocess 0.661 [ms]
- multiprocessing.util 0.971 [ms]
- _winapi 0.207 [ms]
- multiprocessing.connection 8.561 [ms]
- concurrent.futures.process 18.038 [ms]
- concurrent.futures.thread 0.230 [ms]
- concurrent.futures 31.122 [ms]
- _ast 1.706 [ms]
- ast 2.063 [ms]
- _opcode 0.160 [ms]
- opcode 0.483 [ms]
- dis 1.417 [ms]
- importlib 0.216 [ms]
- importlib.machinery 0.443 [ms]
- inspect 8.331 [ms]
- asyncio.compat 0.145 [ms]
- asyncio.events 0.498 [ms]
- asyncio.base_futures 0.193 [ms]
- asyncio.log 0.145 [ms]
- asyncio.coroutines 9.693 [ms]
- asyncio.base_tasks 0.171 [ms]
- _asyncio 0.446 [ms]
- asyncio.futures 0.699 [ms]
- asyncio.tasks 0.377 [ms]
- asyncio.base_events 42.522 [ms]
- asyncio.locks 0.506 [ms]
- asyncio.protocols 0.232 [ms]
- asyncio.queues 0.332 [ms]
- asyncio.streams 0.509 [ms]
- asyncio.subprocess 0.389 [ms]
- asyncio.transports 0.325 [ms]
- asyncio.base_subprocess 0.377 [ms]
- asyncio.constants 0.128 [ms]
- ipaddress 2.337 [ms]
- textwrap 2.321 [ms]
- _ssl 1.181 [ms]
- binascii 0.228 [ms]
- base64 0.514 [ms]
- ssl 9.863 [ms]
- asyncio.sslproto 0.365 [ms]
- asyncio.selector_events 10.786 [ms]
- asyncio.unix_events 12.003 [ms]
- asyncio 62.154 [ms]
- _frozen_importlib_external 0.573 [ms]
- zipimport 0.082 [ms]
- _codecs 0.070 [ms]
- codecs 0.642 [ms]
- encodings.aliases 0.401 [ms]
- encodings 1.633 [ms]
- encodings.utf_8 0.245 [ms]
- _signal 0.120 [ms]
- encodings.latin_1 0.276 [ms]
- _weakrefset 0.295 [ms]
- abc 0.576 [ms]
- io 1.002 [ms]
- errno 0.091 [ms]
- _stat 0.083 [ms]
- stat 0.335 [ms]
- genericpath 0.162 [ms]
- posixpath 0.389 [ms]
- _collections_abc 1.787 [ms]
- os 3.261 [ms]
- _sitebuiltins 0.218 [ms]
- sitecustomize 0.382 [ms]
- usercustomize 0.162 [ms]
- site 4.831 [ms]
- asyncio.selectors 0.127 [ms]
- _operator 0.101 [ms]
- operator 0.871 [ms]
- keyword 0.175 [ms]
- _heapq 0.191 [ms]
- heapq 0.398 [ms]
- itertools 0.140 [ms]
- reprlib 0.230 [ms]
- _collections 0.086 [ms]
- collections 2.977 [ms]
- collections.abc 0.197 [ms]
- math 0.212 [ms]
- select 0.197 [ms]
- selectors 4.811 [ms]
- concurrent 0.165 [ms]
- time 0.117 [ms]
- _functools 0.071 [ms]
- types 0.323 [ms]
- weakref 0.486 [ms]
- functools 1.864 [ms]
- linecache 2.042 [ms]
- traceback 2.375 [ms]
- warnings 0.304 [ms]
- _string 0.051 [ms]
- enum 0.848 [ms]
- _sre 0.090 [ms]
- sre_constants 0.357 [ms]
- sre_parse 0.752 [ms]
- sre_compile 1.163 [ms]
- _locale 0.097 [ms]
- copyreg 0.194 [ms]
- re 3.027 [ms]
- string 5.145 [ms]
- threading 0.672 [ms]
- atexit 0.056 [ms]
- logging 9.633 [ms]
- concurrent.futures._base 10.526 [ms]
- queue 0.285 [ms]
- signal 1.255 [ms]
- multiprocessing.process 1.594 [ms]
- _struct 0.229 [ms]
- struct 0.399 [ms]
- _compat_pickle 0.293 [ms]
- org 0.205 [ms]
- org.python 0.233 [ms]
- org.python.core 0.314 [ms]
- _pickle 0.302 [ms]
- pickle 2.274 [ms]
- _socket 0.493 [ms]
- socket 3.428 [ms]
- array 0.227 [ms]
- multiprocessing.reduction 6.360 [ms]
- multiprocessing.context 8.657 [ms]
- multiprocessing 8.881 [ms]
- fnmatch 0.178 [ms]
- zlib 0.263 [ms]
- _compression 0.276 [ms]
- _bz2 0.231 [ms]
- bz2 0.807 [ms]
- _lzma 0.275 [ms]
- lzma 0.564 [ms]
- pwd 0.065 [ms]
- grp 0.175 [ms]
- shutil 3.174 [ms]
- _hashlib 1.347 [ms]
- _blake2 0.198 [ms]
- _sha3 0.221 [ms]
- hashlib 2.046 [ms]
- _bisect 0.159 [ms]
- bisect 0.333 [ms]
- _random 0.169 [ms]
- random 2.979 [ms]
- tempfile 6.558 [ms]
- _multiprocessing 0.181 [ms]
- _posixsubprocess 0.175 [ms]
- subprocess 0.668 [ms]
- multiprocessing.util 1.057 [ms]
- _winapi 0.211 [ms]
- multiprocessing.connection 8.529 [ms]
- concurrent.futures.process 18.097 [ms]
- concurrent.futures.thread 0.230 [ms]
- concurrent.futures 29.259 [ms]
- _ast 1.723 [ms]
- ast 2.017 [ms]
- _opcode 0.163 [ms]
- opcode 0.540 [ms]
- dis 1.454 [ms]
- importlib 0.217 [ms]
- importlib.machinery 0.449 [ms]
- token 0.215 [ms]
- tokenize 1.873 [ms]
- inspect 10.304 [ms]
- asyncio.compat 0.150 [ms]
- asyncio.events 0.508 [ms]
- asyncio.base_futures 0.193 [ms]
- asyncio.log 0.144 [ms]
- asyncio.coroutines 11.680 [ms]
- asyncio.base_tasks 0.170 [ms]
- _asyncio 0.450 [ms]
- asyncio.futures 0.702 [ms]
- asyncio.tasks 0.379 [ms]
- asyncio.base_events 42.674 [ms]
- asyncio.locks 0.504 [ms]
- asyncio.protocols 0.234 [ms]
- asyncio.queues 0.327 [ms]
- asyncio.streams 0.505 [ms]
- asyncio.subprocess 0.387 [ms]
- asyncio.transports 0.329 [ms]
- asyncio.base_subprocess 0.382 [ms]
- asyncio.constants 0.128 [ms]
- _ssl 1.669 [ms]
- binascii 0.239 [ms]
- base64 0.543 [ms]
- ssl 5.643 [ms]
- asyncio.sslproto 0.369 [ms]
- asyncio.selector_events 6.645 [ms]
- asyncio.unix_events 7.875 [ms]
- asyncio 58.195 [ms]
- _frozen_importlib_external 0.574 [ms]
- zipimport 0.085 [ms]
- _codecs 0.070 [ms]
- codecs 0.633 [ms]
- encodings.aliases 0.399 [ms]
- encodings 1.614 [ms]
- encodings.utf_8 0.243 [ms]
- _signal 0.121 [ms]
- encodings.latin_1 0.277 [ms]
- _weakrefset 0.293 [ms]
- abc 0.575 [ms]
- io 1.006 [ms]
- errno 0.092 [ms]
- _stat 0.078 [ms]
- stat 0.333 [ms]
- genericpath 0.162 [ms]
- posixpath 0.386 [ms]
- _collections_abc 1.801 [ms]
- os 3.273 [ms]
- _sitebuiltins 0.216 [ms]
- sitecustomize 0.382 [ms]
- usercustomize 0.163 [ms]
- site 4.855 [ms]
- _functools 0.071 [ms]
- _operator 0.091 [ms]
- operator 0.483 [ms]
- keyword 0.173 [ms]
- _heapq 0.195 [ms]
- heapq 0.407 [ms]
- itertools 0.137 [ms]
- reprlib 0.226 [ms]
- _collections 0.086 [ms]
- collections 3.014 [ms]
- collections.abc 0.184 [ms]
- weakref 0.662 [ms]
- functools 4.708 [ms]
- types 5.020 [ms]
- enum 5.864 [ms]
- http 7.208 [ms]
- email 0.183 [ms]
- _sre 0.190 [ms]
- sre_constants 0.357 [ms]
- sre_parse 0.742 [ms]
- sre_compile 1.229 [ms]
- _locale 0.100 [ms]
- copyreg 0.191 [ms]
- re 2.181 [ms]
- email.errors 0.715 [ms]
- binascii 0.274 [ms]
- _string 0.052 [ms]
- string 2.208 [ms]
- email.quoprimime 2.512 [ms]
- _struct 0.214 [ms]
- struct 0.378 [ms]
- base64 0.625 [ms]
- email.base64mime 0.794 [ms]
- quopri 0.189 [ms]
- email.encoders 0.340 [ms]
- email.charset 0.577 [ms]
- email.header 5.394 [ms]
- time 0.109 [ms]
- warnings 0.387 [ms]
- math 0.210 [ms]
- _hashlib 1.362 [ms]
- _blake2 0.198 [ms]
- _sha3 0.214 [ms]
- hashlib 2.061 [ms]
- _bisect 0.158 [ms]
- bisect 0.338 [ms]
- _random 0.166 [ms]
- random 3.597 [ms]
- _socket 0.371 [ms]
- select 0.204 [ms]
- selectors 1.343 [ms]
- socket 4.221 [ms]
- _datetime 0.283 [ms]
- datetime 1.300 [ms]
- urllib 0.172 [ms]
- urllib.parse 2.409 [ms]
- locale 0.836 [ms]
- calendar 1.361 [ms]
- email._parseaddr 1.630 [ms]
- email.utils 14.710 [ms]
- email._policybase 20.519 [ms]
- email.feedparser 24.238 [ms]
- email.parser 24.727 [ms]
- uu 0.226 [ms]
- email._encoded_words 0.349 [ms]
- email.iterators 0.158 [ms]
- email.message 1.875 [ms]
- ipaddress 1.908 [ms]
- textwrap 2.309 [ms]
- _ssl 1.170 [ms]
- ssl 8.867 [ms]
- http.client 43.810 [ms]
- _frozen_importlib_external 0.577 [ms]
- zipimport 0.082 [ms]
- _codecs 0.069 [ms]
- codecs 0.636 [ms]
- encodings.aliases 0.398 [ms]
- encodings 1.625 [ms]
- encodings.utf_8 0.244 [ms]
- _signal 0.119 [ms]
- encodings.latin_1 0.282 [ms]
- _weakrefset 0.291 [ms]
- abc 0.574 [ms]
- io 1.000 [ms]
- errno 0.090 [ms]
- _stat 0.073 [ms]
- stat 0.332 [ms]
- genericpath 0.160 [ms]
- posixpath 0.383 [ms]
- _collections_abc 1.804 [ms]
- os 3.267 [ms]
- _sitebuiltins 0.216 [ms]
- sitecustomize 0.381 [ms]
- usercustomize 0.164 [ms]
- site 4.838 [ms]
- _functools 0.075 [ms]
- _operator 0.092 [ms]
- operator 0.486 [ms]
- keyword 0.177 [ms]
- _heapq 0.190 [ms]
- heapq 0.402 [ms]
- itertools 0.140 [ms]
- reprlib 0.223 [ms]
- _collections 0.086 [ms]
- collections 3.030 [ms]
- collections.abc 0.181 [ms]
- weakref 0.657 [ms]
- functools 4.729 [ms]
- types 5.040 [ms]
- enum 5.877 [ms]
- http 7.222 [ms]
- email 0.180 [ms]
- _sre 0.191 [ms]
- sre_constants 0.360 [ms]
- sre_parse 0.740 [ms]
- sre_compile 1.227 [ms]
- _locale 0.099 [ms]
- copyreg 0.190 [ms]
- re 2.175 [ms]
- email.errors 0.709 [ms]
- binascii 0.276 [ms]
- _string 0.052 [ms]
- string 2.206 [ms]
- email.quoprimime 2.511 [ms]
- _struct 0.214 [ms]
- struct 0.377 [ms]
- base64 0.624 [ms]
- email.base64mime 0.791 [ms]
- quopri 0.188 [ms]
- email.encoders 0.338 [ms]
- email.charset 0.565 [ms]
- email.header 5.385 [ms]
- time 0.111 [ms]
- math 0.211 [ms]
- _datetime 0.279 [ms]
- datetime 1.425 [ms]
- urllib 0.166 [ms]
- urllib.parse 2.376 [ms]
- email._parseaddr 0.255 [ms]
- email.utils 5.562 [ms]
- email._policybase 11.335 [ms]
- email.feedparser 15.034 [ms]
- email.parser 15.519 [ms]
- uu 0.208 [ms]
- email._encoded_words 0.360 [ms]
- email.iterators 0.159 [ms]
- email.message 1.291 [ms]
- _socket 0.611 [ms]
- select 0.200 [ms]
- selectors 1.227 [ms]
- socket 4.361 [ms]
- _ssl 2.763 [ms]
- warnings 0.341 [ms]
- ssl 6.564 [ms]
- http.client 36.119 [ms]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment