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
>>> 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 = li[0]
>>> 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.
- Parameters
rows (Iterator[str]) – iterator providing lines of a RECORD.
- Return type
Iterator[RecordEntry]
-
class
installer.records.
RecordEntry
¶ Represents a single record in a RECORD file.
A list of
RecordEntry
objects fully represents a RECORD file.-
__init__
(path, hash_, size)¶ Construct a
RecordEntry
object.Most consumers should use
RecordEntry.from_elements()
, since no validation or parsing is performed by this constructor.
-
validate
(data)¶ Validate that
data
matches this instance.
-
classmethod
from_elements
(path, hash_, size)¶ Build a RecordEntry object, from values of the elements.
Typical usage:
reader = csv.reader(f) for row in reader: 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.
-
__init__
(name, value)¶ Construct a
Hash
object.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.
-
classmethod
parse
(h)¶ Build a Hash object, from a “name=value” string.
This accepts a string of the format for the second element in a record, as described in PEP 376.
Typical usage:
Hash.parse("sha256=Y0sCextp4SQtQNU-MSs7SsdxD1W-gfKJtUlEbvZ3i-4")
- Parameters
h (str) – a name=value string
- Return type
-