MCPcopy Index your code
hub / github.com/nodejs/node / Bucket

Class Bucket

tools/inspector_protocol/jinja2/bccache.py:60–114  ·  view source on GitHub ↗

Buckets are used to store the bytecode for one template. It's created and initialized by the bytecode cache and passed to the loading functions. The buckets get an internal checksum from the cache assigned and use this to automatically reject outdated cache material. Individual byteco

Source from the content-addressed store, hash-verified

58
59
60class Bucket(object):
61 """Buckets are used to store the bytecode for one template. It's created
62 and initialized by the bytecode cache and passed to the loading functions.
63
64 The buckets get an internal checksum from the cache assigned and use this
65 to automatically reject outdated cache material. Individual bytecode
66 cache subclasses don't have to care about cache invalidation.
67 """
68
69 def __init__(self, environment, key, checksum):
70 self.environment = environment
71 self.key = key
72 self.checksum = checksum
73 self.reset()
74
75 def reset(self):
76 """Resets the bucket (unloads the bytecode)."""
77 self.code = None
78
79 def load_bytecode(self, f):
80 """Loads bytecode from a file or file like object."""
81 # make sure the magic header is correct
82 magic = f.read(len(bc_magic))
83 if magic != bc_magic:
84 self.reset()
85 return
86 # the source code of the file changed, we need to reload
87 checksum = pickle.load(f)
88 if self.checksum != checksum:
89 self.reset()
90 return
91 # if marshal_load fails then we need to reload
92 try:
93 self.code = marshal_load(f)
94 except (EOFError, ValueError, TypeError):
95 self.reset()
96 return
97
98 def write_bytecode(self, f):
99 """Dump the bytecode into the file or file like object passed."""
100 if self.code is None:
101 raise TypeError('can\'t write empty bucket')
102 f.write(bc_magic)
103 pickle.dump(self.checksum, f, 2)
104 marshal_dump(self.code, f)
105
106 def bytecode_from_string(self, string):
107 """Load bytecode from a string."""
108 self.load_bytecode(BytesIO(string))
109
110 def bytecode_to_string(self):
111 """Return the bytecode as string."""
112 out = BytesIO()
113 self.write_bytecode(out)
114 return out.getvalue()
115
116
117class BytecodeCache(object):

Callers 1

get_bucketMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…