debian.deb822 module¶
Dictionary-like interfaces to RFC822-like files
The Python deb822 aims to provide a dict-like interface to various RFC822-like
Debian data formats, like Packages/Sources, .changes/.dsc, pdiff Index files,
etc. As well as the generic Deb822
class, the specialised versions
of these classes (Packages
, Sources
, Changes
etc)
know about special fields that contain specially formatted data such as
dependency lists or whitespace separated sub-fields.
This module has few external dependencies, but can use python-apt if available to parse the data, which gives a very significant performance boost when iterating over big Packages files.
Whitespace separated data within fields are known as “multifields”. The “Files” field in Sources files, for instance, has three subfields, while “Files” in .changes files, has five; the relevant classes here know this and correctly handle these cases.
Key lookup in Deb822 objects and their multifields is case-insensitive, but the original case is always preserved, for example when printing the object.
The Debian project and individual developers make extensive use of GPG signatures including in-line signatures. GPG signatures are automatically detected, verified and the payload then offered to the parser.
Relevant documentation on the Deb822 file formats available here.
deb-control(5), the control file in the binary package (generated from debian/control in the source package)
deb-changes(5), changes files that developers upload to add new packages to the archive.
dsc(5), Debian Source Control file that defines the files that are part of a source package.
Debian mirror format, including documentation for Packages, Sources files etc.
Overview of deb822 Classes¶
Classes that deb822 provides:
Deb822
base class with no multifields. A Deb822 object holds a single entry from a Deb822-style file, where paragraphs are separated by blank lines and there may be many paragraphs within a file. Theiter_paragraphs()
function yields paragraphs from a data source.
Packages
represents a Packages file from a Debian mirror. It extends the Deb822 class by interpreting fields that are package relationships (Depends, Recommends etc). Iteration is forced through python-apt for performance and conformance.
Dsc
represents .dsc files (Debian Source Control) that are the metadata file of the source package.Multivalued fields:
Files: md5sum, size, name
Checksums-Sha1: sha1, size, name
Checksums-Sha256: sha256, size, name
Checksums-Sha512: sha512, size, name
Package-List: package, package-type, section, priority, _other
Sources
represents a Sources file from a Debian mirror. It extends the Dsc class by interpreting fields that are package relationships (Build-Depends, Build-Conflicts etc). Iteration is forced through python-apt for performance and conformance.
Release
represents a Release file from a Debian mirror.Multivalued fields:
MD5Sum: md5sum, size, name
SHA1: sha1, size, name
SHA256: sha256, size, name
SHA512: sha512, size, name
Changes
represents a .changes file that is uploaded to “change the archive” by including new source or binary packages.Multivalued fields:
Files: md5sum, size, section, priority, name
Checksums-Sha1: sha1, size, name
Checksums-Sha256: sha256, size, name
Checksums-Sha512: sha512, size, name
PdiffIndex
represents a pdiff Index file (foo.diff/Index) file from a Debian mirror.Multivalued fields:
SHA1-Current: SHA1, size
SHA1-History: SHA1, size, date
SHA1-Patches: SHA1, size, date
SHA1-Download: SHA1, size, filename
X-Unmerged-SHA1-History: SHA1, size, date
X-Unmerged-SHA1-Patches: SHA1, size, date
X-Unmerged-SHA1-Download: SHA1, size, filename
SHA256-Current: SHA256, size
SHA256-History: SHA256, size, date
SHA256-Patches: SHA256, size, date
SHA256-Download: SHA256, size, filename
X-Unmerged-SHA256-History: SHA256, size, date
X-Unmerged-SHA256-Patches: SHA256, size, date
X-Unmerged-SHA256-Download: SHA256, size, filename
Removals
represents the ftp-master removals file listing when and why source and binary packages are removed from the archive.
Input¶
Deb822 objects are normally initialized from a file object (from which at most one paragraph is read) or a string. Alternatively, any sequence that returns one line of input at a time may be used, e.g a list of strings.
PGP signatures, if present, will be stripped.
Example:
>>> from debian.deb822 import Deb822
>>> filename = '/var/lib/apt/lists/deb.debian.org_debian_dists_sid_InRelease'
>>> with open(filename) as fh:
... rel = Deb822(fh)
>>> print('Origin: {Origin}\nCodename: {Codename}\nDate: {Date}'.format_map(
... rel))
Origin: Debian
Codename: sid
Date: Sat, 07 Apr 2018 14:41:12 UTC
>>> print(list(rel.keys()))
['Origin', 'Label', 'Suite', 'Codename', 'Changelogs', 'Date',
'Valid-Until', 'Acquire-By-Hash', 'Architectures', 'Components',
'Description', 'MD5Sum', 'SHA256']
In the above, the MD5Sum and SHA256 fields are just a very long string. If
instead the Release
class is used, these fields are interpreted and
can be addressed:
>>> from debian.deb822 import Release
>>> filename = '/var/lib/apt/lists/deb.debian.org_debian_dists_sid_InRelease'
>>> with open(filename) as fh:
... rel = Release(fh)
>>> wanted = 'main/binary-amd64/Packages'
>>> [(l['sha256'], l['size']) for l in rel['SHA256'] if l['name'] == wanted]
[('c0f7aa0b92ebd6971c0b64f93f52a8b2e15b0b818413ca13438c50eb82586665', '45314424')]
Iteration¶
All classes use the iter_paragraphs()
class method to easily
iterate through each paragraph in a file that contains multiple entries
(e.g. a Packages.gz file).
For example:
>>> with open('/mirror/debian/dists/sid/main/binary-i386/Sources') as f:
... for src in Sources.iter_paragraphs(f):
... print(src['Package'], src['Version'])
The iter_paragraphs methods can use python-apt if available to parse
the data, since it significantly boosts performance.
If python-apt is not present and the
file is a compressed file, it must first be decompressed manually. Note that
python-apt should not be used on debian/control files since python-apt is
designed to be strict and fast while the syntax of debian/control is a
superset of what python-apt is designed to parse.
This function is overridden to force use of the
python-apt parser using use_apt_pkg in the iter_paragraphs()
and iter_paragraphs()
functions.
Sample usage¶
Manipulating a .dsc file:
from debian import deb822
with open('foo_1.1.dsc') as f:
d = deb822.Dsc(f)
source = d['Source']
version = d['Version']
for f in d['Files']:
print('Name:', f['name'])
print('Size:', f['size'])
print('MD5sum:', f['md5sum'])
# If we like, we can change fields
d['Standards-Version'] = '3.7.2'
# And then dump the new contents
with open('foo_1.1.dsc2', 'w') as new_dsc:
d.dump(new_dsc)
(TODO: Improve, expand)
Deb822 Classes¶
- class debian.deb822.BuildInfo(*args: Any, **kwargs: Any)¶
Bases:
_gpg_multivalued
,_PkgRelationMixin
,_VersionAccessorMixin
Representation of a .buildinfo (build environment description) file
This class is a thin wrapper around the transparent GPG handling of
_gpg_multivalued
, the field parsing of_PkgRelationMixin
, and the format parsing ofDeb822
.Note that the ‘relations’ structure returned by the relations method is identical to that produced by other classes in this module. Consequently, existing code to consume this structure can be used here, although it means that there are redundant lists and tuples within the structure.
Example:
>>> from debian.deb822 import BuildInfo >>> filename = 'package.buildinfo' >>> with open(filename) as fh: ... info = BuildInfo(fh) >>> print(info.get_environment()) {'DEB_BUILD_OPTIONS': 'parallel=4', 'LANG': 'en_AU.UTF-8', 'LC_ALL': 'C.UTF-8', 'LC_TIME': 'en_GB.UTF-8', 'LD_LIBRARY_PATH': '/usr/lib/libeatmydata', 'SOURCE_DATE_EPOCH': '1601784586'} >>> installed = info.relations['installed-build-depends'] >>> for dep in installed: ... print("Installed %s/%s" % (dep[0]['name'], dep[0]['version'][1])) Installed autoconf/2.69-11.1 Installed automake/1:1.16.2-4 Installed autopoint/0.19.8.1-10 Installed autotools-dev/20180224.1 ... etc ... >>> changelog = info.get_changelog() >>> print(changelog.author) 'xyz Build Daemon (xyz-01) <buildd_xyz-01@buildd.debian.org>' >>> print(changelog[0].changes()) ['', ' * Binary-only non-maintainer upload for amd64; no source changes.', ' * Add Python 3.9 as supported version', '']
- class _EnvParserState¶
Bases:
object
- IGNORE_WHITESPACE = 0¶
- START_VALUE_QUOTE = 2¶
- VALUE = 3¶
- VALUE_BACKSLASH_ESCAPE = 4¶
- VAR_NAME = 1¶
- static _env_deserialise(serialised: str) Generator[Tuple[str, str], None, None] ¶
extract the environment variables and values from the text
- Format is:
VAR_NAME=”value”
with ignorable whitespace around the construct (and separating each item). Quote characters within the value are backslash escaped.
When producing the buildinfo file, dpkg only includes specifically allowed environment variables and thus there is no defined quoting rules for the variable names.
The format is described by deb-buildinfo(5) and implemented in dpkg source scripts/dpkg-genbuildinfo.pl:cleansed_environment(), while the environment variables that are included in the output are listed in dpkg source scripts/Dpkg/Build/Info.pm
- _get_array_value(field: str) List[str] | None ¶
- _multivalued_fields: Dict[str, List[str]] = {'checksums-md5': ['md5', 'size', 'name'], 'checksums-sha1': ['sha1', 'size', 'name'], 'checksums-sha256': ['sha256', 'size', 'name'], 'checksums-sha512': ['sha512', 'size', 'name']}¶
- _relationship_fields: List[str] = ['installed-build-depends']¶
- get_architecture() List[str] | None ¶
- get_binary() List[str] | None ¶
- get_build_date() datetime ¶
- get_changelog() Changelog | None ¶
Return the changelog entry from the buildinfo (for binNMUs)
If no “Binary-Only-Changes” field is present in the buildinfo file then None is returned.
- get_environment() Dict[str, str] ¶
Return the build environment that was recorded
The environment is returned as a dict in the style of os.environ. The backslash quoting of values described in deb-buildinfo(5) is removed.
- get_source() Tuple[str, str] ¶
- is_build_arch_all() bool ¶
- is_build_arch_any() bool ¶
- is_build_source() bool ¶
- class debian.deb822.Changes(*args: Any, **kwargs: Any)¶
Bases:
_gpg_multivalued
,_VersionAccessorMixin
Representation of a .changes (archive changes) file
This class is a thin wrapper around the transparent GPG handling of
_gpg_multivalued
and the parsing ofDeb822
.- _multivalued_fields: Dict[str, List[str]] = {'checksums-sha1': ['sha1', 'size', 'name'], 'checksums-sha256': ['sha256', 'size', 'name'], 'checksums-sha512': ['sha512', 'size', 'name'], 'files': ['md5sum', 'size', 'section', 'priority', 'name'], 'package-list': ['package', 'package-type', 'section', 'priority', 'key-value-list']}¶
- get_pool_path() str ¶
Return the path in the pool where the files would be installed
- class debian.deb822.Deb822(sequence: bytes | str | IO[str] | IO[bytes] | Iterable[str] | Iterable[bytes] | Mapping[str, Any] | None = None, fields: List[str] | None = None, _parsed: Deb822 | TagSectionWrapper | None = None, encoding: str = 'utf-8', strict: Dict[str, bool] | None = None)¶
Bases:
Deb822Dict
Generic Deb822 data
- Parameters:
sequence – a string, or any object that returns a line of input each time, normally a file. Alternately, sequence can be a dict that contains the initial key-value pairs. When python-apt is present, sequence can also be a compressed object, for example a file object associated to something.gz.
fields – if given, it is interpreted as a list of fields that should be parsed (the rest will be discarded).
_parsed – internal parameter.
encoding – When parsing strings, interpret them in this encoding. (All values are given back as unicode objects, so an encoding is necessary in order to properly interpret the strings.)
strict – Dict controlling the strictness of the internal parser to permit tuning of its behaviour between “generous in what it accepts” and “strict conformance”. Known keys are described below.
Internal parser tuning
whitespace-separates-paragraphs: (default: True) Blank lines between paragraphs should not have any whitespace in them at all. However:
Policy §5.1 permits debian/control in source packages to separate packages with lines containing whitespace to allow human edited files to have stray whitespace. Failing to honour this breaks tools such as wrap-and-sort (see, for example, Debian Bug 715558).
apt_pkg.TagFile accepts whitespace-only lines within the Description field; strictly matching the behaviour of apt’s Deb822 parser requires setting this key to False (as is done by default for
Sources
andPackages
. (see, for example, Debian Bug 913274).
Note that these tuning parameter are only for the parser that is internal to Deb822 and do not apply to python-apt’s apt_pkg.TagFile parser which would normally be used for Packages and Sources files.
- _dump_fd_b(fd: IO[bytes], encoding: str) None ¶
- _dump_fd_t(fd: IO[str]) None ¶
- _dump_format() Generator[str, None, None] ¶
- _dump_str() str ¶
- _explicit_source_re = re.compile('(?P<source>[^ ]+)( \\((?P<version>.+)\\))?')¶
- classmethod _gpg_stripped_paragraph(sequence: Iterator[bytes], strict: Dict[str, bool] | None = None) List[bytes] ¶
- _gpgre = re.compile(b'^-----(?P<action>BEGIN|END) PGP (?P<what>[^-]+)-----[\\r\\t ]*$')¶
- _internal_parser(sequence: bytes | str | IO[str] | IO[bytes] | Iterable[str] | Iterable[bytes], fields: List[str] | None = None, strict: Dict[str, bool] | None = None) None ¶
- _key_part = '^(?P<key>[^: \\t\\n\\r\\f\\v]+)\\s*:\\s*'¶
- _merge_fields(s1: str, s2: str) str ¶
- _new_field_re = re.compile('^(?P<key>[^: \\t\\n\\r\\f\\v]+)\\s*:\\s*(?P<data>(?:\\S+(\\s+\\S+)*)?)\\s*$')¶
- static _skip_useless_lines(sequence: IO[str] | IO[bytes] | Iterable[str] | Iterable[bytes]) Iterator[bytes] ¶
Yields only lines that do not begin with ‘#’.
Also skips any blank lines at the beginning of the input.
- static _split_gpg_and_payload(sequence: Iterator[bytes], strict: Dict[str, bool] | None = None) Tuple[List[bytes], List[bytes], List[bytes]] ¶
- dump() str ¶
- dump(fd, encoding=None, text_mode=False)
- dump(fd, encoding=None, text_mode=True)
- dump(fd=None, encoding=None, text_mode=False)
- dump(fd=None, encoding=None, text_mode=False)
Dump the contents in the original format
- Parameters:
fd – file-like object to which the data should be written (see notes below)
encoding – str, optional (Defaults to object default). Encoding to use when writing out the data.
text_mode – bool, optional (Defaults to
False
). Encoding should be undertaken by this function rather than by the caller.
If fd is None, returns a unicode object. Otherwise, fd is assumed to be a file-like object, and this method will write the data to it instead of returning a unicode object.
If fd is not none and text_mode is False, the data will be encoded to a byte string before writing to the file. The encoding used is chosen via the encoding parameter; None means to use the encoding the object was initialized with (utf-8 by default). This will raise UnicodeEncodeError if the encoding can’t support all the characters in the Deb822Dict values.
- get_as_string(key: str) str ¶
Return the self[key] as a string (or unicode)
The default implementation just returns unicode(self[key]); however, this can be overridden in subclasses (e.g. _multivalued) that can take special values.
- get_gpg_info(keyrings: Iterable[str] | None = None) GpgInfo ¶
Return a GpgInfo object with GPG signature information
This method will raise ValueError if the signature is not available (e.g. the original text cannot be found).
- Parameters:
keyrings – list of keyrings to use (see GpgInfo.from_sequence)
- static is_multi_line(s: str) bool ¶
- static is_single_line(s: str) bool ¶
- classmethod iter_paragraphs(sequence: InputDataType, fields: List[str] | None = None, use_apt_pkg: bool = False, shared_storage: bool = False, encoding: str = 'utf-8', strict: Dict[str, bool] | None = None) Iterator[T_Deb822] ¶
Generator that yields a Deb822 object for each paragraph in sequence.
- Parameters:
sequence – same as in __init__.
fields – likewise.
use_apt_pkg – if sequence is a file, apt_pkg can be used if available to parse the file, since it’s much much faster. Set this parameter to True to enable use of apt_pkg. Note that the TagFile parser from apt_pkg is a much stricter parser of the Deb822 format, particularly with regards whitespace between paragraphs and comments within paragraphs. If these features are required (for example in debian/control files), ensure that this parameter is set to False.
shared_storage – not used, here for historical reasons. Deb822 objects never use shared storage anymore.
encoding – Interpret the paragraphs in this encoding. (All values are given back as unicode objects, so an encoding is necessary in order to properly interpret the strings.)
strict – dict of settings to tune the internal parser if that is being used. See the documentation for
Deb822
for details.
- merge_fields(key: str, d1: Mapping[str, str], d2: Mapping[str, str] | None = None) str | None ¶
- static split_gpg_and_payload(sequence: Iterator[bytes] | Iterator[str], strict: Dict[str, bool] | None = None) Tuple[List[bytes], List[bytes], List[bytes]] ¶
Return a (gpg_pre, payload, gpg_post) tuple
Each element of the returned tuple is a list of lines (with trailing whitespace stripped).
- Parameters:
sequence – iterable. An iterable that yields lines of data (str, unicode, bytes) to be parsed, possibly including a GPG in-line signature.
strict – dict, optional. Control over the strictness of the parser. See the
Deb822
class documentation for details.
- validate_input(key: str, value: str) None ¶
Raise ValueError if value is not a valid value for key
Subclasses that do interesting things for different keys may wish to override this method.
- class debian.deb822.Deb822Dict(_dict: Mapping[str, Any] | Iterable[Tuple[str, str]] | None = None, _parsed: Deb822 | TagSectionWrapper | None = None, _fields: List[str] | None = None, encoding: str = 'utf-8')¶
Bases:
MutableMapping
A dictionary-like object suitable for storing RFC822-like data.
- Deb822Dict behaves like a normal dict, except:
key lookup is case-insensitive
key order is preserved
if initialized with a _parsed parameter, it will pull values from that dictionary-like object as needed (rather than making a copy). The _parsed dict is expected to be able to handle case-insensitive keys.
If _parsed is not None, an optional _fields parameter specifies which keys in the _parsed dictionary are exposed.
- copy() T_Deb822Dict ¶
- order_after(field: str, reference_field: str) None ¶
Re-order the given field so appears directly before the reference field in the paragraph
The reference field must be present.
- order_before(field: str, reference_field: str) None ¶
Re-order the given field so appears directly after the reference field in the paragraph
The reference field must be present.
- order_first(field: str) None ¶
Re-order the given field so it is “first” in the paragraph
- order_last(field: str) None ¶
Re-order the given field so it is “last” in the paragraph
- sort_fields(key: Callable[[str], Any] | None = None) None ¶
Re-order all fields
- Parameters:
key – Provide a key function (same semantics as for sorted). Keep in mind that Deb822 preserve the cases for field names - in generally, callers are recommended to use “lower()” to normalize the case.
- class debian.deb822.Dsc(*args: Any, **kwargs: Any)¶
Bases:
_gpg_multivalued
,_VersionAccessorMixin
Representation of a .dsc (Debian Source Control) file
This class is a thin wrapper around the transparent GPG handling of
_gpg_multivalued
and the parsing ofDeb822
.- _multivalued_fields: Dict[str, List[str]] = {'checksums-sha1': ['sha1', 'size', 'name'], 'checksums-sha256': ['sha256', 'size', 'name'], 'checksums-sha512': ['sha512', 'size', 'name'], 'files': ['md5sum', 'size', 'name'], 'package-list': ['package', 'package-type', 'section', 'priority', '_other']}¶
- exception debian.deb822.Error¶
Bases:
Exception
Base class for custom exceptions in this module.
- class debian.deb822.GpgInfo(*args: Any, **kwargs: Any)¶
Bases:
dict
A wrapper around gnupg parsable output obtained via –status-fd
This class is really a dictionary containing parsed output from gnupg plus some methods to make sense of the data. Keys are keywords and values are arguments suitably split. See /usr/share/doc/gnupg/DETAILS.gz
- static _get_full_bytes(sequence: Iterable[bytes]) bytes ¶
Return a byte string from a sequence of lines of bytes.
This method detects if the sequence’s lines are newline-terminated, and constructs the byte string appropriately.
- classmethod from_file(target: str, *args: Any, **kwargs: Any) GpgInfo ¶
Create a new GpgInfo object from the given file.
See GpgInfo.from_sequence.
- classmethod from_output(out: str | List[str], err: str | List[str] | None = None) GpgInfo ¶
Create a GpgInfo object based on the gpg or gpgv output
Create a new GpgInfo object from gpg(v) –status-fd output (out) and optionally collect stderr as well (err).
Both out and err can be lines in newline-terminated sequence or regular strings.
- classmethod from_sequence(sequence: bytes | Iterable[bytes], keyrings: Iterable[str] | None = None, executable: Iterable[str] | None = None) GpgInfo ¶
Create a new GpgInfo object from the given sequence.
- Parameters:
sequence – sequence of lines of bytes or a single byte string
keyrings – list of keyrings to use (default: [‘/usr/share/keyrings/debian-keyring.gpg’])
executable – list of args for subprocess.Popen, the first element being the gpgv executable (default: [‘/usr/bin/gpgv’])
- uid() None ¶
Return the primary ID of the signee key, None is not available
- uidkeys = ('GOODSIG', 'EXPSIG', 'EXPKEYSIG', 'REVKEYSIG', 'BADSIG')¶
- valid() bool ¶
Is the signature valid?
- class debian.deb822.Packages(*args: Any, **kwargs: Any)¶
Bases:
Deb822
,_PkgRelationMixin
,_VersionAccessorMixin
Represent an APT binary package list
This class is a thin wrapper around the parsing of
Deb822
, using the field parsing of_PkgRelationMixin
.- _relationship_fields: List[str] = ['depends', 'pre-depends', 'recommends', 'suggests', 'breaks', 'conflicts', 'provides', 'replaces', 'enhances', 'built-using']¶
- classmethod iter_paragraphs(sequence: bytes | str | IO[str] | IO[bytes] | Iterable[str] | Iterable[bytes], fields: List[str] | None = None, use_apt_pkg: bool = True, shared_storage: bool = False, encoding: str = 'utf-8', strict: Dict[str, bool] | None = None) Iterator[Packages] ¶
Generator that yields a Deb822 object for each paragraph in Packages.
Note that this overloaded form of the generator uses apt_pkg (a strict but fast parser) by default.
See the
iter_paragraphs()
function for details.
- property source: str | None¶
source package that generates the binary package
If the source package and source package version are the same as the binary package, an explicit “Source” field will not be within the paragraph.
- class debian.deb822.PdiffIndex(*args: Any, **kwargs: Any)¶
Bases:
_multivalued
Representation of a foo.diff/Index file from a Debian mirror
This class is a thin wrapper around the transparent GPG handling of
_gpg_multivalued
and the parsing ofDeb822
.- property _fixed_field_lengths: Dict[str, Dict[str, int]]¶
- _get_size_field_length(key: str) int ¶
- _multivalued_fields: Dict[str, List[str]] = {'sha1-current': ['SHA1', 'size'], 'sha1-download': ['SHA1', 'size', 'filename'], 'sha1-history': ['SHA1', 'size', 'date'], 'sha1-patches': ['SHA1', 'size', 'date'], 'sha256-current': ['SHA256', 'size'], 'sha256-download': ['SHA256', 'size', 'filename'], 'sha256-history': ['SHA256', 'size', 'date'], 'sha256-patches': ['SHA256', 'size', 'date'], 'x-unmerged-sha1-download': ['SHA1', 'size', 'filename'], 'x-unmerged-sha1-history': ['SHA1', 'size', 'date'], 'x-unmerged-sha1-patches': ['SHA1', 'size', 'date'], 'x-unmerged-sha256-download': ['SHA256', 'size', 'filename'], 'x-unmerged-sha256-history': ['SHA256', 'size', 'date'], 'x-unmerged-sha256-patches': ['SHA256', 'size', 'date']}¶
- class debian.deb822.PkgRelation¶
Bases:
object
Inter-package relationships
Structured representation of the relationships of a package to another, i.e. of what can appear in a Deb882 field like Depends, Recommends, Suggests, … (see Debian Policy 7.1).
- class ArchRestriction(enabled, arch)¶
Bases:
tuple
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('enabled', 'arch')¶
- classmethod _make(iterable)¶
Make a new ArchRestriction object from a sequence or iterable
- _replace(**kwds)¶
Return a new ArchRestriction object replacing specified fields with new values
- arch¶
Alias for field number 1
- enabled¶
Alias for field number 0
- class BuildRestriction(enabled, profile)¶
Bases:
tuple
- _asdict()¶
Return a new dict which maps field names to their values.
- _field_defaults = {}¶
- _fields = ('enabled', 'profile')¶
- classmethod _make(iterable)¶
Make a new BuildRestriction object from a sequence or iterable
- _replace(**kwds)¶
Return a new BuildRestriction object replacing specified fields with new values
- enabled¶
Alias for field number 0
- profile¶
Alias for field number 1
- __blank_sep_RE = re.compile('\\s+')¶
- __comma_sep_RE = re.compile('\\s*,\\s*')¶
- __dep_RE = re.compile('^\\s*(?P<name>[a-zA-Z0-9][a-zA-Z0-9.+\\-]*)(:(?P<archqual>([a-zA-Z0-9][a-zA-Z0-9-]*)))?(\\s*\\(\\s*(?P<relop>[>=<]+)\\s*(?P<version>[0-9a-zA-Z:\\-+~.]+)\\s*\\))?(\\s*\\[(?P<archs>[\\s!\\w\\-]+)\\])?\)¶
- __pipe_sep_RE = re.compile('\\s*\\|\\s*')¶
- __restriction_RE = re.compile('(?P<enabled>\\!)?(?P<profile>[^\\s]+)')¶
- __restriction_sep_RE = re.compile('>\\s*<')¶
- classmethod parse_relations(raw: str) List[List[PkgRelation.ParsedRelation]] ¶
Parse a package relationship string (i.e. the value of a field like Depends, Recommends, Build-Depends …)
- static str(rels: List[List[PkgRelation.ParsedRelation]]) builtins.str ¶
Format to string structured inter-package relationships
Perform the inverse operation of parse_relations, returning a string suitable to be written in a package stanza.
- class debian.deb822.Release(*args: Any, **kwargs: Any)¶
Bases:
_multivalued
Represents a Release file
Set the size_field_behavior attribute to “dak” to make the size field length only as long as the longest actual value. The default, “apt-ftparchive” makes the field 16 characters long regardless.
This class is a thin wrapper around the parsing of
Deb822
.- __size_field_behavior = 'apt-ftparchive'¶
- property _fixed_field_lengths: Dict[str, Dict[str, int]]¶
- _get_size_field_length(key: str) int ¶
- _multivalued_fields: Dict[str, List[str]] = {'md5sum': ['md5sum', 'size', 'name'], 'sha1': ['sha1', 'size', 'name'], 'sha256': ['sha256', 'size', 'name'], 'sha512': ['sha512', 'size', 'name']}¶
- set_size_field_behavior(value: str) None ¶
- property size_field_behavior¶
- class debian.deb822.Removals(*args: Any, **kwargs: Any)¶
Bases:
Deb822
Represent an ftp-master removals.822 file
Removal of packages from the archive are recorded by ftp-masters. See https://ftp-master.debian.org/#removed
Note: this API is experimental and backwards-incompatible changes might be required in the future. Please use it and help us improve it!
- __binaries_line_re = re.compile('\\s*(?P<package>.+?)_(?P<version>[^\\s]+)\\s+\\[(?P<archs>.+)\\]')¶
- __sources_line_re = re.compile('\\s*(?P<package>.+?)_(?P<version>[^\\s]+)\\s*')¶
- property also_bugs: List[int]¶
list of bug numbers in the package closed by the removal
The bug numbers are returned as integers.
Removal of a package implicitly also closes all bugs associated with the package.
- property also_wnpp: List[int]¶
list of WNPP bug numbers closed by the removal
The bug numbers are returned as integers.
- property binaries: List[Dict[str, str | Iterable[str]]]¶
list of binary packages that were removed
A list of dicts is returned, each dict has the form:
{ 'package': 'some-package-name', 'version': '1.2.3-1', 'architectures': set(['i386', 'amd64']) }
- property bug: List[int]¶
list of bug numbers that had requested the package removal
The bug numbers are returned as integers.
Note: there is normally only one entry in this list but there may be more than one.
- property date: datetime¶
a datetime object for the removal action
- property sources: List[Dict[str, str]]¶
list of source packages that were removed
A list of dicts is returned, each dict has the form:
{ 'source': 'some-package-name', 'version': '1.2.3-1' }
Note: There may be no source packages removed at all if the removal is only of a binary package. An empty list is returned in that case.
- class debian.deb822.RestrictedField(name: str, from_str: Callable[[str], Any] | None = None, to_str: Callable[[Any], str | None] | None = None, allow_none: bool | None = True)¶
Bases:
RestrictedField
Placeholder for a property providing access to a restricted field.
Use this as an attribute when defining a subclass of RestrictedWrapper. It will be replaced with a property. See the RestrictedWrapper documentation for an example.
- exception debian.deb822.RestrictedFieldError¶
Bases:
Error
Raised when modifying the raw value of a field is not allowed.
- class debian.deb822.Sources(*args: Any, **kwargs: Any)¶
Bases:
Dsc
,_PkgRelationMixin
Represent an APT source package list
This class is a thin wrapper around the parsing of
Deb822
, using the field parsing of_PkgRelationMixin
.- _relationship_fields: List[str] = ['build-depends', 'build-depends-indep', 'build-depends-arch', 'build-conflicts', 'build-conflicts-indep', 'build-conflicts-arch', 'binary']¶
- classmethod iter_paragraphs(sequence: bytes | str | IO[str] | IO[bytes] | Iterable[str] | Iterable[bytes], fields: List[str] | None = None, use_apt_pkg: bool = True, shared_storage: bool = False, encoding: str = 'utf-8', strict: Dict[str, bool] | None = None) Iterator[Sources] ¶
Generator that yields a Deb822 object for each paragraph in Sources.
Note that this overloaded form of the generator uses apt_pkg (a strict but fast parser) by default.
See the
iter_paragraphs()
function for details.
- class debian.deb822.TagSectionWrapper(section: apt_pkg.TagSection[bytes], decoder: _AutoDecoder | None = None)¶
Bases:
Mapping
Wrap a TagSection object, using its find_raw method to get field values
This allows us to pick which whitespace to strip off the beginning and end of the data, so we don’t lose leading newlines.
- class debian.deb822._AutoDecoder(encoding: str | None = None)¶
Bases:
object
- decode(value: str | bytes) str ¶
If value is not already Unicode, decode it intelligently.
- decode_bytes(value: bytes) str ¶
- class debian.deb822._PkgRelationMixin(*args: Any, **kwargs: Any)¶
Bases:
object
Package relationship mixin
Inheriting from this mixin you can extend a
Deb822
object with attributes letting you access inter-package relationship in a structured way, rather than as strings. For example, while you can usually usepkg['depends']
to obtain the Depends string of package pkg, mixing in with this class you gain pkg.depends to access Depends as a Pkgrel instanceTo use, subclass _PkgRelationMixin from a class with a _relationship_fields attribute. It should be a list of field names for which structured access is desired; for each of them a method wild be added to the inherited class. The method name will be the lowercase version of field name; ‘-’ will be mangled as ‘_’. The method would return relationships in the same format of the PkgRelation’ relations property.
See Packages and Sources as examples.
- _relationship_fields: List[str] = []¶
- property relations: _lowercase_dict¶
Return a dictionary of inter-package relationships among the current and other packages.
Dictionary keys depend on the package kind. Binary packages have keys like ‘depends’, ‘recommends’, … while source packages have keys like ‘build-depends’, ‘build-depends-indep’ and so on. See the Debian policy for the comprehensive field list.
Dictionary values are package relationships returned as lists of lists of dictionaries (see below for some examples).
The encoding of package relationships is as follows:
the top-level lists corresponds to the comma-separated list of
Deb822
, their components form a conjunction, i.e. they have to be AND-ed togetherthe inner lists corresponds to the pipe-separated list of
Deb822
, their components form a disjunction, i.e. they have to be OR-ed togethermember of the inner lists are dictionaries with the following keys:
name
package (or virtual package) name
version
A pair <operator, version> if the relationship is versioned, None otherwise. operator is one of
<<
,<=
,=
,>=
,>>
; version is the given version as a string.arch
A list of pairs <enabled, arch> if the relationship is architecture specific, None otherwise. Enabled is a boolean (
False
if the architecture is negated with!
,True
otherwise), arch the Debian architecture name as a string.restrictions
A list of lists of tuples <enabled, profile> if there is a restriction formula defined,
None
otherwise. Each list of tuples represents a restriction list while each tuple represents an individual term within the restriction list. Enabled is a boolean (False
if the restriction is negated with!
,True
otherwise). The profile is the name of the build restriction. https://wiki.debian.org/BuildProfileSpec
The arch and restrictions tuples are available as named tuples so elements are available as term[0] or alternatively as term.enabled (and so forth).
Examples:
"emacs | emacsen, make, debianutils (>= 1.7)"
becomes:[ [ {'name': 'emacs'}, {'name': 'emacsen'} ], [ {'name': 'make'} ], [ {'name': 'debianutils', 'version': ('>=', '1.7')} ] ]
"tcl8.4-dev, procps [!hurd-i386]"
becomes:[ [ {'name': 'tcl8.4-dev'} ], [ {'name': 'procps', 'arch': (false, 'hurd-i386')} ] ]
"texlive <!cross>"
becomes:[ [ {'name': 'texlive', 'restriction': [[(false, 'cross')]]} ] ]
- class debian.deb822._VersionAccessorMixin¶
Bases:
object
Give access to Version keys as debian_support.Version objects.
- set_version(version: _HasVersionFieldProtocol) None ¶
- debian.deb822._cached_strI(v: str) _CaseInsensitiveString ¶
- class debian.deb822._gpg_multivalued(*args: Any, **kwargs: Any)¶
Bases:
_multivalued
A _multivalued class that can support gpg signed objects
This class’s feature is that it stores the raw text before parsing so that gpg can verify the signature. Use it just like you would use the _multivalued class.
This class only stores raw text if it is given a raw string, or if it detects a gpg signature when given a file or sequence of lines (see Deb822.split_gpg_and_payload for details).
- static _bytes(s: bytes | str, encoding: str) bytes ¶
Converts s to bytes if necessary, using encoding.
If s is already bytes type, returns it directly.
- debian.deb822._has_fileno(f: Any) bool ¶
test that a file-like object is really a filehandle
Only filehandles can be given to apt_pkg.TagFile.
- class debian.deb822._lowercase_dict¶
Bases:
dict
Dictionary wrapper which lowercase keys upon lookup.
- class debian.deb822._multivalued(*args: Any, **kwargs: Any)¶
Bases:
Deb822
A class with (R/W) support for multivalued fields.
To use, create a subclass with a _multivalued_fields attribute. It should be a dictionary with lower-case keys, with lists of human-readable identifiers of the fields as the values. Please see
Dsc
,Changes
, andPdiffIndex
as examples.- _multivalued_fields: Dict[str, List[str]] = {}¶
- get_as_string(key: str) str ¶
Return the self[key] as a string (or unicode)
The default implementation just returns unicode(self[key]); however, this can be overridden in subclasses (e.g. _multivalued) that can take special values.
- validate_input(key: str, value: List[Dict[str, str]] | str) None ¶
Raise ValueError if value is not a valid value for key
Subclasses that do interesting things for different keys may wish to override this method.