MCPcopy
hub / github.com/pallets/jinja / load_bytecode

Method load_bytecode

src/jinja2/bccache.py:65–82  ·  view source on GitHub ↗

Loads bytecode from a file or file like object.

(self, f: t.BinaryIO)

Source from the content-addressed store, hash-verified

63 self.code: t.Optional[CodeType] = None
64
65 def load_bytecode(self, f: t.BinaryIO) -> None:
66 """Loads bytecode from a file or file like object."""
67 # make sure the magic header is correct
68 magic = f.read(len(bc_magic))
69 if magic != bc_magic:
70 self.reset()
71 return
72 # the source code of the file changed, we need to reload
73 checksum = pickle.load(f)
74 if self.checksum != checksum:
75 self.reset()
76 return
77 # if marshal_load fails then we need to reload
78 try:
79 self.code = marshal.load(f)
80 except (EOFError, ValueError, TypeError):
81 self.reset()
82 return
83
84 def write_bytecode(self, f: t.IO[bytes]) -> None:
85 """Dump the bytecode into the file or file like object passed."""

Callers 2

bytecode_from_stringMethod · 0.95
load_bytecodeMethod · 0.45

Calls 2

resetMethod · 0.95
loadMethod · 0.45

Tested by

no test coverage detected