Skip to content

Commit

Permalink
More deferred imports to save ~20ms
Browse files Browse the repository at this point in the history
  • Loading branch information
heapcrash committed May 31, 2021
1 parent 37b5e42 commit 0bf308b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The table below shows which release corresponds to each branch, and what date th
- [#1893][1893] Fix bytes warning in "pwn cyclic"
- [#1903][1903] Add zsh completion script
- [#1904][1904] Add bash completion script
- [#1906][1906] Defer import of urlrequests and urllib
- [#1906][1906] Defer import of several modules to save on startup time

[1733]: https://github.com/Gallopsled/pwntools/pull/1733
[1876]: https://github.com/Gallopsled/pwntools/pull/1876
Expand Down
4 changes: 3 additions & 1 deletion pwnlib/tubes/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import socket
import socks
import ssl as _ssl

from pwnlib.log import getLogger
from pwnlib.timeout import Timeout
Expand Down Expand Up @@ -85,6 +84,9 @@ def __init__(self, host, port,
self.lhost, self.lport = self.sock.getsockname()[:2]

if ssl:
# Deferred import to save startup time
import ssl as _ssl

ssl_args = ssl_args or {}
ssl_context = ssl_context or _ssl.SSLContext(_ssl.PROTOCOL_TLSv1_2)
if isinstance(sni, str):
Expand Down
5 changes: 3 additions & 2 deletions pwnlib/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import os
import time

from six.moves.xmlrpc_client import ServerProxy

import packaging.version

from pwnlib.args import args
Expand Down Expand Up @@ -75,6 +73,9 @@ def available_on_pypi(prerelease=current_version.is_prerelease):
>>> available_on_pypi(prerelease=False).is_prerelease
False
"""
# Deferred import to save startup time
from six.moves.xmlrpc_client import ServerProxy

versions = getattr(available_on_pypi, 'cached', None)
if versions is None:
client = ServerProxy('https://pypi.python.org/pypi')
Expand Down

0 comments on commit 0bf308b

Please sign in to comment.