Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 1 | """Find modules used by a script, using introspection.""" |
Just van Rossum | a920a88 | 2003-07-18 15:31:40 +0000 | [diff] [blame] | 2 | # This module should be kept compatible with Python 2.2, see PEP 291. |
Thomas Heller | 919000e | 2002-11-25 20:21:59 +0000 | [diff] [blame] | 3 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 4 | from __future__ import generators |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 5 | import dis |
| 6 | import imp |
| 7 | import marshal |
| 8 | import os |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 9 | import sys |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 10 | import new |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 11 | import struct |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 12 | |
Just van Rossum | 5d0bd1e | 2002-11-26 09:53:16 +0000 | [diff] [blame] | 13 | if hasattr(sys.__stdout__, "newlines"): |
| 14 | READ_MODE = "U" # universal line endings |
| 15 | else: |
| 16 | # remain compatible with Python < 2.3 |
| 17 | READ_MODE = "r" |
| 18 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 19 | LOAD_CONST = chr(dis.opname.index('LOAD_CONST')) |
| 20 | IMPORT_NAME = chr(dis.opname.index('IMPORT_NAME')) |
| 21 | STORE_NAME = chr(dis.opname.index('STORE_NAME')) |
| 22 | STORE_GLOBAL = chr(dis.opname.index('STORE_GLOBAL')) |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 23 | STORE_OPS = [STORE_NAME, STORE_GLOBAL] |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 24 | HAVE_ARGUMENT = chr(dis.HAVE_ARGUMENT) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 25 | |
Guido van Rossum | f1b5a0e | 1998-05-18 20:21:56 +0000 | [diff] [blame] | 26 | # Modulefinder does a good job at simulating Python's, but it can not |
| 27 | # handle __path__ modifications packages make at runtime. Therefore there |
| 28 | # is a mechanism whereby you can register extra paths in this map for a |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 29 | # package, and it will be honored. |
Guido van Rossum | f1b5a0e | 1998-05-18 20:21:56 +0000 | [diff] [blame] | 30 | |
| 31 | # Note this is a mapping is lists of paths. |
| 32 | packagePathMap = {} |
| 33 | |
| 34 | # A Public interface |
| 35 | def AddPackagePath(packagename, path): |
Guido van Rossum | e7e632a | 1998-09-14 16:02:28 +0000 | [diff] [blame] | 36 | paths = packagePathMap.get(packagename, []) |
| 37 | paths.append(path) |
| 38 | packagePathMap[packagename] = paths |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 39 | |
Thomas Heller | c7aaf95 | 2002-11-14 18:45:11 +0000 | [diff] [blame] | 40 | replacePackageMap = {} |
| 41 | |
| 42 | # This ReplacePackage mechanism allows modulefinder to work around the |
| 43 | # way the _xmlplus package injects itself under the name "xml" into |
| 44 | # sys.modules at runtime by calling ReplacePackage("_xmlplus", "xml") |
| 45 | # before running ModuleFinder. |
| 46 | |
| 47 | def ReplacePackage(oldname, newname): |
| 48 | replacePackageMap[oldname] = newname |
| 49 | |
| 50 | |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 51 | class Module: |
| 52 | |
| 53 | def __init__(self, name, file=None, path=None): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 54 | self.__name__ = name |
| 55 | self.__file__ = file |
| 56 | self.__path__ = path |
| 57 | self.__code__ = None |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 58 | # The set of global names that are assigned to in the module. |
| 59 | # This includes those names imported through starimports of |
| 60 | # Python modules. |
| 61 | self.globalnames = {} |
| 62 | # The set of starimports this module did that could not be |
| 63 | # resolved, ie. a starimport from a non-Python module. |
| 64 | self.starimports = {} |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 65 | |
| 66 | def __repr__(self): |
Neil Schemenauer | 32d23c9 | 2004-02-15 16:43:20 +0000 | [diff] [blame] | 67 | s = "Module(%r" % (self.__name__,) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 68 | if self.__file__ is not None: |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 69 | s = s + ", %r" % (self.__file__,) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 70 | if self.__path__ is not None: |
Walter Dörwald | 70a6b49 | 2004-02-12 17:35:32 +0000 | [diff] [blame] | 71 | s = s + ", %r" % (self.__path__,) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 72 | s = s + ")" |
| 73 | return s |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 74 | |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 75 | class ModuleFinder: |
| 76 | |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 77 | def __init__(self, path=None, debug=0, excludes=[], replace_paths=[]): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 78 | if path is None: |
| 79 | path = sys.path |
| 80 | self.path = path |
| 81 | self.modules = {} |
| 82 | self.badmodules = {} |
| 83 | self.debug = debug |
| 84 | self.indent = 0 |
Guido van Rossum | 78fc363 | 1998-03-20 17:37:24 +0000 | [diff] [blame] | 85 | self.excludes = excludes |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 86 | self.replace_paths = replace_paths |
| 87 | self.processed_paths = [] # Used in debugging only |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 88 | |
| 89 | def msg(self, level, str, *args): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 90 | if level <= self.debug: |
| 91 | for i in range(self.indent): |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 92 | print(" ", end=' ') |
| 93 | print(str, end=' ') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 94 | for arg in args: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 95 | print(repr(arg), end=' ') |
| 96 | print() |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 97 | |
| 98 | def msgin(self, *args): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 99 | level = args[0] |
| 100 | if level <= self.debug: |
| 101 | self.indent = self.indent + 1 |
Guido van Rossum | 68468eb | 2003-02-27 20:14:51 +0000 | [diff] [blame] | 102 | self.msg(*args) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 103 | |
| 104 | def msgout(self, *args): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 105 | level = args[0] |
| 106 | if level <= self.debug: |
| 107 | self.indent = self.indent - 1 |
Guido van Rossum | 68468eb | 2003-02-27 20:14:51 +0000 | [diff] [blame] | 108 | self.msg(*args) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 109 | |
| 110 | def run_script(self, pathname): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 111 | self.msg(2, "run_script", pathname) |
Just van Rossum | 5d0bd1e | 2002-11-26 09:53:16 +0000 | [diff] [blame] | 112 | fp = open(pathname, READ_MODE) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 113 | stuff = ("", "r", imp.PY_SOURCE) |
| 114 | self.load_module('__main__', fp, pathname, stuff) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 115 | |
| 116 | def load_file(self, pathname): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 117 | dir, name = os.path.split(pathname) |
| 118 | name, ext = os.path.splitext(name) |
Just van Rossum | 5d0bd1e | 2002-11-26 09:53:16 +0000 | [diff] [blame] | 119 | fp = open(pathname, READ_MODE) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 120 | stuff = (ext, "r", imp.PY_SOURCE) |
| 121 | self.load_module(name, fp, pathname, stuff) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 122 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 123 | def import_hook(self, name, caller=None, fromlist=None, level=-1): |
| 124 | self.msg(3, "import_hook", name, caller, fromlist, level) |
| 125 | parent = self.determine_parent(caller, level=level) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 126 | q, tail = self.find_head_package(parent, name) |
| 127 | m = self.load_tail(q, tail) |
| 128 | if not fromlist: |
| 129 | return q |
| 130 | if m.__path__: |
| 131 | self.ensure_fromlist(m, fromlist) |
Thomas Heller | 318b7b9 | 2002-11-26 08:06:50 +0000 | [diff] [blame] | 132 | return None |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 133 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 134 | def determine_parent(self, caller, level=-1): |
| 135 | self.msgin(4, "determine_parent", caller, level) |
| 136 | if not caller or level == 0: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 137 | self.msgout(4, "determine_parent -> None") |
| 138 | return None |
| 139 | pname = caller.__name__ |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 140 | if level >= 1: # relative import |
| 141 | if caller.__path__: |
| 142 | level -= 1 |
| 143 | if level == 0: |
| 144 | parent = self.modules[pname] |
| 145 | assert parent is caller |
| 146 | self.msgout(4, "determine_parent ->", parent) |
| 147 | return parent |
| 148 | if pname.count(".") < level: |
| 149 | raise ImportError, "relative importpath too deep" |
| 150 | pname = ".".join(pname.split(".")[:-level]) |
| 151 | parent = self.modules[pname] |
| 152 | self.msgout(4, "determine_parent ->", parent) |
| 153 | return parent |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 154 | if caller.__path__: |
| 155 | parent = self.modules[pname] |
| 156 | assert caller is parent |
| 157 | self.msgout(4, "determine_parent ->", parent) |
| 158 | return parent |
| 159 | if '.' in pname: |
Walter Dörwald | aaab30e | 2002-09-11 20:36:02 +0000 | [diff] [blame] | 160 | i = pname.rfind('.') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 161 | pname = pname[:i] |
| 162 | parent = self.modules[pname] |
| 163 | assert parent.__name__ == pname |
| 164 | self.msgout(4, "determine_parent ->", parent) |
| 165 | return parent |
| 166 | self.msgout(4, "determine_parent -> None") |
| 167 | return None |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 168 | |
| 169 | def find_head_package(self, parent, name): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 170 | self.msgin(4, "find_head_package", parent, name) |
| 171 | if '.' in name: |
Walter Dörwald | aaab30e | 2002-09-11 20:36:02 +0000 | [diff] [blame] | 172 | i = name.find('.') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 173 | head = name[:i] |
| 174 | tail = name[i+1:] |
| 175 | else: |
| 176 | head = name |
| 177 | tail = "" |
| 178 | if parent: |
| 179 | qname = "%s.%s" % (parent.__name__, head) |
| 180 | else: |
| 181 | qname = head |
| 182 | q = self.import_module(head, qname, parent) |
| 183 | if q: |
| 184 | self.msgout(4, "find_head_package ->", (q, tail)) |
| 185 | return q, tail |
| 186 | if parent: |
| 187 | qname = head |
| 188 | parent = None |
| 189 | q = self.import_module(head, qname, parent) |
| 190 | if q: |
| 191 | self.msgout(4, "find_head_package ->", (q, tail)) |
| 192 | return q, tail |
| 193 | self.msgout(4, "raise ImportError: No module named", qname) |
| 194 | raise ImportError, "No module named " + qname |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 195 | |
| 196 | def load_tail(self, q, tail): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 197 | self.msgin(4, "load_tail", q, tail) |
| 198 | m = q |
| 199 | while tail: |
Walter Dörwald | aaab30e | 2002-09-11 20:36:02 +0000 | [diff] [blame] | 200 | i = tail.find('.') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 201 | if i < 0: i = len(tail) |
| 202 | head, tail = tail[:i], tail[i+1:] |
| 203 | mname = "%s.%s" % (m.__name__, head) |
| 204 | m = self.import_module(head, mname, m) |
| 205 | if not m: |
| 206 | self.msgout(4, "raise ImportError: No module named", mname) |
| 207 | raise ImportError, "No module named " + mname |
| 208 | self.msgout(4, "load_tail ->", m) |
| 209 | return m |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 210 | |
| 211 | def ensure_fromlist(self, m, fromlist, recursive=0): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 212 | self.msg(4, "ensure_fromlist", m, fromlist, recursive) |
| 213 | for sub in fromlist: |
| 214 | if sub == "*": |
| 215 | if not recursive: |
| 216 | all = self.find_all_submodules(m) |
| 217 | if all: |
| 218 | self.ensure_fromlist(m, all, 1) |
| 219 | elif not hasattr(m, sub): |
| 220 | subname = "%s.%s" % (m.__name__, sub) |
| 221 | submod = self.import_module(sub, subname, m) |
| 222 | if not submod: |
| 223 | raise ImportError, "No module named " + subname |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 224 | |
| 225 | def find_all_submodules(self, m): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 226 | if not m.__path__: |
| 227 | return |
| 228 | modules = {} |
Thomas Heller | aaf1c8d | 2003-11-14 10:28:42 +0000 | [diff] [blame] | 229 | # 'suffixes' used to be a list hardcoded to [".py", ".pyc", ".pyo"]. |
| 230 | # But we must also collect Python extension modules - although |
| 231 | # we cannot separate normal dlls from Python extensions. |
| 232 | suffixes = [] |
| 233 | for triple in imp.get_suffixes(): |
| 234 | suffixes.append(triple[0]) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 235 | for dir in m.__path__: |
| 236 | try: |
| 237 | names = os.listdir(dir) |
| 238 | except os.error: |
| 239 | self.msg(2, "can't list directory", dir) |
| 240 | continue |
| 241 | for name in names: |
| 242 | mod = None |
| 243 | for suff in suffixes: |
| 244 | n = len(suff) |
| 245 | if name[-n:] == suff: |
| 246 | mod = name[:-n] |
| 247 | break |
| 248 | if mod and mod != "__init__": |
| 249 | modules[mod] = mod |
| 250 | return modules.keys() |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 251 | |
| 252 | def import_module(self, partname, fqname, parent): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 253 | self.msgin(3, "import_module", partname, fqname, parent) |
| 254 | try: |
| 255 | m = self.modules[fqname] |
| 256 | except KeyError: |
| 257 | pass |
| 258 | else: |
| 259 | self.msgout(3, "import_module ->", m) |
| 260 | return m |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 261 | if fqname in self.badmodules: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 262 | self.msgout(3, "import_module -> None") |
| 263 | return None |
Thomas Heller | 2e7c832 | 2004-05-11 15:10:59 +0000 | [diff] [blame] | 264 | if parent and parent.__path__ is None: |
| 265 | self.msgout(3, "import_module -> None") |
| 266 | return None |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 267 | try: |
| 268 | fp, pathname, stuff = self.find_module(partname, |
Just van Rossum | f0dfbaf | 2003-03-05 17:23:48 +0000 | [diff] [blame] | 269 | parent and parent.__path__, parent) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 270 | except ImportError: |
| 271 | self.msgout(3, "import_module ->", None) |
| 272 | return None |
| 273 | try: |
| 274 | m = self.load_module(fqname, fp, pathname, stuff) |
| 275 | finally: |
| 276 | if fp: fp.close() |
| 277 | if parent: |
| 278 | setattr(parent, partname, m) |
| 279 | self.msgout(3, "import_module ->", m) |
| 280 | return m |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 281 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 282 | def load_module(self, fqname, fp, pathname, file_info): |
| 283 | suffix, mode, type = file_info |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 284 | self.msgin(2, "load_module", fqname, fp and "fp", pathname) |
| 285 | if type == imp.PKG_DIRECTORY: |
| 286 | m = self.load_package(fqname, pathname) |
| 287 | self.msgout(2, "load_module ->", m) |
| 288 | return m |
| 289 | if type == imp.PY_SOURCE: |
Guido van Rossum | 78fc363 | 1998-03-20 17:37:24 +0000 | [diff] [blame] | 290 | co = compile(fp.read()+'\n', pathname, 'exec') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 291 | elif type == imp.PY_COMPILED: |
| 292 | if fp.read(4) != imp.get_magic(): |
| 293 | self.msgout(2, "raise ImportError: Bad magic number", pathname) |
Guido van Rossum | ce33eb3 | 2000-05-02 13:49:13 +0000 | [diff] [blame] | 294 | raise ImportError, "Bad magic number in %s" % pathname |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 295 | fp.read(4) |
| 296 | co = marshal.load(fp) |
| 297 | else: |
| 298 | co = None |
| 299 | m = self.add_module(fqname) |
Guido van Rossum | ab045f9 | 1998-03-06 19:55:10 +0000 | [diff] [blame] | 300 | m.__file__ = pathname |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 301 | if co: |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 302 | if self.replace_paths: |
| 303 | co = self.replace_paths_in_code(co) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 304 | m.__code__ = co |
Guido van Rossum | 3c51cf2 | 1998-03-05 05:15:07 +0000 | [diff] [blame] | 305 | self.scan_code(co, m) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 306 | self.msgout(2, "load_module ->", m) |
| 307 | return m |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 308 | |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 309 | def _add_badmodule(self, name, caller): |
| 310 | if name not in self.badmodules: |
| 311 | self.badmodules[name] = {} |
| 312 | self.badmodules[name][caller.__name__] = 1 |
| 313 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 314 | def _safe_import_hook(self, name, caller, fromlist, level=-1): |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 315 | # wrapper for self.import_hook() that won't raise ImportError |
| 316 | if name in self.badmodules: |
| 317 | self._add_badmodule(name, caller) |
| 318 | return |
| 319 | try: |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 320 | self.import_hook(name, caller, level=level) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 321 | except ImportError as msg: |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 322 | self.msg(2, "ImportError:", str(msg)) |
| 323 | self._add_badmodule(name, caller) |
| 324 | else: |
| 325 | if fromlist: |
| 326 | for sub in fromlist: |
| 327 | if sub in self.badmodules: |
| 328 | self._add_badmodule(sub, caller) |
| 329 | continue |
| 330 | try: |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 331 | self.import_hook(name, caller, [sub], level=level) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 332 | except ImportError as msg: |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 333 | self.msg(2, "ImportError:", str(msg)) |
| 334 | fullname = name + "." + sub |
| 335 | self._add_badmodule(fullname, caller) |
| 336 | |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 337 | def scan_opcodes(self, co, |
| 338 | unpack = struct.unpack): |
| 339 | # Scan the code, and yield 'interesting' opcode combinations |
| 340 | # Version for Python 2.4 and older |
| 341 | code = co.co_code |
| 342 | names = co.co_names |
| 343 | consts = co.co_consts |
| 344 | while code: |
| 345 | c = code[0] |
| 346 | if c in STORE_OPS: |
| 347 | oparg, = unpack('<H', code[1:3]) |
| 348 | yield "store", (names[oparg],) |
| 349 | code = code[3:] |
| 350 | continue |
| 351 | if c == LOAD_CONST and code[3] == IMPORT_NAME: |
| 352 | oparg_1, oparg_2 = unpack('<xHxH', code[:6]) |
| 353 | yield "import", (consts[oparg_1], names[oparg_2]) |
| 354 | code = code[6:] |
| 355 | continue |
| 356 | if c >= HAVE_ARGUMENT: |
| 357 | code = code[3:] |
| 358 | else: |
| 359 | code = code[1:] |
| 360 | |
| 361 | def scan_opcodes_25(self, co, |
| 362 | unpack = struct.unpack): |
| 363 | # Scan the code, and yield 'interesting' opcode combinations |
| 364 | # Python 2.5 version (has absolute and relative imports) |
| 365 | code = co.co_code |
| 366 | names = co.co_names |
| 367 | consts = co.co_consts |
| 368 | LOAD_LOAD_AND_IMPORT = LOAD_CONST + LOAD_CONST + IMPORT_NAME |
| 369 | while code: |
| 370 | c = code[0] |
| 371 | if c in STORE_OPS: |
| 372 | oparg, = unpack('<H', code[1:3]) |
| 373 | yield "store", (names[oparg],) |
| 374 | code = code[3:] |
| 375 | continue |
| 376 | if code[:9:3] == LOAD_LOAD_AND_IMPORT: |
| 377 | oparg_1, oparg_2, oparg_3 = unpack('<xHxHxH', code[:9]) |
| 378 | level = consts[oparg_1] |
| 379 | if level == 0: # absolute import |
| 380 | yield "absolute_import", (consts[oparg_2], names[oparg_3]) |
| 381 | else: # relative import |
| 382 | yield "relative_import", (level, consts[oparg_2], names[oparg_3]) |
| 383 | code = code[9:] |
| 384 | continue |
| 385 | if c >= HAVE_ARGUMENT: |
| 386 | code = code[3:] |
| 387 | else: |
| 388 | code = code[1:] |
| 389 | |
Guido van Rossum | 3c51cf2 | 1998-03-05 05:15:07 +0000 | [diff] [blame] | 390 | def scan_code(self, co, m): |
| 391 | code = co.co_code |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 392 | if sys.version_info >= (2, 5): |
| 393 | scanner = self.scan_opcodes_25 |
| 394 | else: |
| 395 | scanner = self.scan_opcodes |
| 396 | for what, args in scanner(co): |
| 397 | if what == "store": |
| 398 | name, = args |
| 399 | m.globalnames[name] = 1 |
| 400 | elif what == "absolute_import": |
| 401 | fromlist, name = args |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 402 | have_star = 0 |
| 403 | if fromlist is not None: |
| 404 | if "*" in fromlist: |
| 405 | have_star = 1 |
| 406 | fromlist = [f for f in fromlist if f != "*"] |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 407 | self._safe_import_hook(name, m, fromlist, level=0) |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 408 | if have_star: |
| 409 | # We've encountered an "import *". If it is a Python module, |
| 410 | # the code has already been parsed and we can suck out the |
| 411 | # global names. |
| 412 | mm = None |
| 413 | if m.__path__: |
| 414 | # At this point we don't know whether 'name' is a |
| 415 | # submodule of 'm' or a global module. Let's just try |
| 416 | # the full name first. |
| 417 | mm = self.modules.get(m.__name__ + "." + name) |
| 418 | if mm is None: |
| 419 | mm = self.modules.get(name) |
| 420 | if mm is not None: |
| 421 | m.globalnames.update(mm.globalnames) |
| 422 | m.starimports.update(mm.starimports) |
| 423 | if mm.__code__ is None: |
| 424 | m.starimports[name] = 1 |
| 425 | else: |
| 426 | m.starimports[name] = 1 |
Guido van Rossum | fc2a0a8 | 2006-10-27 23:06:01 +0000 | [diff] [blame] | 427 | elif what == "relative_import": |
| 428 | level, fromlist, name = args |
| 429 | if name: |
| 430 | self._safe_import_hook(name, m, fromlist, level=level) |
| 431 | else: |
| 432 | parent = self.determine_parent(m, level=level) |
| 433 | self._safe_import_hook(parent.__name__, None, fromlist, level=0) |
| 434 | else: |
| 435 | # We don't expect anything else from the generator. |
| 436 | raise RuntimeError(what) |
| 437 | |
Guido van Rossum | 3c51cf2 | 1998-03-05 05:15:07 +0000 | [diff] [blame] | 438 | for c in co.co_consts: |
| 439 | if isinstance(c, type(co)): |
| 440 | self.scan_code(c, m) |
| 441 | |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 442 | def load_package(self, fqname, pathname): |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 443 | self.msgin(2, "load_package", fqname, pathname) |
Thomas Heller | c7aaf95 | 2002-11-14 18:45:11 +0000 | [diff] [blame] | 444 | newname = replacePackageMap.get(fqname) |
| 445 | if newname: |
| 446 | fqname = newname |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 447 | m = self.add_module(fqname) |
| 448 | m.__file__ = pathname |
| 449 | m.__path__ = [pathname] |
Guido van Rossum | f1b5a0e | 1998-05-18 20:21:56 +0000 | [diff] [blame] | 450 | |
Guido van Rossum | e7e632a | 1998-09-14 16:02:28 +0000 | [diff] [blame] | 451 | # As per comment at top of file, simulate runtime __path__ additions. |
| 452 | m.__path__ = m.__path__ + packagePathMap.get(fqname, []) |
Guido van Rossum | f1b5a0e | 1998-05-18 20:21:56 +0000 | [diff] [blame] | 453 | |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 454 | fp, buf, stuff = self.find_module("__init__", m.__path__) |
| 455 | self.load_module(fqname, fp, buf, stuff) |
| 456 | self.msgout(2, "load_package ->", m) |
| 457 | return m |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 458 | |
| 459 | def add_module(self, fqname): |
Guido van Rossum | e2b70bc | 2006-08-18 22:13:04 +0000 | [diff] [blame] | 460 | if fqname in self.modules: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 461 | return self.modules[fqname] |
| 462 | self.modules[fqname] = m = Module(fqname) |
| 463 | return m |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 464 | |
Just van Rossum | f0dfbaf | 2003-03-05 17:23:48 +0000 | [diff] [blame] | 465 | def find_module(self, name, path, parent=None): |
| 466 | if parent is not None: |
Thomas Heller | 2e7c832 | 2004-05-11 15:10:59 +0000 | [diff] [blame] | 467 | # assert path is not None |
Just van Rossum | f0dfbaf | 2003-03-05 17:23:48 +0000 | [diff] [blame] | 468 | fullname = parent.__name__+'.'+name |
Guido van Rossum | 03f7f08 | 2001-10-18 19:15:32 +0000 | [diff] [blame] | 469 | else: |
| 470 | fullname = name |
| 471 | if fullname in self.excludes: |
| 472 | self.msgout(3, "find_module -> Excluded", fullname) |
Guido van Rossum | 78fc363 | 1998-03-20 17:37:24 +0000 | [diff] [blame] | 473 | raise ImportError, name |
| 474 | |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 475 | if path is None: |
| 476 | if name in sys.builtin_module_names: |
| 477 | return (None, None, ("", "", imp.C_BUILTIN)) |
Guido van Rossum | 78fc363 | 1998-03-20 17:37:24 +0000 | [diff] [blame] | 478 | |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 479 | path = self.path |
| 480 | return imp.find_module(name, path) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 481 | |
| 482 | def report(self): |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 483 | """Print a report to stdout, listing the found modules with their |
| 484 | paths, as well as modules that are missing, or seem to be missing. |
| 485 | """ |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 486 | print() |
| 487 | print(" %-25s %s" % ("Name", "File")) |
| 488 | print(" %-25s %s" % ("----", "----")) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 489 | # Print modules found |
Guido van Rossum | d59cde8 | 2007-06-12 00:25:08 +0000 | [diff] [blame] | 490 | keys = sorted(self.modules.keys()) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 491 | for key in keys: |
| 492 | m = self.modules[key] |
| 493 | if m.__path__: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 494 | print("P", end=' ') |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 495 | else: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 496 | print("m", end=' ') |
| 497 | print("%-25s" % key, m.__file__ or "") |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 498 | |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 499 | # Print missing modules |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 500 | missing, maybe = self.any_missing_maybe() |
| 501 | if missing: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 502 | print() |
| 503 | print("Missing modules:") |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 504 | for name in missing: |
Guido van Rossum | d59cde8 | 2007-06-12 00:25:08 +0000 | [diff] [blame] | 505 | mods = sorted(self.badmodules[name].keys()) |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 506 | print("?", name, "imported from", ', '.join(mods)) |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 507 | # Print modules that may be missing, but then again, maybe not... |
| 508 | if maybe: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 509 | print() |
| 510 | print("Submodules thay appear to be missing, but could also be", end=' ') |
| 511 | print("global names in the parent package:") |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 512 | for name in maybe: |
Guido van Rossum | d59cde8 | 2007-06-12 00:25:08 +0000 | [diff] [blame] | 513 | mods = sorted(self.badmodules[name].keys()) |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 514 | print("?", name, "imported from", ', '.join(mods)) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 515 | |
Guido van Rossum | 03f7f08 | 2001-10-18 19:15:32 +0000 | [diff] [blame] | 516 | def any_missing(self): |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 517 | """Return a list of modules that appear to be missing. Use |
| 518 | any_missing_maybe() if you want to know which modules are |
| 519 | certain to be missing, and which *may* be missing. |
| 520 | """ |
| 521 | missing, maybe = self.any_missing_maybe() |
| 522 | return missing + maybe |
| 523 | |
| 524 | def any_missing_maybe(self): |
| 525 | """Return two lists, one with modules that are certainly missing |
| 526 | and one with modules that *may* be missing. The latter names could |
| 527 | either be submodules *or* just global names in the package. |
| 528 | |
| 529 | The reason it can't always be determined is that it's impossible to |
| 530 | tell which names are imported when "from module import *" is done |
| 531 | with an extension module, short of actually importing it. |
| 532 | """ |
Guido van Rossum | 03f7f08 | 2001-10-18 19:15:32 +0000 | [diff] [blame] | 533 | missing = [] |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 534 | maybe = [] |
| 535 | for name in self.badmodules: |
| 536 | if name in self.excludes: |
| 537 | continue |
| 538 | i = name.rfind(".") |
| 539 | if i < 0: |
| 540 | missing.append(name) |
| 541 | continue |
| 542 | subname = name[i+1:] |
| 543 | pkgname = name[:i] |
| 544 | pkg = self.modules.get(pkgname) |
| 545 | if pkg is not None: |
| 546 | if pkgname in self.badmodules[name]: |
| 547 | # The package tried to import this module itself and |
| 548 | # failed. It's definitely missing. |
| 549 | missing.append(name) |
| 550 | elif subname in pkg.globalnames: |
| 551 | # It's a global in the package: definitely not missing. |
| 552 | pass |
| 553 | elif pkg.starimports: |
| 554 | # It could be missing, but the package did an "import *" |
| 555 | # from a non-Python module, so we simply can't be sure. |
| 556 | maybe.append(name) |
| 557 | else: |
| 558 | # It's not a global in the package, the package didn't |
| 559 | # do funny star imports, it's very likely to be missing. |
| 560 | # The symbol could be inserted into the package from the |
| 561 | # outside, but since that's not good style we simply list |
| 562 | # it missing. |
| 563 | missing.append(name) |
| 564 | else: |
| 565 | missing.append(name) |
| 566 | missing.sort() |
| 567 | maybe.sort() |
| 568 | return missing, maybe |
Guido van Rossum | 03f7f08 | 2001-10-18 19:15:32 +0000 | [diff] [blame] | 569 | |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 570 | def replace_paths_in_code(self, co): |
| 571 | new_filename = original_filename = os.path.normpath(co.co_filename) |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 572 | for f, r in self.replace_paths: |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 573 | if original_filename.startswith(f): |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 574 | new_filename = r + original_filename[len(f):] |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 575 | break |
| 576 | |
| 577 | if self.debug and original_filename not in self.processed_paths: |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 578 | if new_filename != original_filename: |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 579 | self.msgout(2, "co_filename %r changed to %r" \ |
| 580 | % (original_filename,new_filename,)) |
| 581 | else: |
| 582 | self.msgout(2, "co_filename %r remains unchanged" \ |
| 583 | % (original_filename,)) |
| 584 | self.processed_paths.append(original_filename) |
| 585 | |
| 586 | consts = list(co.co_consts) |
| 587 | for i in range(len(consts)): |
| 588 | if isinstance(consts[i], type(co)): |
| 589 | consts[i] = self.replace_paths_in_code(consts[i]) |
| 590 | |
Tim Peters | 2c60f7a | 2003-01-29 03:49:43 +0000 | [diff] [blame] | 591 | return new.code(co.co_argcount, co.co_nlocals, co.co_stacksize, |
| 592 | co.co_flags, co.co_code, tuple(consts), co.co_names, |
| 593 | co.co_varnames, new_filename, co.co_name, |
Neal Norwitz | 82c7231 | 2002-11-12 23:09:12 +0000 | [diff] [blame] | 594 | co.co_firstlineno, co.co_lnotab, |
| 595 | co.co_freevars, co.co_cellvars) |
Guido van Rossum | 6b767ac | 2001-03-20 20:43:34 +0000 | [diff] [blame] | 596 | |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 597 | |
| 598 | def test(): |
| 599 | # Parse command line |
| 600 | import getopt |
| 601 | try: |
Guido van Rossum | baf0603 | 1998-08-25 14:06:55 +0000 | [diff] [blame] | 602 | opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:") |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 603 | except getopt.error as msg: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 604 | print(msg) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 605 | return |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 606 | |
| 607 | # Process options |
| 608 | debug = 1 |
| 609 | domods = 0 |
| 610 | addpath = [] |
Guido van Rossum | baf0603 | 1998-08-25 14:06:55 +0000 | [diff] [blame] | 611 | exclude = [] |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 612 | for o, a in opts: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 613 | if o == '-d': |
| 614 | debug = debug + 1 |
| 615 | if o == '-m': |
| 616 | domods = 1 |
| 617 | if o == '-p': |
Walter Dörwald | aaab30e | 2002-09-11 20:36:02 +0000 | [diff] [blame] | 618 | addpath = addpath + a.split(os.pathsep) |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 619 | if o == '-q': |
| 620 | debug = 0 |
Guido van Rossum | baf0603 | 1998-08-25 14:06:55 +0000 | [diff] [blame] | 621 | if o == '-x': |
| 622 | exclude.append(a) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 623 | |
| 624 | # Provide default arguments |
| 625 | if not args: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 626 | script = "hello.py" |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 627 | else: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 628 | script = args[0] |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 629 | |
| 630 | # Set the path based on sys.path and the script directory |
| 631 | path = sys.path[:] |
| 632 | path[0] = os.path.dirname(script) |
| 633 | path = addpath + path |
| 634 | if debug > 1: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 635 | print("path:") |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 636 | for item in path: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 637 | print(" ", repr(item)) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 638 | |
| 639 | # Create the module finder and turn its crank |
Guido van Rossum | baf0603 | 1998-08-25 14:06:55 +0000 | [diff] [blame] | 640 | mf = ModuleFinder(path, debug, exclude) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 641 | for arg in args[1:]: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 642 | if arg == '-m': |
| 643 | domods = 1 |
| 644 | continue |
| 645 | if domods: |
| 646 | if arg[-2:] == '.*': |
| 647 | mf.import_hook(arg[:-2], None, ["*"]) |
| 648 | else: |
| 649 | mf.import_hook(arg) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 650 | else: |
Guido van Rossum | 912a14c | 1998-03-05 04:56:37 +0000 | [diff] [blame] | 651 | mf.load_file(arg) |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 652 | mf.run_script(script) |
| 653 | mf.report() |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 654 | return mf # for -i debugging |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 655 | |
| 656 | |
| 657 | if __name__ == '__main__': |
| 658 | try: |
Just van Rossum | e29310a | 2002-12-31 16:33:00 +0000 | [diff] [blame] | 659 | mf = test() |
Guido van Rossum | 75dc496 | 1998-03-05 03:42:00 +0000 | [diff] [blame] | 660 | except KeyboardInterrupt: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 661 | print("\n[interrupt]") |