dist_meta.record

Classes to model parts of RECORD files.

Classes:

FileHash(name, value)

Represents a checksum for a file in a RECORD file, or as the URL fragment in a PEP 503 repository URL.

RecordEntry(path[, hash, size, distro])

Represents a path in a distribution.

class RecordEntry(path, hash=None, size=None, distro=None)[source]

Bases: PurePosixPath

Represents a path in a distribution.

Parameters

Note

Path operations (joinpath(), parent etc.) will return a standard pathlib.PurePosixPath object without the extended attributes of this class.

Methods:

__repr__()

Return a string representation of the RecordEntry.

as_record_entry()

Returns an entry for a RECORD file, in the form <name>,<hash>,<size>.

from_record_entry(entry[, distro])

Construct a RecordEntry from a line in a RECORD file, in the form <name>,<hash>,<size>.

read_bytes()

Open the file in bytes mode, read it, and close the file.

read_text([encoding, errors])

Open the file in text mode, read it, and close the file.

Attributes:

distro

The distribution the file belongs to.

hash

The hash/checksum of the file.

size

The size of the file.

__repr__()[source]

Return a string representation of the RecordEntry.

Return type

str

as_record_entry()[source]

Returns an entry for a RECORD file, in the form <name>,<hash>,<size>.

Return type

str

distro

Type:    Optional[Distribution]

The distribution the file belongs to.

classmethod from_record_entry(entry, distro=None)[source]

Construct a RecordEntry from a line in a RECORD file, in the form <name>,<hash>,<size>.

New in version 0.2.0.

Parameters
Return type

RecordEntry

hash

Type:    Optional[FileHash]

The hash/checksum of the file.

read_bytes()[source]

Open the file in bytes mode, read it, and close the file.

Return type

bytes

Returns

The content of the file.

Attention

This operation requires a value for self.distro.

read_text(encoding='UTF-8', errors=None)[source]

Open the file in text mode, read it, and close the file.

Parameters
Return type

str

Returns

The content of the file.

Attention

This operation requires a value for self.distro.

size

Type:    Optional[int]

The size of the file.

namedtuple FileHash(name, value)[source]

Bases: NamedTuple

Represents a checksum for a file in a RECORD file, or as the URL fragment in a PEP 503 repository URL.

Fields
  1.  name (str) – The name of the hash algorithm.

  2.  value (str) – The urlsafe_b64encode()’d hexdigest of the hash.

digest()[source]

Returns the digest of the hash.

This is a bytes object which may contain bytes in the whole range from 0 to 255.

Return type

bytes

classmethod from_hash(the_hash)[source]

Construct a FileHash object from a hashlib hash object.

Parameters

the_hash (hashlib.HASH)

Return type

FileHash

classmethod from_string(string)[source]

Constructs a FileHash from a string in the form <name>=<value>.

Parameters

string (str)

Return type

FileHash

hexdigest()[source]

Like self.digest() except the digest is returned as a string object of double length, containing only hexadecimal digits.

This may be used to exchange the value safely in email or other non-binary environments.

Return type

str

to_string()[source]

Returns the FileHash as a string, in the form <name>=<value>.

Return type

str