MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / _Record

Class _Record

pipcl.py:3226–3268  ·  view source on GitHub ↗

Internal - builds up text suitable for writing to a RECORD item, e.g. within a wheel.

Source from the content-addressed store, hash-verified

3224
3225
3226class _Record:
3227 '''
3228 Internal - builds up text suitable for writing to a RECORD item, e.g.
3229 within a wheel.
3230 '''
3231 def __init__(self):
3232 self.text = ''
3233
3234 def add_content(self, content, to_, verbose=True):
3235 if isinstance(content, str):
3236 content = content.encode('utf8')
3237
3238 # Specification for the line we write is supposed to be in
3239 # https://packaging.python.org/en/latest/specifications/binary-distribution-format
3240 # but it's not very clear.
3241 #
3242 h = hashlib.sha256(content)
3243 digest = h.digest()
3244 digest = base64.urlsafe_b64encode(digest)
3245 digest = digest.rstrip(b'=')
3246 digest = digest.decode('utf8')
3247
3248 self.text += f'{to_},sha256={digest},{len(content)}\n'
3249 if verbose:
3250 log2(f'Adding {to_}')
3251
3252 def add_file(self, from_, to_):
3253 log1(f'Adding file: {os.path.relpath(from_)} => {to_}')
3254 with open(from_, 'rb') as f:
3255 content = f.read()
3256 self.add_content(content, to_, verbose=False)
3257
3258 def get(self, record_path=None):
3259 '''
3260 Returns contents of the RECORD file. If `record_path` is
3261 specified we append a final line `<record_path>,,`; this can be
3262 used to include the RECORD file itself in the contents, with
3263 empty hash and size fields.
3264 ''&#x27;
3265 ret = self.text
3266 if record_path:
3267 ret += f'{record_path},,\n'
3268 return ret
3269
3270
3271class NewFiles:

Callers 2

build_wheelMethod · 0.85
installMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…