dist_meta.record
¶
Classes to model parts of RECORD
files.
Classes:
|
Represents a checksum for a file in a |
|
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
path (
Union
[str
,Path
,PathLike
]) – The path to the file in the distribution, relative to the distribution root (i.e. thesite-packages
directory).hash (
Optional
[FileHash
]) – The hash/checksum of the file. DefaultNone
.distro (
Optional
[Distribution
]) – The distribution the file belongs to. DefaultNone
.
Note
Path operations (
joinpath()
,parent
etc.) will return a standardpathlib.PurePosixPath
object without the extended attributes of this class.Methods:
__repr__
()Return a string representation of the
RecordEntry
.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 aRECORD
file, in the form<name>,<hash>,<size>
.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:
The distribution the file belongs to.
The hash/checksum of the file.
The size of the file.
-
__repr__
()[source]¶ Return a string representation of the
RecordEntry
.- Return type
-
as_record_entry
()[source]¶ Returns an entry for a
RECORD
file, in the form<name>,<hash>,<size>
.- Return type
-
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 aRECORD
file, in the form<name>,<hash>,<size>
.New in version 0.2.0.
- Parameters
entry (
str
)distro (
Optional
[Distribution
]) – The distribution theRECORD
file belongs to. Optional. DefaultNone
.
- Return type
-
read_bytes
()[source]¶ Open the file in bytes mode, read it, and close the file.
- Return type
- 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
- Returns
The content of the file.
Attention
This operation requires a value for
self.distro
.
-
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
name (
str
) – The name of the hash algorithm.value (
str
) – Theurlsafe_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
-
classmethod
from_hash
(the_hash)[source]¶ Construct a
FileHash
object from ahashlib
hash object.- Parameters
the_hash (
hashlib.HASH
)- Return type
-
classmethod
from_string
(string)[source]¶ Constructs a
FileHash
from a string in the form<name>=<value>
.
-
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