Caution
This API is not finalised, and may change in a patch version.
installer.records
¶
Provides an object-oriented model for handling PEP 376 RECORD files.
Example¶
>>> from installer.records import parse_record_file, RecordEntry
>>> lines = [
... "file.py,sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI,3144",
... "distribution-1.0.dist-info/RECORD,,",
... ]
>>> records = parse_record_file(lines)
>>> li = list(records)
>>> len(li)
2
>>> record_tuple = li[0]
>>> record_tuple
('file.py', 'sha256=AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI', '3144')
>>> record = RecordEntry.from_elements(*record_tuple)
>>> record
RecordEntry(path='file.py', hash_=Hash(name='sha256', value='AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI'), size=3144)
>>> record.path
'file.py'
>>> record.hash_
Hash(name='sha256', value='AVTFPZpEKzuHr7OvQZmhaU3LvwKz06AJw8mT\\_pNh2yI')
>>> record.size
3144
>>> record.validate(b"...")
False
Reference¶
- installer.records.parse_record_file(rows)¶
Parse a PEP 376 RECORD.
Returns an iterable of 3-value tuples, that can be passed to
RecordEntry.from_elements
.
- class installer.records.RecordEntry¶
Represents a single record in a RECORD file.
A list of
RecordEntry
objects fully represents a RECORD file.Most consumers should use
RecordEntry.from_elements()
, since no validation or parsing is performed by this constructor.- to_row(path_prefix=None)¶
Convert this into a 3-element tuple that can be written in a RECORD file.
- __init__(path, hash_, size)¶
- validate(data)¶
Validate that
data
matches this instance.Attention
Deprecated since version 0.8.0: Use
validate_stream()
instead, withBytesIO(data)
.
- validate_stream(stream)¶
Validate that data read from stream matches this instance.
- classmethod from_elements(path, hash_, size)¶
Build a RecordEntry object, from values of the elements.
Typical usage:
for row in parse_record_file(f): record = RecordEntry.from_elements(row[0], row[1], row[2])
Meaning of each element is specified in PEP 376.
- Parameters:
- Raises:
InvalidRecordEntry – if any element is invalid
- Return type:
- class installer.records.Hash¶
Represents the “hash” element of a RecordEntry.
Most consumers should use
Hash.parse()
instead, since no validation or parsing is performed by this constructor.- validate(data)¶
Validate that
data
matches this instance.