Loads bytecode from a file or file like object.
(self, f)
| 51 | self.code = None |
| 52 | |
| 53 | def load_bytecode(self, f): |
| 54 | """Loads bytecode from a file or file like object.""" |
| 55 | # make sure the magic header is correct |
| 56 | magic = f.read(len(bc_magic)) |
| 57 | if magic != bc_magic: |
| 58 | self.reset() |
| 59 | return |
| 60 | # the source code of the file changed, we need to reload |
| 61 | checksum = pickle.load(f) |
| 62 | if self.checksum != checksum: |
| 63 | self.reset() |
| 64 | return |
| 65 | # now load the code. Because marshal is not able to load |
| 66 | # from arbitrary streams we have to work around that |
| 67 | if isinstance(f, file): |
| 68 | self.code = marshal.load(f) |
| 69 | else: |
| 70 | self.code = marshal.loads(f.read()) |
| 71 | |
| 72 | def write_bytecode(self, f): |
| 73 | """Dump the bytecode into the file or file like object passed.""" |
no test coverage detected