Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 1 | """Abstract base classes related to import.""" |
| 2 | from . import _bootstrap |
| 3 | from . import machinery |
| 4 | import abc |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 5 | import imp |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 6 | import marshal |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 7 | import sys |
| 8 | import tokenize |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 9 | import warnings |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 10 | |
| 11 | |
| 12 | class Loader(metaclass=abc.ABCMeta): |
| 13 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 14 | """Abstract base class for import loaders.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 15 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 16 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 17 | def load_module(self, fullname): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 18 | """Abstract method which when implemented should load a module. |
| 19 | The fullname is a str.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 20 | raise NotImplementedError |
| 21 | |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 22 | |
| 23 | class Finder(metaclass=abc.ABCMeta): |
| 24 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 25 | """Abstract base class for import finders.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 26 | |
| 27 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 28 | def find_module(self, fullname, path=None): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 29 | """Abstract method which when implemented should find a module. |
| 30 | The fullname is a str and the optional path is a str or None. |
| 31 | Returns a Loader object. |
| 32 | """ |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 33 | raise NotImplementedError |
| 34 | |
| 35 | Finder.register(machinery.BuiltinImporter) |
| 36 | Finder.register(machinery.FrozenImporter) |
| 37 | Finder.register(machinery.PathFinder) |
| 38 | |
| 39 | |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 40 | class ResourceLoader(Loader): |
| 41 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 42 | """Abstract base class for loaders which can return data from their |
| 43 | back-end storage. |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 44 | |
| 45 | This ABC represents one of the optional protocols specified by PEP 302. |
| 46 | |
| 47 | """ |
| 48 | |
| 49 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 50 | def get_data(self, path): |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 51 | """Abstract method which when implemented should return the bytes for |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 52 | the specified path. The path must be a str.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 53 | raise NotImplementedError |
| 54 | |
| 55 | |
| 56 | class InspectLoader(Loader): |
| 57 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 58 | """Abstract base class for loaders which support inspection about the |
| 59 | modules they can load. |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 60 | |
| 61 | This ABC represents one of the optional protocols specified by PEP 302. |
| 62 | |
| 63 | """ |
| 64 | |
| 65 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 66 | def is_package(self, fullname): |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 67 | """Abstract method which when implemented should return whether the |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 68 | module is a package. The fullname is a str. Returns a bool.""" |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 69 | raise NotImplementedError |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 70 | |
| 71 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 72 | def get_code(self, fullname): |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 73 | """Abstract method which when implemented should return the code object |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 74 | for the module. The fullname is a str. Returns a types.CodeType.""" |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 75 | raise NotImplementedError |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 76 | |
| 77 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 78 | def get_source(self, fullname): |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 79 | """Abstract method which should return the source code for the |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 80 | module. The fullname is a str. Returns a str.""" |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 81 | raise NotImplementedError |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 82 | |
Brett Cannon | a113ac5 | 2009-03-15 01:41:33 +0000 | [diff] [blame] | 83 | InspectLoader.register(machinery.BuiltinImporter) |
Brett Cannon | 8d11013 | 2009-03-15 02:20:16 +0000 | [diff] [blame] | 84 | InspectLoader.register(machinery.FrozenImporter) |
Brett Cannon | a113ac5 | 2009-03-15 01:41:33 +0000 | [diff] [blame] | 85 | |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 86 | |
Brett Cannon | 6919427 | 2009-07-20 04:23:48 +0000 | [diff] [blame] | 87 | class ExecutionLoader(InspectLoader): |
| 88 | |
| 89 | """Abstract base class for loaders that wish to support the execution of |
| 90 | modules as scripts. |
| 91 | |
| 92 | This ABC represents one of the optional protocols specified in PEP 302. |
| 93 | |
| 94 | """ |
| 95 | |
| 96 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 97 | def get_filename(self, fullname): |
Brett Cannon | 6919427 | 2009-07-20 04:23:48 +0000 | [diff] [blame] | 98 | """Abstract method which should return the value that __file__ is to be |
| 99 | set to.""" |
| 100 | raise NotImplementedError |
| 101 | |
| 102 | |
Brett Cannon | 0cf9e6a | 2010-06-28 04:57:24 +0000 | [diff] [blame] | 103 | class SourceLoader(_bootstrap.SourceLoader, ResourceLoader, ExecutionLoader): |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 104 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 105 | """Abstract base class for loading source code (and optionally any |
| 106 | corresponding bytecode). |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 107 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 108 | To support loading from source code, the abstractmethods inherited from |
| 109 | ResourceLoader and ExecutionLoader need to be implemented. To also support |
| 110 | loading from bytecode, the optional methods specified directly by this ABC |
| 111 | is required. |
| 112 | |
| 113 | Inherited abstractmethods not implemented in this ABC: |
| 114 | |
| 115 | * ResourceLoader.get_data |
| 116 | * ExecutionLoader.get_filename |
| 117 | |
| 118 | """ |
| 119 | |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 120 | def path_mtime(self, path): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 121 | """Return the (int) modification time for the path (str).""" |
Antoine Pitrou | 5136ac0 | 2012-01-13 18:52:16 +0100 | [diff] [blame] | 122 | if self.path_stats.__func__ is SourceLoader.path_stats: |
| 123 | raise NotImplementedError |
| 124 | return int(self.path_stats(path)['mtime']) |
| 125 | |
| 126 | def path_stats(self, path): |
| 127 | """Return a metadata dict for the source pointed to by the path (str). |
| 128 | Possible keys: |
| 129 | - 'mtime' (mandatory) is the numeric timestamp of last source |
| 130 | code modification; |
| 131 | - 'size' (optional) is the size in bytes of the source code. |
| 132 | """ |
| 133 | if self.path_mtime.__func__ is SourceLoader.path_mtime: |
| 134 | raise NotImplementedError |
| 135 | return {'mtime': self.path_mtime(path)} |
Brett Cannon | 8d18907 | 2010-08-22 20:38:47 +0000 | [diff] [blame] | 136 | |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 137 | def set_data(self, path, data): |
Brett Cannon | 8d18907 | 2010-08-22 20:38:47 +0000 | [diff] [blame] | 138 | """Write the bytes to the path (if possible). |
| 139 | |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 140 | Accepts a str path and data as bytes. |
| 141 | |
Brett Cannon | 8d18907 | 2010-08-22 20:38:47 +0000 | [diff] [blame] | 142 | Any needed intermediary directories are to be created. If for some |
| 143 | reason the file cannot be written because of permissions, fail |
| 144 | silently. |
| 145 | |
| 146 | """ |
| 147 | raise NotImplementedError |
| 148 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 149 | |
| 150 | class PyLoader(SourceLoader): |
| 151 | |
| 152 | """Implement the deprecated PyLoader ABC in terms of SourceLoader. |
| 153 | |
| 154 | This class has been deprecated! It is slated for removal in Python 3.4. |
| 155 | If compatibility with Python 3.1 is not needed then implement the |
| 156 | SourceLoader ABC instead of this class. If Python 3.1 compatibility is |
| 157 | needed, then use the following idiom to have a single class that is |
| 158 | compatible with Python 3.1 onwards:: |
| 159 | |
| 160 | try: |
| 161 | from importlib.abc import SourceLoader |
| 162 | except ImportError: |
| 163 | from importlib.abc import PyLoader as SourceLoader |
| 164 | |
| 165 | |
| 166 | class CustomLoader(SourceLoader): |
| 167 | def get_filename(self, fullname): |
| 168 | # Implement ... |
| 169 | |
| 170 | def source_path(self, fullname): |
| 171 | '''Implement source_path in terms of get_filename.''' |
| 172 | try: |
| 173 | return self.get_filename(fullname) |
| 174 | except ImportError: |
| 175 | return None |
| 176 | |
| 177 | def is_package(self, fullname): |
| 178 | filename = os.path.basename(self.get_filename(fullname)) |
| 179 | return os.path.splitext(filename)[0] == '__init__' |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 180 | |
| 181 | """ |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 182 | |
| 183 | @abc.abstractmethod |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 184 | def is_package(self, fullname): |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 185 | raise NotImplementedError |
| 186 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 187 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 188 | def source_path(self, fullname): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 189 | """Abstract method. Accepts a str module name and returns the path to |
| 190 | the source code for the module.""" |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 191 | raise NotImplementedError |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 192 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 193 | def get_filename(self, fullname): |
| 194 | """Implement get_filename in terms of source_path. |
| 195 | |
| 196 | As get_filename should only return a source file path there is no |
| 197 | chance of the path not existing but loading still being possible, so |
| 198 | ImportError should propagate instead of being turned into returning |
| 199 | None. |
| 200 | |
| 201 | """ |
| 202 | warnings.warn("importlib.abc.PyLoader is deprecated and is " |
| 203 | "slated for removal in Python 3.4; " |
| 204 | "use SourceLoader instead. " |
| 205 | "See the importlib documentation on how to be " |
| 206 | "compatible with Python 3.1 onwards.", |
Florent Xicluna | 6731775 | 2011-12-10 11:07:42 +0100 | [diff] [blame] | 207 | DeprecationWarning) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 208 | path = self.source_path(fullname) |
| 209 | if path is None: |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 210 | raise ImportError(name=fullname) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 211 | else: |
| 212 | return path |
| 213 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 214 | |
| 215 | class PyPycLoader(PyLoader): |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 216 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 217 | """Abstract base class to assist in loading source and bytecode by |
| 218 | requiring only back-end storage methods to be implemented. |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 219 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 220 | This class has been deprecated! Removal is slated for Python 3.4. Implement |
| 221 | the SourceLoader ABC instead. If Python 3.1 compatibility is needed, see |
| 222 | PyLoader. |
| 223 | |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 224 | The methods get_code, get_source, and load_module are implemented for the |
| 225 | user. |
| 226 | |
| 227 | """ |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 228 | |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 229 | def get_filename(self, fullname): |
| 230 | """Return the source or bytecode file path.""" |
| 231 | path = self.source_path(fullname) |
| 232 | if path is not None: |
| 233 | return path |
| 234 | path = self.bytecode_path(fullname) |
| 235 | if path is not None: |
| 236 | return path |
| 237 | raise ImportError("no source or bytecode path available for " |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 238 | "{0!r}".format(fullname), name=fullname) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 239 | |
| 240 | def get_code(self, fullname): |
| 241 | """Get a code object from source or bytecode.""" |
| 242 | warnings.warn("importlib.abc.PyPycLoader is deprecated and slated for " |
| 243 | "removal in Python 3.4; use SourceLoader instead. " |
| 244 | "If Python 3.1 compatibility is required, see the " |
| 245 | "latest documentation for PyLoader.", |
Florent Xicluna | 6731775 | 2011-12-10 11:07:42 +0100 | [diff] [blame] | 246 | DeprecationWarning) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 247 | source_timestamp = self.source_mtime(fullname) |
| 248 | # Try to use bytecode if it is available. |
| 249 | bytecode_path = self.bytecode_path(fullname) |
| 250 | if bytecode_path: |
| 251 | data = self.get_data(bytecode_path) |
| 252 | try: |
| 253 | magic = data[:4] |
| 254 | if len(magic) < 4: |
Philip Jenvey | 4b42ff6 | 2012-02-24 21:48:17 -0800 | [diff] [blame] | 255 | raise ImportError( |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 256 | "bad magic number in {}".format(fullname), |
| 257 | name=fullname, path=bytecode_path) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 258 | raw_timestamp = data[4:8] |
| 259 | if len(raw_timestamp) < 4: |
| 260 | raise EOFError("bad timestamp in {}".format(fullname)) |
Brett Cannon | c264e3e | 2012-01-25 18:58:03 -0500 | [diff] [blame] | 261 | pyc_timestamp = _bootstrap._r_long(raw_timestamp) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 262 | bytecode = data[8:] |
| 263 | # Verify that the magic number is valid. |
| 264 | if imp.get_magic() != magic: |
Philip Jenvey | 4b42ff6 | 2012-02-24 21:48:17 -0800 | [diff] [blame] | 265 | raise ImportError( |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 266 | "bad magic number in {}".format(fullname), |
| 267 | name=fullname, path=bytecode_path) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 268 | # Verify that the bytecode is not stale (only matters when |
| 269 | # there is source to fall back on. |
| 270 | if source_timestamp: |
| 271 | if pyc_timestamp < source_timestamp: |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 272 | raise ImportError("bytecode is stale", name=fullname, |
| 273 | path=bytecode_path) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 274 | except (ImportError, EOFError): |
| 275 | # If source is available give it a shot. |
| 276 | if source_timestamp is not None: |
| 277 | pass |
| 278 | else: |
| 279 | raise |
| 280 | else: |
| 281 | # Bytecode seems fine, so try to use it. |
| 282 | return marshal.loads(bytecode) |
| 283 | elif source_timestamp is None: |
| 284 | raise ImportError("no source or bytecode available to create code " |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 285 | "object for {0!r}".format(fullname), |
| 286 | name=fullname) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 287 | # Use the source. |
| 288 | source_path = self.source_path(fullname) |
| 289 | if source_path is None: |
| 290 | message = "a source path must exist to load {0}".format(fullname) |
Brett Cannon | bbb6680 | 2012-04-12 21:09:01 -0400 | [diff] [blame] | 291 | raise ImportError(message, name=fullname) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 292 | source = self.get_data(source_path) |
| 293 | code_object = compile(source, source_path, 'exec', dont_inherit=True) |
| 294 | # Generate bytecode and write it out. |
| 295 | if not sys.dont_write_bytecode: |
| 296 | data = bytearray(imp.get_magic()) |
Brett Cannon | c264e3e | 2012-01-25 18:58:03 -0500 | [diff] [blame] | 297 | data.extend(_bootstrap._w_long(source_timestamp)) |
Brett Cannon | f23e374 | 2010-06-27 23:57:46 +0000 | [diff] [blame] | 298 | data.extend(marshal.dumps(code_object)) |
| 299 | self.write_bytecode(fullname, data) |
| 300 | return code_object |
| 301 | |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 302 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 303 | def source_mtime(self, fullname): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 304 | """Abstract method. Accepts a str filename and returns an int |
Brett Cannon | 7aa21f7 | 2009-03-15 00:53:05 +0000 | [diff] [blame] | 305 | modification time for the source of the module.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 306 | raise NotImplementedError |
| 307 | |
| 308 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 309 | def bytecode_path(self, fullname): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 310 | """Abstract method. Accepts a str filename and returns the str pathname |
| 311 | to the bytecode for the module.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 312 | raise NotImplementedError |
| 313 | |
| 314 | @abc.abstractmethod |
Raymond Hettinger | cd92f37 | 2011-01-13 02:31:25 +0000 | [diff] [blame] | 315 | def write_bytecode(self, fullname, bytecode): |
Raymond Hettinger | d958ea7 | 2011-01-13 19:08:04 +0000 | [diff] [blame] | 316 | """Abstract method. Accepts a str filename and bytes object |
| 317 | representing the bytecode for the module. Returns a boolean |
| 318 | representing whether the bytecode was written or not.""" |
Brett Cannon | 2a922ed | 2009-03-09 03:35:50 +0000 | [diff] [blame] | 319 | raise NotImplementedError |