From 5084aae7b2ca073c33ed55de48429a44b20c6966 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 6 Mar 2026 11:53:07 +0000 Subject: [PATCH] WIP --- mitogen/core.py | 51 ++- mitogen/imports/__init__.py | 30 ++ mitogen/imports/stdlibs/__init__.py | 0 mitogen/imports/stdlibs/py24.py | 440 ++++++++++++++++++++++++++ mitogen/imports/stdlibs/py25.py | 437 ++++++++++++++++++++++++++ mitogen/imports/stdlibs/py26.py | 454 +++++++++++++++++++++++++++ mitogen/imports/stdlibs/py27.py | 462 ++++++++++++++++++++++++++++ mitogen/imports/stdlibs/py36.py | 313 +++++++++++++++++++ mitogen/imports/stdlibs/py37.py | 317 +++++++++++++++++++ mitogen/imports/stdlibs/py38.py | 320 +++++++++++++++++++ mitogen/imports/stdlibs/py39.py | 324 +++++++++++++++++++ mitogen/master.py | 5 +- mitogen/parent.py | 1 + stdlibs_gen.py | 31 ++ tests/importer_test.py | 16 +- tests/responder_test.py | 6 +- 16 files changed, 3167 insertions(+), 40 deletions(-) create mode 100644 mitogen/imports/stdlibs/__init__.py create mode 100644 mitogen/imports/stdlibs/py24.py create mode 100644 mitogen/imports/stdlibs/py25.py create mode 100644 mitogen/imports/stdlibs/py26.py create mode 100644 mitogen/imports/stdlibs/py27.py create mode 100644 mitogen/imports/stdlibs/py36.py create mode 100644 mitogen/imports/stdlibs/py37.py create mode 100644 mitogen/imports/stdlibs/py38.py create mode 100644 mitogen/imports/stdlibs/py39.py create mode 100644 stdlibs_gen.py diff --git a/mitogen/core.py b/mitogen/core.py index cfda0a979..24561a608 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -739,7 +739,7 @@ def enable_profiling(econtext=None): def import_module(modname): """ - Import `module` and return the attribute named `attr`. + Return the module with absolute name `modname`, importing it as necessary. """ return __import__(modname, None, None, ['']) @@ -1319,18 +1319,22 @@ class ImportPolicy(object): :param blocks: Prefixes always denied by the responder, only local versions can be used. + + :param unsuitables: + Prefixes unsuitable to be served, e.g. because they're Python stdlib, + platform specific. An optimisation to reduce futile round trips. """ - def __init__(self, overrides=(), blocks=()): + def __init__(self, overrides=(), blocks=(), unsuitables=()): self.overrides = set(overrides) self.blocks = set(blocks) - self._always = set(Importer.ALWAYS_BLACKLIST) + self.unsuitables = set(unsuitables) def denied(self, fullname): fullnames = frozenset(module_lineage(fullname)) if self.overrides and not self.overrides.intersection(fullnames): return ModuleDeniedByOverridesError if self.blocks.intersection(fullnames): return ModuleDeniedByBlocksError - if self._always.intersection(fullnames): return ModuleUnsuitableError + if self.unsuitables.intersection(fullnames): return ModuleUnsuitableError return False def denied_raise(self, fullname): @@ -1340,9 +1344,13 @@ def denied_raise(self, fullname): def overriden(self, fullname): return bool(self.overrides.intersection(module_lineage(fullname))) + def unsuited(self, fullname): + return bool(self.unsuitables.intersection(module_lineage(fullname))) + def __repr__(self): - args = (type(self).__name__, self.overrides, self.blocks) - return '%s(overrides=%r, blocks=%r)' % args + name = type(self).__name__ + args = (name, self.overrides, self.blocks, self.unsuitables) + return '%s(overrides=%r, blocks=%r, unsuitables=%r)' % args class Importer(object): @@ -1381,29 +1389,6 @@ class Importer(object): 'utils', ] - ALWAYS_BLACKLIST = [ - # 2.x generates needless imports for 'builtins', while 3.x does the - # same for '__builtin__'. The correct one is built-in, the other always - # a negative round-trip. - 'builtins', - '__builtin__', - - # On some Python releases (e.g. 3.8, 3.9) the subprocess module tries - # to import of this Windows-only builtin module. - 'msvcrt', - - # Python 2.x module that was renamed to _thread in 3.x. - # This entry avoids a roundtrip on 2.x -> 3.x. - 'thread', - - # org.python.core imported by copy, pickle, xml.sax; breaks Jython, but - # very unlikely to trigger a bug report. - 'org', - ] - - if sys.version_info >= (3, 0): - ALWAYS_BLACKLIST += ['cStringIO'] - def __init__(self, router, context, core_src, policy): self._log = logging.getLogger('mitogen.importer') self._context = context @@ -1487,6 +1472,9 @@ def find_module(self, fullname, path=None): if hasattr(_tls, 'running'): return None + if self.policy.unsuited(fullname): + return None + _tls.running = True try: #_v and self._log.debug('Python requested %r', fullname) @@ -1536,6 +1524,10 @@ def find_spec(self, fullname, path, target=None): if fullname.endswith('.'): return None + if self.policy.unsuited(fullname): + log.debug('Skipping %s. It is unsuited.') + return None + pkgname, _, modname = fullname.rpartition('.') if pkgname and modname not in self._present.get(pkgname, ()): log.debug('Skipping %s. Parent %s has no submodule %s', @@ -4205,6 +4197,7 @@ def _setup_importer(self): policy = ImportPolicy( self.config['import_overrides'], self.config['import_blocks'], + self.config['import_unsuitables'], ) importer = Importer( self.router, diff --git a/mitogen/imports/__init__.py b/mitogen/imports/__init__.py index bf246e267..628c86d00 100644 --- a/mitogen/imports/__init__.py +++ b/mitogen/imports/__init__.py @@ -36,3 +36,33 @@ def codeobj_imports(co): * `names`: tuple of names in `from mod import ..`. """ return _code_imports(co.co_code, co.co_consts, co.co_names) + + +def stdlib_module_names(version_info=None): + """ + Return a set of known module names for a Python version. + """ + if version_info is None: + version_info = sys.version_info + if version_info >= (3, 10): + return sys.stdlib_module_names + + modname = "%s.stdlibs.py%d%d" % (__name__, version_info[0], version_info[1]) + return __import__(modname, None, None, ['']).module_names + + +def unsuitable_module_names(version_info=None): + """ + Return a set of module names known to be unsuitable for serving by Mitogen. + """ + if version_info is None: + version_info = sys.version_info + names = set([ + 'org', # Jython, Imported by copy, pickle, & xml.sax. + ]) + names.update(stdlib_module_names(version_info)) + if version_info >= (3, 0): + names.update(stdlib_module_names((2, 7))) + else: + names.update(stdlib_module_names((3, 6))) + return names diff --git a/mitogen/imports/stdlibs/__init__.py b/mitogen/imports/stdlibs/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/mitogen/imports/stdlibs/py24.py b/mitogen/imports/stdlibs/py24.py new file mode 100644 index 000000000..a8556ffec --- /dev/null +++ b/mitogen/imports/stdlibs/py24.py @@ -0,0 +1,440 @@ +module_names = frozenset([ + 'AL', + 'Audio_mac', + 'BaseHTTPServer', + 'Bastion', + 'CD', + 'CDIO', + 'CDROM', + 'CGIHTTPServer', + 'CL', + 'CL_old', + 'Canvas', + 'Carbon', + 'ColorPicker', + 'ConfigParser', + 'Cookie', + 'DEVICE', + 'DLFCN', + 'Dialog', + 'DocXMLRPCServer', + 'ERRNO', + 'EasyDialogs', + 'FILE', + 'FL', + 'FileDialog', + 'FixTk', + 'FrameWork', + 'GET', + 'GL', + 'GLWS', + 'HTMLParser', + 'IN', + 'IOCTL', + 'MacOS', + 'MimeWriter', + 'MiniAEFrame', + 'Nav', + 'OSATerminology', + 'Para', + 'PixMapWrapper', + 'Queue', + 'SOCKET', + 'STROPTS', + 'SUNAUDIODEV', + 'SV', + 'ScrolledText', + 'SimpleDialog', + 'SimpleHTTPServer', + 'SimpleXMLRPCServer', + 'SocketServer', + 'StringIO', + 'TYPES', + 'Tix', + 'Tkconstants', + 'Tkdnd', + 'Tkinter', + 'UserDict', + 'UserList', + 'UserString', + 'WAIT', + 'WASTEconst', + '_AE', + '_AH', + '_App', + '_CF', + '_CG', + '_CarbonEvt', + '_Cm', + '_Ctl', + '_Dlg', + '_Drag', + '_Evt', + '_File', + '_Fm', + '_Folder', + '_Help', + '_IBCarbon', + '_Icn', + '_LWPCookieJar', + '_Launch', + '_List', + '_Menu', + '_Mlte', + '_MozillaCookieJar', + '_OSA', + '_Qd', + '_Qdoffs', + '_Qt', + '_Res', + '_Scrap', + '_Snd', + '_TE', + '_Win', + '__builtin__', + '__future__', + '__hello__', + '__phello__', + '_bisect', + '_bsddb', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_csv', + '_curses', + '_curses_panel', + '_emx_link', + '_heapq', + '_hotshot', + '_locale', + '_multibytecodec', + '_pybsddb', + '_random', + '_socket', + '_sre', + '_ssl', + '_strptime', + '_subprocess', + '_symtable', + '_testcapi', + '_threading_local', + '_tkinter', + '_weakref', + '_winreg', + 'addpack', + 'aepack', + 'aetools', + 'aetypes', + 'aifc', + 'al', + 'anydbm', + 'applesingle', + 'appletrawmain', + 'appletrunner', + 'argvemulator', + 'array', + 'asynchat', + 'asyncore', + 'atexit', + 'audiodev', + 'audioop', + 'autoGIL', + 'base64', + 'bdb', + 'bgenlocations', + 'binascii', + 'binhex', + 'bisect', + 'bsddb', + 'bsddb185', + 'buildtools', + 'bundlebuilder', + 'bz2', + 'cPickle', + 'cStringIO', + 'calendar', + 'cd', + 'cddb', + 'cdplayer', + 'cfmfile', + 'cgi', + 'cgitb', + 'chunk', + 'cl', + 'cmath', + 'cmd', + 'cmp', + 'cmpcache', + 'code', + 'codecs', + 'codehack', + 'codeop', + 'collections', + 'colorsys', + 'commands', + 'compileall', + 'compiler', + 'cookielib', + 'copy', + 'copy_reg', + 'crypt', + 'csv', + 'curses', + 'datetime', + 'dbhash', + 'dbm', + 'decimal', + 'difflib', + 'dircache', + 'dircmp', + 'dis', + 'distutils', + 'dl', + 'doctest', + 'dumbdbm', + 'dummy_thread', + 'dummy_threading', + 'dump', + 'email', + 'encodings', + 'errno', + 'exceptions', + 'fcntl', + 'filecmp', + 'fileinput', + 'find', + 'findertools', + 'fl', + 'flp', + 'fm', + 'fmt', + 'fnmatch', + 'formatter', + 'fpectl', + 'fpetest', + 'fpformat', + 'ftplib', + 'gc', + 'gdbm', + 'gensuitemodule', + 'gestalt', + 'getopt', + 'getpass', + 'gettext', + 'gl', + 'glob', + 'gopherlib', + 'grep', + 'grp', + 'gzip', + 'heapq', + 'hmac', + 'hotshot', + 'htmlentitydefs', + 'htmllib', + 'httplib', + 'ic', + 'icglue', + 'icopen', + 'idlelib', + 'ihooks', + 'imageop', + 'imaplib', + 'imgfile', + 'imghdr', + 'imp', + 'imputil', + 'inspect', + 'itertools', + 'jpeg', + 'keyword', + 'linecache', + 'linuxaudiodev', + 'locale', + 'lockfile', + 'logging', + 'macerrors', + 'macfs', + 'macostools', + 'macpath', + 'macresource', + 'macurl2path', + 'mailbox', + 'mailcap', + 'markupbase', + 'marshal', + 'math', + 'md5', + 'mhlib', + 'mimetools', + 'mimetypes', + 'mimify', + 'mmap', + 'modulefinder', + 'msvcrt', + 'multifile', + 'mutex', + 'netrc', + 'new', + 'newdir', + 'ni', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'opcode', + 'operator', + 'optparse', + 'os', + 'os2', + 'os2emxpath', + 'ossaudiodev', + 'packmail', + 'panel', + 'panelparser', + 'parser', + 'pcre', + 'pdb', + 'pickle', + 'pickletools', + 'pimp', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'poly', + 'popen2', + 'poplib', + 'posix', + 'posixfile', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pure', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pyexpat', + 'quopri', + 'rand', + 'random', + 're', + 'readcd', + 'readline', + 'reconvert', + 'regex', + 'regex_syntax', + 'regsub', + 'repr', + 'resource', + 'rexec', + 'rfc822', + 'rgbimg', + 'riscosenviron', + 'riscospath', + 'rlcompleter', + 'robotparser', + 'rourl2path', + 'sched', + 'select', + 'sets', + 'sgi', + 'sgmllib', + 'sha', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'sre', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'stat', + 'statcache', + 'statvfs', + 'string', + 'stringold', + 'stringprep', + 'strop', + 'struct', + 'subprocess', + 'sunau', + 'sunaudio', + 'sunaudiodev', + 'sv', + 'symbol', + 'symtable', + 'sys', + 'syslog', + 'tabnanny', + 'tarfile', + 'tb', + 'telnetlib', + 'tempfile', + 'terminalcommand', + 'termios', + 'textwrap', + 'this', + 'thread', + 'threading', + 'time', + 'timeit', + 'timing', + 'tkColorChooser', + 'tkCommonDialog', + 'tkFileDialog', + 'tkFont', + 'tkMessageBox', + 'tkSimpleDialog', + 'toaiff', + 'token', + 'tokenize', + 'torgb', + 'trace', + 'traceback', + 'tty', + 'turtle', + 'types', + 'tzparse', + 'unicodedata', + 'unittest', + 'urllib', + 'urllib2', + 'urlparse', + 'user', + 'util', + 'uu', + 'videoreader', + 'warnings', + 'waste', + 'wave', + 'weakref', + 'webbrowser', + 'whatsound', + 'whichdb', + 'whrandom', + 'winsound', + 'xdrlib', + 'xml', + 'xmllib', + 'xmlrpclib', + 'xx', + 'xxsubtype', + 'zipfile', + 'zipimport', + 'zlib', + 'zmod', +]) diff --git a/mitogen/imports/stdlibs/py25.py b/mitogen/imports/stdlibs/py25.py new file mode 100644 index 000000000..30337bc4e --- /dev/null +++ b/mitogen/imports/stdlibs/py25.py @@ -0,0 +1,437 @@ +module_names = frozenset([ + 'AL', + 'Audio_mac', + 'BaseHTTPServer', + 'Bastion', + 'CD', + 'CDIO', + 'CDROM', + 'CGIHTTPServer', + 'CL', + 'CL_old', + 'Canvas', + 'Carbon', + 'ColorPicker', + 'ConfigParser', + 'Cookie', + 'DEVICE', + 'DLFCN', + 'Dialog', + 'DocXMLRPCServer', + 'ERRNO', + 'EasyDialogs', + 'FILE', + 'FL', + 'FileDialog', + 'FixTk', + 'FrameWork', + 'GET', + 'GL', + 'GLWS', + 'HTMLParser', + 'IN', + 'IOCTL', + 'MacOS', + 'MimeWriter', + 'MiniAEFrame', + 'Nav', + 'OSATerminology', + 'PixMapWrapper', + 'Queue', + 'SOCKET', + 'STROPTS', + 'SUNAUDIODEV', + 'SV', + 'ScrolledText', + 'SimpleDialog', + 'SimpleHTTPServer', + 'SimpleXMLRPCServer', + 'SocketServer', + 'StringIO', + 'TYPES', + 'Tix', + 'Tkconstants', + 'Tkdnd', + 'Tkinter', + 'UserDict', + 'UserList', + 'UserString', + 'WAIT', + '_AE', + '_AH', + '_App', + '_CF', + '_CG', + '_CarbonEvt', + '_Cm', + '_Ctl', + '_Dlg', + '_Drag', + '_Evt', + '_File', + '_Fm', + '_Folder', + '_Help', + '_IBCarbon', + '_Icn', + '_LWPCookieJar', + '_Launch', + '_List', + '_Menu', + '_Mlte', + '_MozillaCookieJar', + '_OSA', + '_Qd', + '_Qdoffs', + '_Qt', + '_Res', + '_Scrap', + '_Snd', + '_TE', + '_Win', + '__builtin__', + '__future__', + '__hello__', + '__phello__', + '_ast', + '_bisect', + '_bsddb', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_elementtree', + '_emx_link', + '_functools', + '_hashlib', + '_heapq', + '_hotshot', + '_locale', + '_lsprof', + '_md5', + '_msi', + '_multibytecodec', + '_pybsddb', + '_random', + '_sha', + '_sha256', + '_sha512', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_strptime', + '_struct', + '_subprocess', + '_symtable', + '_testcapi', + '_threading_local', + '_tkinter', + '_types', + '_weakref', + '_winreg', + 'aepack', + 'aetools', + 'aetypes', + 'aifc', + 'al', + 'anydbm', + 'applesingle', + 'appletrawmain', + 'appletrunner', + 'argvemulator', + 'array', + 'asynchat', + 'asyncore', + 'atexit', + 'audiodev', + 'audioop', + 'autoGIL', + 'base64', + 'bdb', + 'bgenlocations', + 'binascii', + 'binhex', + 'bisect', + 'bsddb', + 'bsddb185', + 'buildtools', + 'bundlebuilder', + 'bz2', + 'cPickle', + 'cProfile', + 'cStringIO', + 'calendar', + 'cd', + 'cddb', + 'cdplayer', + 'cfmfile', + 'cgi', + 'cgitb', + 'chunk', + 'cl', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'commands', + 'compileall', + 'compiler', + 'contextlib', + 'cookielib', + 'copy', + 'copy_reg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'datetime', + 'dbhash', + 'dbm', + 'decimal', + 'difflib', + 'dircache', + 'dis', + 'distutils', + 'dl', + 'doctest', + 'dumbdbm', + 'dummy_thread', + 'dummy_threading', + 'email', + 'encodings', + 'errno', + 'exceptions', + 'fcntl', + 'filecmp', + 'fileinput', + 'findertools', + 'fl', + 'flp', + 'fm', + 'fnmatch', + 'formatter', + 'fpectl', + 'fpetest', + 'fpformat', + 'ftplib', + 'functools', + 'gc', + 'gdbm', + 'gensuitemodule', + 'gestalt', + 'getopt', + 'getpass', + 'gettext', + 'gl', + 'glob', + 'gopherlib', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'hotshot', + 'htmlentitydefs', + 'htmllib', + 'httplib', + 'ic', + 'icglue', + 'icopen', + 'idlelib', + 'ihooks', + 'imageop', + 'imaplib', + 'imgfile', + 'imghdr', + 'imp', + 'imputil', + 'inspect', + 'itertools', + 'jpeg', + 'keyword', + 'linecache', + 'linuxaudiodev', + 'locale', + 'logging', + 'macerrors', + 'macfs', + 'macostools', + 'macpath', + 'macresource', + 'macurl2path', + 'mailbox', + 'mailcap', + 'markupbase', + 'marshal', + 'math', + 'md5', + 'mhlib', + 'mimetools', + 'mimetypes', + 'mimify', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multifile', + 'mutex', + 'netrc', + 'new', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'opcode', + 'operator', + 'optparse', + 'os', + 'os2', + 'os2emxpath', + 'ossaudiodev', + 'panel', + 'panelparser', + 'parser', + 'pcre', + 'pdb', + 'pickle', + 'pickletools', + 'pimp', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'popen2', + 'poplib', + 'posix', + 'posixfile', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pure', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pyexpat', + 'quopri', + 'random', + 're', + 'readcd', + 'readline', + 'repr', + 'resource', + 'rexec', + 'rfc822', + 'rgbimg', + 'riscosenviron', + 'riscospath', + 'rlcompleter', + 'robotparser', + 'rourl2path', + 'runpy', + 'sched', + 'select', + 'sets', + 'sgi', + 'sgmllib', + 'sha', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'spwd', + 'sqlite3', + 'sre', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'stat', + 'statvfs', + 'string', + 'stringold', + 'stringprep', + 'strop', + 'struct', + 'subprocess', + 'sunau', + 'sunaudio', + 'sunaudiodev', + 'sv', + 'symbol', + 'symtable', + 'sys', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'terminalcommand', + 'termios', + 'textwrap', + 'this', + 'thread', + 'threading', + 'time', + 'timeit', + 'timing', + 'tkColorChooser', + 'tkCommonDialog', + 'tkFileDialog', + 'tkFont', + 'tkMessageBox', + 'tkSimpleDialog', + 'toaiff', + 'token', + 'tokenize', + 'torgb', + 'trace', + 'traceback', + 'tty', + 'turtle', + 'types', + 'unicodedata', + 'unittest', + 'urllib', + 'urllib2', + 'urlparse', + 'user', + 'uu', + 'uuid', + 'videoreader', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'whichdb', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmllib', + 'xmlrpclib', + 'xx', + 'xxsubtype', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py26.py b/mitogen/imports/stdlibs/py26.py new file mode 100644 index 000000000..cdcfc1798 --- /dev/null +++ b/mitogen/imports/stdlibs/py26.py @@ -0,0 +1,454 @@ +module_names = frozenset([ + 'AL', + 'Audio_mac', + 'BaseHTTPServer', + 'Bastion', + 'CD', + 'CDIO', + 'CDROM', + 'CGIHTTPServer', + 'CL', + 'CL_old', + 'Canvas', + 'Carbon', + 'ColorPicker', + 'ConfigParser', + 'Cookie', + 'DEVICE', + 'DLFCN', + 'Dialog', + 'DocXMLRPCServer', + 'ERRNO', + 'EasyDialogs', + 'FILE', + 'FL', + 'FileDialog', + 'FixTk', + 'FrameWork', + 'GET', + 'GL', + 'GLWS', + 'HTMLParser', + 'IN', + 'IOCTL', + 'MacOS', + 'MimeWriter', + 'MiniAEFrame', + 'Nav', + 'OSATerminology', + 'PixMapWrapper', + 'Queue', + 'SOCKET', + 'STROPTS', + 'SUNAUDIODEV', + 'SV', + 'ScrolledText', + 'SimpleDialog', + 'SimpleHTTPServer', + 'SimpleXMLRPCServer', + 'SocketServer', + 'StringIO', + 'TYPES', + 'Tix', + 'Tkconstants', + 'Tkdnd', + 'Tkinter', + 'UserDict', + 'UserList', + 'UserString', + 'WAIT', + '_AE', + '_AH', + '_App', + '_CF', + '_CG', + '_CarbonEvt', + '_Cm', + '_Ctl', + '_Dlg', + '_Drag', + '_Evt', + '_File', + '_Fm', + '_Folder', + '_Help', + '_IBCarbon', + '_Icn', + '_LWPCookieJar', + '_Launch', + '_List', + '_Menu', + '_Mlte', + '_MozillaCookieJar', + '_OSA', + '_Qd', + '_Qdoffs', + '_Qt', + '_Res', + '_Scrap', + '_Snd', + '_TE', + '_Win', + '__builtin__', + '__future__', + '__hello__', + '__phello__', + '_abcoll', + '_ast', + '_bisect', + '_bsddb', + '_bytesio', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_elementtree', + '_emx_link', + '_fileio', + '_functools', + '_hashlib', + '_heapq', + '_hotshot', + '_json', + '_locale', + '_lsprof', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_pybsddb', + '_random', + '_scproxy', + '_sha', + '_sha256', + '_sha512', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_strptime', + '_struct', + '_subprocess', + '_symtable', + '_testcapi', + '_threading_local', + '_tkinter', + '_warnings', + '_weakref', + '_winreg', + 'abc', + 'aepack', + 'aetools', + 'aetypes', + 'aifc', + 'al', + 'anydbm', + 'applesingle', + 'appletrawmain', + 'appletrunner', + 'argvemulator', + 'array', + 'ast', + 'asynchat', + 'asyncore', + 'atexit', + 'audiodev', + 'audioop', + 'autoGIL', + 'base64', + 'bdb', + 'bgenlocations', + 'binascii', + 'binhex', + 'bisect', + 'bsddb', + 'bsddb185', + 'buildtools', + 'bundlebuilder', + 'bz2', + 'cPickle', + 'cProfile', + 'cStringIO', + 'calendar', + 'cd', + 'cddb', + 'cdplayer', + 'cfmfile', + 'cgi', + 'cgitb', + 'chunk', + 'cl', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'commands', + 'compileall', + 'compiler', + 'contextlib', + 'cookielib', + 'copy', + 'copy_reg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'datetime', + 'dbhash', + 'dbm', + 'decimal', + 'difflib', + 'dircache', + 'dis', + 'distutils', + 'dl', + 'doctest', + 'dumbdbm', + 'dummy_thread', + 'dummy_threading', + 'email', + 'encodings', + 'errno', + 'exceptions', + 'fcntl', + 'filecmp', + 'fileinput', + 'findertools', + 'fl', + 'flp', + 'fm', + 'fnmatch', + 'formatter', + 'fpectl', + 'fpetest', + 'fpformat', + 'fractions', + 'ftplib', + 'functools', + 'future_builtins', + 'gc', + 'gdbm', + 'genericpath', + 'gensuitemodule', + 'gestalt', + 'getopt', + 'getpass', + 'gettext', + 'gl', + 'glob', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'hotshot', + 'htmlentitydefs', + 'htmllib', + 'httplib', + 'ic', + 'icglue', + 'icopen', + 'idlelib', + 'ihooks', + 'imageop', + 'imaplib', + 'imgfile', + 'imghdr', + 'imp', + 'imputil', + 'inspect', + 'io', + 'itertools', + 'jpeg', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'linuxaudiodev', + 'locale', + 'logging', + 'macerrors', + 'macostools', + 'macpath', + 'macresource', + 'macurl2path', + 'mailbox', + 'mailcap', + 'markupbase', + 'marshal', + 'math', + 'md5', + 'mhlib', + 'mimetools', + 'mimetypes', + 'mimify', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multifile', + 'multiprocessing', + 'mutex', + 'netrc', + 'new', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'os2', + 'os2emxpath', + 'ossaudiodev', + 'panel', + 'panelparser', + 'parser', + 'pcre', + 'pdb', + 'pickle', + 'pickletools', + 'pimp', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'popen2', + 'poplib', + 'posix', + 'posixfile', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pure', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_topics', + 'pyexpat', + 'quopri', + 'random', + 're', + 'readcd', + 'readline', + 'repr', + 'resource', + 'rexec', + 'rfc822', + 'rgbimg', + 'riscosenviron', + 'riscospath', + 'rlcompleter', + 'robotparser', + 'rourl2path', + 'runpy', + 'sched', + 'select', + 'sets', + 'sgi', + 'sgmllib', + 'sha', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'spwd', + 'sqlite3', + 'sre', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statvfs', + 'string', + 'stringold', + 'stringprep', + 'strop', + 'struct', + 'subprocess', + 'sunau', + 'sunaudio', + 'sunaudiodev', + 'sv', + 'symbol', + 'symtable', + 'sys', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'terminalcommand', + 'termios', + 'textwrap', + 'this', + 'thread', + 'threading', + 'time', + 'timeit', + 'timing', + 'tkColorChooser', + 'tkCommonDialog', + 'tkFileDialog', + 'tkFont', + 'tkMessageBox', + 'tkSimpleDialog', + 'toaiff', + 'token', + 'tokenize', + 'torgb', + 'trace', + 'traceback', + 'tty', + 'turtle', + 'types', + 'unicodedata', + 'unittest', + 'urllib', + 'urllib2', + 'urlparse', + 'user', + 'uu', + 'uuid', + 'videoreader', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'whichdb', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmllib', + 'xmlrpclib', + 'xx', + 'xxsubtype', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py27.py b/mitogen/imports/stdlibs/py27.py new file mode 100644 index 000000000..6664b31e2 --- /dev/null +++ b/mitogen/imports/stdlibs/py27.py @@ -0,0 +1,462 @@ +module_names = frozenset([ + 'AL', + 'Audio_mac', + 'BaseHTTPServer', + 'Bastion', + 'CD', + 'CDIO', + 'CDROM', + 'CGIHTTPServer', + 'CL', + 'CL_old', + 'Canvas', + 'Carbon', + 'ColorPicker', + 'ConfigParser', + 'Cookie', + 'DEVICE', + 'DLFCN', + 'Dialog', + 'DocXMLRPCServer', + 'ERRNO', + 'EasyDialogs', + 'FILE', + 'FL', + 'FileDialog', + 'FixTk', + 'FrameWork', + 'GET', + 'GL', + 'GLWS', + 'HTMLParser', + 'IN', + 'IOCTL', + 'MacOS', + 'MimeWriter', + 'MiniAEFrame', + 'Nav', + 'OSATerminology', + 'PixMapWrapper', + 'Queue', + 'SOCKET', + 'STROPTS', + 'SUNAUDIODEV', + 'SV', + 'ScrolledText', + 'SimpleDialog', + 'SimpleHTTPServer', + 'SimpleXMLRPCServer', + 'SocketServer', + 'StringIO', + 'TYPES', + 'Tix', + 'Tkconstants', + 'Tkdnd', + 'Tkinter', + 'UserDict', + 'UserList', + 'UserString', + 'WAIT', + '_AE', + '_AH', + '_App', + '_CF', + '_CG', + '_CarbonEvt', + '_Cm', + '_Ctl', + '_Dlg', + '_Drag', + '_Evt', + '_File', + '_Fm', + '_Folder', + '_Help', + '_IBCarbon', + '_Icn', + '_LWPCookieJar', + '_Launch', + '_List', + '_Menu', + '_Mlte', + '_MozillaCookieJar', + '_OSA', + '_Qd', + '_Qdoffs', + '_Qt', + '_Res', + '_Scrap', + '_Snd', + '_TE', + '_Win', + '__builtin__', + '__future__', + '__hello__', + '__phello__', + '_abcoll', + '_ast', + '_bisect', + '_bsddb', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_elementtree', + '_emx_link', + '_functools', + '_hashlib', + '_heapq', + '_hotshot', + '_io', + '_json', + '_locale', + '_lsprof', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_osx_support', + '_pybsddb', + '_pyio', + '_random', + '_scproxy', + '_sha', + '_sha256', + '_sha512', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_strptime', + '_struct', + '_subprocess', + '_symtable', + '_testcapi', + '_threading_local', + '_tkinter', + '_warnings', + '_weakref', + '_weakrefset', + '_winreg', + 'abc', + 'aepack', + 'aetools', + 'aetypes', + 'aifc', + 'al', + 'antigravity', + 'anydbm', + 'applesingle', + 'appletrawmain', + 'appletrunner', + 'argparse', + 'argvemulator', + 'array', + 'ast', + 'asynchat', + 'asyncore', + 'atexit', + 'audiodev', + 'audioop', + 'autoGIL', + 'base64', + 'bdb', + 'bgenlocations', + 'binascii', + 'binhex', + 'bisect', + 'bsddb', + 'bsddb185', + 'buildtools', + 'bundlebuilder', + 'bz2', + 'cPickle', + 'cProfile', + 'cStringIO', + 'calendar', + 'cd', + 'cddb', + 'cdplayer', + 'cfmfile', + 'cgi', + 'cgitb', + 'chunk', + 'cl', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'commands', + 'compileall', + 'compiler', + 'contextlib', + 'cookielib', + 'copy', + 'copy_reg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'datetime', + 'dbhash', + 'dbm', + 'decimal', + 'difflib', + 'dircache', + 'dis', + 'distutils', + 'dl', + 'doctest', + 'dumbdbm', + 'dummy_thread', + 'dummy_threading', + 'email', + 'encodings', + 'ensurepip', + 'errno', + 'exceptions', + 'fcntl', + 'filecmp', + 'fileinput', + 'findertools', + 'fl', + 'flp', + 'fm', + 'fnmatch', + 'formatter', + 'fpectl', + 'fpetest', + 'fpformat', + 'fractions', + 'ftplib', + 'functools', + 'future_builtins', + 'gc', + 'gdbm', + 'genericpath', + 'gensuitemodule', + 'gestalt', + 'getopt', + 'getpass', + 'gettext', + 'gl', + 'glob', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'hotshot', + 'htmlentitydefs', + 'htmllib', + 'httplib', + 'ic', + 'icglue', + 'icopen', + 'idlelib', + 'ihooks', + 'imageop', + 'imaplib', + 'imgfile', + 'imghdr', + 'imp', + 'importlib', + 'imputil', + 'inspect', + 'io', + 'itertools', + 'jpeg', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'linuxaudiodev', + 'locale', + 'logging', + 'macerrors', + 'macostools', + 'macpath', + 'macresource', + 'macurl2path', + 'mailbox', + 'mailcap', + 'markupbase', + 'marshal', + 'math', + 'md5', + 'mhlib', + 'mimetools', + 'mimetypes', + 'mimify', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multifile', + 'multiprocessing', + 'mutex', + 'netrc', + 'new', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'os2', + 'os2emxpath', + 'ossaudiodev', + 'panel', + 'panelparser', + 'parser', + 'pcre', + 'pdb', + 'pickle', + 'pickletools', + 'pimp', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'popen2', + 'poplib', + 'posix', + 'posixfile', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pure', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_data', + 'pyexpat', + 'quopri', + 'random', + 're', + 'readcd', + 'readline', + 'repr', + 'resource', + 'rexec', + 'rfc822', + 'rgbimg', + 'riscosenviron', + 'riscospath', + 'rlcompleter', + 'robotparser', + 'rourl2path', + 'runpy', + 'sched', + 'select', + 'sets', + 'sgi', + 'sgmllib', + 'sha', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'spwd', + 'sqlite3', + 'sre', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statvfs', + 'string', + 'stringold', + 'stringprep', + 'strop', + 'struct', + 'subprocess', + 'sunau', + 'sunaudio', + 'sunaudiodev', + 'sv', + 'symbol', + 'symtable', + 'sys', + 'sysconfig', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'terminalcommand', + 'termios', + 'textwrap', + 'this', + 'thread', + 'threading', + 'time', + 'timeit', + 'timing', + 'tkColorChooser', + 'tkCommonDialog', + 'tkFileDialog', + 'tkFont', + 'tkMessageBox', + 'tkSimpleDialog', + 'toaiff', + 'token', + 'tokenize', + 'torgb', + 'trace', + 'traceback', + 'ttk', + 'tty', + 'turtle', + 'types', + 'unicodedata', + 'unittest', + 'urllib', + 'urllib2', + 'urlparse', + 'user', + 'uu', + 'uuid', + 'videoreader', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'whichdb', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmllib', + 'xmlrpclib', + 'xx', + 'xxsubtype', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py36.py b/mitogen/imports/stdlibs/py36.py new file mode 100644 index 000000000..d1f3ac603 --- /dev/null +++ b/mitogen/imports/stdlibs/py36.py @@ -0,0 +1,313 @@ +module_names = frozenset([ + '__future__', + '__hello__', + '__phello__', + '_ast', + '_asyncio', + '_bisect', + '_blake2', + '_bootlocale', + '_bz2', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_collections_abc', + '_compat_pickle', + '_compression', + '_crypt', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_datetime', + '_dbm', + '_decimal', + '_distutils_findvs', + '_dummy_thread', + '_elementtree', + '_frozen_importlib', + '_frozen_importlib_external', + '_functools', + '_gdbm', + '_hashlib', + '_heapq', + '_imp', + '_io', + '_json', + '_locale', + '_lsprof', + '_lzma', + '_markupbase', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_opcode', + '_operator', + '_osx_support', + '_overlapped', + '_pickle', + '_posixsubprocess', + '_pydecimal', + '_pyio', + '_random', + '_scproxy', + '_sha1', + '_sha256', + '_sha3', + '_sha512', + '_signal', + '_sitebuiltins', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_stat', + '_string', + '_strptime', + '_struct', + '_symtable', + '_testbuffer', + '_testcapi', + '_testconsole', + '_testimportmultiple', + '_testmultiphase', + '_thread', + '_threading_local', + '_tkinter', + '_tracemalloc', + '_warnings', + '_weakref', + '_weakrefset', + '_winapi', + 'abc', + 'aifc', + 'antigravity', + 'argparse', + 'array', + 'ast', + 'asynchat', + 'asyncio', + 'asyncore', + 'atexit', + 'audioop', + 'base64', + 'bdb', + 'binascii', + 'binhex', + 'bisect', + 'builtins', + 'bz2', + 'cProfile', + 'calendar', + 'cgi', + 'cgitb', + 'chunk', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'compileall', + 'concurrent', + 'configparser', + 'contextlib', + 'copy', + 'copyreg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'datetime', + 'dbm', + 'decimal', + 'difflib', + 'dis', + 'distutils', + 'doctest', + 'dummy_threading', + 'email', + 'encodings', + 'ensurepip', + 'enum', + 'errno', + 'faulthandler', + 'fcntl', + 'filecmp', + 'fileinput', + 'fnmatch', + 'formatter', + 'fpectl', + 'fpetest', + 'fractions', + 'ftplib', + 'functools', + 'gc', + 'genericpath', + 'getopt', + 'getpass', + 'gettext', + 'glob', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'html', + 'http', + 'idlelib', + 'imaplib', + 'imghdr', + 'imp', + 'importlib', + 'inspect', + 'io', + 'ipaddress', + 'itertools', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'locale', + 'logging', + 'lzma', + 'macpath', + 'macurl2path', + 'mailbox', + 'mailcap', + 'marshal', + 'math', + 'mimetypes', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multiprocessing', + 'netrc', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'ossaudiodev', + 'parser', + 'pathlib', + 'pdb', + 'pickle', + 'pickletools', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'poplib', + 'posix', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_data', + 'pyexpat', + 'queue', + 'quopri', + 'random', + 're', + 'readline', + 'reprlib', + 'resource', + 'rlcompleter', + 'runpy', + 'sched', + 'secrets', + 'select', + 'selectors', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'socketserver', + 'spwd', + 'sqlite3', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statistics', + 'string', + 'stringprep', + 'struct', + 'subprocess', + 'sunau', + 'symbol', + 'symtable', + 'sys', + 'sysconfig', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'termios', + 'textwrap', + 'this', + 'threading', + 'time', + 'timeit', + 'tkinter', + 'token', + 'tokenize', + 'trace', + 'traceback', + 'tracemalloc', + 'tty', + 'turtle', + 'turtledemo', + 'types', + 'typing', + 'unicodedata', + 'unittest', + 'urllib', + 'uu', + 'uuid', + 'venv', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'winreg', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmlrpc', + 'xx', + 'xxlimited', + 'xxsubtype', + 'zipapp', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py37.py b/mitogen/imports/stdlibs/py37.py new file mode 100644 index 000000000..a6c8f770e --- /dev/null +++ b/mitogen/imports/stdlibs/py37.py @@ -0,0 +1,317 @@ +module_names = frozenset([ + '__future__', + '__hello__', + '__phello__', + '_abc', + '_ast', + '_asyncio', + '_bisect', + '_blake2', + '_bootlocale', + '_bz2', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_collections_abc', + '_compat_pickle', + '_compression', + '_contextvars', + '_crypt', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_datetime', + '_dbm', + '_decimal', + '_dummy_thread', + '_elementtree', + '_frozen_importlib', + '_frozen_importlib_external', + '_functools', + '_gdbm', + '_hashlib', + '_heapq', + '_imp', + '_io', + '_json', + '_locale', + '_lsprof', + '_lzma', + '_markupbase', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_opcode', + '_operator', + '_osx_support', + '_overlapped', + '_pickle', + '_posixsubprocess', + '_py_abc', + '_pydecimal', + '_pyio', + '_queue', + '_random', + '_scproxy', + '_sha1', + '_sha256', + '_sha3', + '_sha512', + '_signal', + '_sitebuiltins', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_stat', + '_string', + '_strptime', + '_struct', + '_symtable', + '_testbuffer', + '_testcapi', + '_testconsole', + '_testimportmultiple', + '_testmultiphase', + '_thread', + '_threading_local', + '_tkinter', + '_tracemalloc', + '_uuid', + '_warnings', + '_weakref', + '_weakrefset', + '_winapi', + '_xxtestfuzz', + 'abc', + 'aifc', + 'antigravity', + 'argparse', + 'array', + 'ast', + 'asynchat', + 'asyncio', + 'asyncore', + 'atexit', + 'audioop', + 'base64', + 'bdb', + 'binascii', + 'binhex', + 'bisect', + 'builtins', + 'bz2', + 'cProfile', + 'calendar', + 'cgi', + 'cgitb', + 'chunk', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'compileall', + 'concurrent', + 'configparser', + 'contextlib', + 'contextvars', + 'copy', + 'copyreg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'dataclasses', + 'datetime', + 'dbm', + 'decimal', + 'difflib', + 'dis', + 'distutils', + 'doctest', + 'dummy_threading', + 'email', + 'encodings', + 'ensurepip', + 'enum', + 'errno', + 'faulthandler', + 'fcntl', + 'filecmp', + 'fileinput', + 'fnmatch', + 'formatter', + 'fractions', + 'ftplib', + 'functools', + 'gc', + 'genericpath', + 'getopt', + 'getpass', + 'gettext', + 'glob', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'html', + 'http', + 'idlelib', + 'imaplib', + 'imghdr', + 'imp', + 'importlib', + 'inspect', + 'io', + 'ipaddress', + 'itertools', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'locale', + 'logging', + 'lzma', + 'macpath', + 'mailbox', + 'mailcap', + 'marshal', + 'math', + 'mimetypes', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multiprocessing', + 'netrc', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'ossaudiodev', + 'parser', + 'pathlib', + 'pdb', + 'pickle', + 'pickletools', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'poplib', + 'posix', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_data', + 'pyexpat', + 'queue', + 'quopri', + 'random', + 're', + 'readline', + 'reprlib', + 'resource', + 'rlcompleter', + 'runpy', + 'sched', + 'secrets', + 'select', + 'selectors', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'socketserver', + 'spwd', + 'sqlite3', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statistics', + 'string', + 'stringprep', + 'struct', + 'subprocess', + 'sunau', + 'symbol', + 'symtable', + 'sys', + 'sysconfig', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'termios', + 'textwrap', + 'this', + 'threading', + 'time', + 'timeit', + 'tkinter', + 'token', + 'tokenize', + 'trace', + 'traceback', + 'tracemalloc', + 'tty', + 'turtle', + 'turtledemo', + 'types', + 'typing', + 'unicodedata', + 'unittest', + 'urllib', + 'uu', + 'uuid', + 'venv', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'winreg', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmlrpc', + 'xx', + 'xxlimited', + 'xxsubtype', + 'zipapp', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py38.py b/mitogen/imports/stdlibs/py38.py new file mode 100644 index 000000000..ecc8a28c0 --- /dev/null +++ b/mitogen/imports/stdlibs/py38.py @@ -0,0 +1,320 @@ +module_names = frozenset([ + '__future__', + '__hello__', + '__phello__', + '_abc', + '_ast', + '_asyncio', + '_bisect', + '_blake2', + '_bootlocale', + '_bz2', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_collections_abc', + '_compat_pickle', + '_compression', + '_contextvars', + '_crypt', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_datetime', + '_dbm', + '_decimal', + '_dummy_thread', + '_elementtree', + '_frozen_importlib', + '_frozen_importlib_external', + '_functools', + '_gdbm', + '_hashlib', + '_heapq', + '_imp', + '_io', + '_json', + '_locale', + '_lsprof', + '_lzma', + '_markupbase', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_opcode', + '_operator', + '_osx_support', + '_overlapped', + '_pickle', + '_posixshmem', + '_posixsubprocess', + '_py_abc', + '_pydecimal', + '_pyio', + '_queue', + '_random', + '_scproxy', + '_sha1', + '_sha256', + '_sha3', + '_sha512', + '_signal', + '_sitebuiltins', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_stat', + '_statistics', + '_string', + '_strptime', + '_struct', + '_symtable', + '_testbuffer', + '_testcapi', + '_testconsole', + '_testimportmultiple', + '_testinternalcapi', + '_testmultiphase', + '_thread', + '_threading_local', + '_tkinter', + '_tracemalloc', + '_uuid', + '_warnings', + '_weakref', + '_weakrefset', + '_winapi', + '_xxsubinterpreters', + '_xxtestfuzz', + 'abc', + 'aifc', + 'antigravity', + 'argparse', + 'array', + 'ast', + 'asynchat', + 'asyncio', + 'asyncore', + 'atexit', + 'audioop', + 'base64', + 'bdb', + 'binascii', + 'binhex', + 'bisect', + 'builtins', + 'bz2', + 'cProfile', + 'calendar', + 'cgi', + 'cgitb', + 'chunk', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'compileall', + 'concurrent', + 'configparser', + 'contextlib', + 'contextvars', + 'copy', + 'copyreg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'dataclasses', + 'datetime', + 'dbm', + 'decimal', + 'difflib', + 'dis', + 'distutils', + 'doctest', + 'dummy_threading', + 'email', + 'encodings', + 'ensurepip', + 'enum', + 'errno', + 'faulthandler', + 'fcntl', + 'filecmp', + 'fileinput', + 'fnmatch', + 'formatter', + 'fractions', + 'ftplib', + 'functools', + 'gc', + 'genericpath', + 'getopt', + 'getpass', + 'gettext', + 'glob', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'html', + 'http', + 'idlelib', + 'imaplib', + 'imghdr', + 'imp', + 'importlib', + 'inspect', + 'io', + 'ipaddress', + 'itertools', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'locale', + 'logging', + 'lzma', + 'mailbox', + 'mailcap', + 'marshal', + 'math', + 'mimetypes', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multiprocessing', + 'netrc', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'ossaudiodev', + 'parser', + 'pathlib', + 'pdb', + 'pickle', + 'pickletools', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'poplib', + 'posix', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_data', + 'pyexpat', + 'queue', + 'quopri', + 'random', + 're', + 'readline', + 'reprlib', + 'resource', + 'rlcompleter', + 'runpy', + 'sched', + 'secrets', + 'select', + 'selectors', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'socketserver', + 'spwd', + 'sqlite3', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statistics', + 'string', + 'stringprep', + 'struct', + 'subprocess', + 'sunau', + 'symbol', + 'symtable', + 'sys', + 'sysconfig', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'termios', + 'textwrap', + 'this', + 'threading', + 'time', + 'timeit', + 'tkinter', + 'token', + 'tokenize', + 'trace', + 'traceback', + 'tracemalloc', + 'tty', + 'turtle', + 'turtledemo', + 'types', + 'typing', + 'unicodedata', + 'unittest', + 'urllib', + 'uu', + 'uuid', + 'venv', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'winreg', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmlrpc', + 'xx', + 'xxlimited', + 'xxsubtype', + 'zipapp', + 'zipfile', + 'zipimport', + 'zlib', +]) diff --git a/mitogen/imports/stdlibs/py39.py b/mitogen/imports/stdlibs/py39.py new file mode 100644 index 000000000..4613ab5dc --- /dev/null +++ b/mitogen/imports/stdlibs/py39.py @@ -0,0 +1,324 @@ +module_names = frozenset([ + '__future__', + '__hello__', + '__phello__', + '_abc', + '_aix_support', + '_ast', + '_asyncio', + '_bisect', + '_blake2', + '_bootlocale', + '_bootsubprocess', + '_bz2', + '_codecs', + '_codecs_cn', + '_codecs_hk', + '_codecs_iso2022', + '_codecs_jp', + '_codecs_kr', + '_codecs_tw', + '_collections', + '_collections_abc', + '_compat_pickle', + '_compression', + '_contextvars', + '_crypt', + '_csv', + '_ctypes', + '_ctypes_test', + '_curses', + '_curses_panel', + '_datetime', + '_dbm', + '_decimal', + '_elementtree', + '_frozen_importlib', + '_frozen_importlib_external', + '_functools', + '_gdbm', + '_hashlib', + '_heapq', + '_imp', + '_io', + '_json', + '_locale', + '_lsprof', + '_lzma', + '_markupbase', + '_md5', + '_msi', + '_multibytecodec', + '_multiprocessing', + '_opcode', + '_operator', + '_osx_support', + '_overlapped', + '_peg_parser', + '_pickle', + '_posixshmem', + '_posixsubprocess', + '_py_abc', + '_pydecimal', + '_pyio', + '_queue', + '_random', + '_scproxy', + '_sha1', + '_sha256', + '_sha3', + '_sha512', + '_signal', + '_sitebuiltins', + '_socket', + '_sqlite3', + '_sre', + '_ssl', + '_stat', + '_statistics', + '_string', + '_strptime', + '_struct', + '_symtable', + '_testbuffer', + '_testcapi', + '_testconsole', + '_testimportmultiple', + '_testinternalcapi', + '_testmultiphase', + '_thread', + '_threading_local', + '_tkinter', + '_tracemalloc', + '_uuid', + '_warnings', + '_weakref', + '_weakrefset', + '_winapi', + '_xxsubinterpreters', + '_xxtestfuzz', + '_zoneinfo', + 'abc', + 'aifc', + 'antigravity', + 'argparse', + 'array', + 'ast', + 'asynchat', + 'asyncio', + 'asyncore', + 'atexit', + 'audioop', + 'base64', + 'bdb', + 'binascii', + 'binhex', + 'bisect', + 'builtins', + 'bz2', + 'cProfile', + 'calendar', + 'cgi', + 'cgitb', + 'chunk', + 'cmath', + 'cmd', + 'code', + 'codecs', + 'codeop', + 'collections', + 'colorsys', + 'compileall', + 'concurrent', + 'configparser', + 'contextlib', + 'contextvars', + 'copy', + 'copyreg', + 'crypt', + 'csv', + 'ctypes', + 'curses', + 'dataclasses', + 'datetime', + 'dbm', + 'decimal', + 'difflib', + 'dis', + 'distutils', + 'doctest', + 'email', + 'encodings', + 'ensurepip', + 'enum', + 'errno', + 'faulthandler', + 'fcntl', + 'filecmp', + 'fileinput', + 'fnmatch', + 'formatter', + 'fractions', + 'ftplib', + 'functools', + 'gc', + 'genericpath', + 'getopt', + 'getpass', + 'gettext', + 'glob', + 'graphlib', + 'grp', + 'gzip', + 'hashlib', + 'heapq', + 'hmac', + 'html', + 'http', + 'idlelib', + 'imaplib', + 'imghdr', + 'imp', + 'importlib', + 'inspect', + 'io', + 'ipaddress', + 'itertools', + 'json', + 'keyword', + 'lib2to3', + 'linecache', + 'locale', + 'logging', + 'lzma', + 'mailbox', + 'mailcap', + 'marshal', + 'math', + 'mimetypes', + 'mmap', + 'modulefinder', + 'msilib', + 'msvcrt', + 'multiprocessing', + 'netrc', + 'nis', + 'nntplib', + 'nt', + 'ntpath', + 'nturl2path', + 'numbers', + 'opcode', + 'operator', + 'optparse', + 'os', + 'ossaudiodev', + 'parser', + 'pathlib', + 'pdb', + 'pickle', + 'pickletools', + 'pipes', + 'pkgutil', + 'platform', + 'plistlib', + 'poplib', + 'posix', + 'posixpath', + 'pprint', + 'profile', + 'pstats', + 'pty', + 'pwd', + 'py_compile', + 'pyclbr', + 'pydoc', + 'pydoc_data', + 'pyexpat', + 'queue', + 'quopri', + 'random', + 're', + 'readline', + 'reprlib', + 'resource', + 'rlcompleter', + 'runpy', + 'sched', + 'secrets', + 'select', + 'selectors', + 'shelve', + 'shlex', + 'shutil', + 'signal', + 'site', + 'smtpd', + 'smtplib', + 'sndhdr', + 'socket', + 'socketserver', + 'spwd', + 'sqlite3', + 'sre_compile', + 'sre_constants', + 'sre_parse', + 'ssl', + 'stat', + 'statistics', + 'string', + 'stringprep', + 'struct', + 'subprocess', + 'sunau', + 'symbol', + 'symtable', + 'sys', + 'sysconfig', + 'syslog', + 'tabnanny', + 'tarfile', + 'telnetlib', + 'tempfile', + 'termios', + 'textwrap', + 'this', + 'threading', + 'time', + 'timeit', + 'tkinter', + 'token', + 'tokenize', + 'trace', + 'traceback', + 'tracemalloc', + 'tty', + 'turtle', + 'turtledemo', + 'types', + 'typing', + 'unicodedata', + 'unittest', + 'urllib', + 'uu', + 'uuid', + 'venv', + 'warnings', + 'wave', + 'weakref', + 'webbrowser', + 'winreg', + 'winsound', + 'wsgiref', + 'xdrlib', + 'xml', + 'xmlrpc', + 'xx', + 'xxlimited', + 'xxsubtype', + 'zipapp', + 'zipfile', + 'zipimport', + 'zlib', + 'zoneinfo', +]) diff --git a/mitogen/master.py b/mitogen/master.py index cf5c860cf..e7c4d6326 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -1402,7 +1402,10 @@ def __init__(self, broker=None, max_message_size=None): def upgrade(self): self.id_allocator = IdAllocator(self) - self.responder = ModuleResponder(self, mitogen.core.ImportPolicy()) + policy = mitogen.core.ImportPolicy( + unsuitables=mitogen.imports.unsuitable_module_names(), + ) + self.responder = ModuleResponder(self, policy) self.resource_responder = ResourceResponder(self) self.log_forwarder = LogForwarder(self) self.route_monitor = mitogen.parent.RouteMonitor(router=self) diff --git a/mitogen/parent.py b/mitogen/parent.py index 3f678053e..13b171e29 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1506,6 +1506,7 @@ def get_econtext_config(self): 'debug': self.options.debug, 'import_blocks': list(import_policy.blocks), 'import_overrides': list(import_policy.overrides), + 'import_unsuitables': list(import_policy.unsuitables), 'profiling': self.options.profiling, 'unidirectional': self.options.unidirectional, 'log_level': get_log_level(), diff --git a/stdlibs_gen.py b/stdlibs_gen.py new file mode 100644 index 000000000..e0b545eb8 --- /dev/null +++ b/stdlibs_gen.py @@ -0,0 +1,31 @@ +import pathlib + +import stdlibs + +VERSIONS_2x = [ + (2, 4), + (2, 5), + (2, 6), + (2, 7), +] + +VERSIONS_3x = [ + (3, 6), + (3, 7), + (3, 8), + (3, 9), +] + +VERSIONS = VERSIONS_2x + VERSIONS_3x + +STDLIBS = { + version: sorted(stdlibs.stdlib_module_names('%d.%d' % version)) + for version in VERSIONS +} + +pathlib.Path('mitogen/imports/stdlibs').mkdir(parents=True, exist_ok=True) +for version, names in STDLIBS.items(): + with open('mitogen/imports/stdlibs/py%d%d.py' % version, 'w', encoding='utf-8') as f: + f.write('module_names = frozenset([\n') + f.write(''.join(" '%s',\n" % name for name in names)) + f.write('])\n') diff --git a/tests/importer_test.py b/tests/importer_test.py index cff8cda04..fa9f60070 100644 --- a/tests/importer_test.py +++ b/tests/importer_test.py @@ -22,7 +22,7 @@ class ImporterMixin(testlib.RouterMixin): def setUp(self): super(ImporterMixin, self).setUp() self.context = mock.Mock() - self.policy = mock.Mock() + self.policy = mitogen.core.ImportPolicy() self.importer = mitogen.core.Importer(self.router, self.context, '', self.policy) # TODO: this is a horrendous hack. Without it, we can't deliver a @@ -278,8 +278,6 @@ def test_default(self): self.assertFalse(policy.denied('pkg.mod')) self.assertFalse(policy.denied('otherpkg')) self.assertFalse(policy.denied('otherpkg.mod')) - self.assertTrue(policy.denied('__builtin__')) - self.assertTrue(policy.denied('builtins')) def test_overrides(self): policy = mitogen.core.ImportPolicy(overrides=['pkg']) @@ -287,8 +285,6 @@ def test_overrides(self): self.assertFalse(policy.denied('pkg.mod')) self.assertTrue(policy.denied('otherpkg')) self.assertTrue(policy.denied('otherpkg.mod')) - self.assertTrue(policy.denied('__builtin__')) - self.assertTrue(policy.denied('builtins')) def test_blocks(self): policy = mitogen.core.ImportPolicy(blocks=['pkg']) @@ -296,8 +292,6 @@ def test_blocks(self): self.assertTrue(policy.denied('pkg.mod')) self.assertFalse(policy.denied('otherpkg')) self.assertFalse(policy.denied('otherpkg.mod')) - self.assertTrue(policy.denied('__builtin__')) - self.assertTrue(policy.denied('builtins')) def test_overrides_and_blocks(self): policy = mitogen.core.ImportPolicy(overrides=['pkg'], blocks=['pkg']) @@ -305,8 +299,16 @@ def test_overrides_and_blocks(self): self.assertTrue(policy.denied('pkg.mod')) self.assertTrue(policy.denied('otherpkg')) self.assertTrue(policy.denied('otherpkg.mod')) + + def test_unsuitables(self): + policy = mitogen.core.ImportPolicy( + unsuitables=('__builtin__', 'builtins', 'org'), + ) self.assertTrue(policy.denied('__builtin__')) self.assertTrue(policy.denied('builtins')) + self.assertTrue(policy.denied('org.python.core')) + self.assertFalse(policy.denied('__main__')) + self.assertFalse(policy.denied('organisation')) class Python24LineCacheTest(testlib.TestCase): diff --git a/tests/responder_test.py b/tests/responder_test.py index d8b714966..46816b2c6 100644 --- a/tests/responder_test.py +++ b/tests/responder_test.py @@ -21,7 +21,7 @@ class NeutralizeMainTest(testlib.RouterMixin, testlib.TestCase): def call(self, *args, **kwargs): router = mock.Mock() - policy = mock.Mock() + policy = mitogen.core.ImportPolicy() return self.klass(router, policy).neutralize_main(*args, **kwargs) def test_missing_exec_guard(self): @@ -121,7 +121,7 @@ def test_obviously_missing(self): ) msg.router = router - policy = mock.Mock() + policy = mitogen.core.ImportPolicy() responder = mitogen.master.ModuleResponder(router, policy) responder._on_get_module(msg) self.assertEqual(1, len(router._async_route.mock_calls)) @@ -160,7 +160,7 @@ def test_ansible_six_messed_up_path(self): ) msg.router = router - policy = mock.Mock() + policy = mitogen.core.ImportPolicy() responder = mitogen.master.ModuleResponder(router, policy) responder._on_get_module(msg) self.assertEqual(1, len(router._async_route.mock_calls))