debian_inspector.deb822 module
A parser for deb822 data files as used by Debian control and copyright files, and several related formats.
For details, see: - https://www.debian.org/doc/debian-policy/ch-controlfields - https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ - https://datatracker.ietf.org/doc/rfc2822/
Why yet another Debian 822 parser?
This module exists because no existing parser module supports some must-have features. Neither the standard email module nor the python-debian library, nor other existing libraries can do these:
track the start and end line numbers of each field within each paragraph: we need line numbers to trace license detection in copyright files.
lenient parsing recovering from common errors: this helps handling a larger variety of copyright files even if they are not exactly well-formed
- class debian_inspector.deb822.Deb822Field(name=None, lines=_Nothing.NOTHING)
Bases:
object
A Deb822Field field with a name and a list of NumberedLines.
- add_continuation_line(line)
- property end_line
- classmethod from_line(line)
Parse a
line
Line object as a “Name: value” declaration line and return a Deb822Field object. Return None if this is not a deb822 field declaration line.
- lines
- name
- rstrip()
Remove the last lines of these lines they are all blank or empty. Return self.
- property start_line
- property text
- to_dict()
- class debian_inspector.deb822.NumberedLine(number, value)
Bases:
object
A text line that tracks its absolute line number. Numbers start at 1.
- is_blank()
- is_field_continuation()
Return True if this is a field declaration line.
For example:
>>> NumberedLine(1, 'foo').is_field_continuation() False >>> NumberedLine(1, '').is_field_continuation() False >>> NumberedLine(1, ' ').is_field_continuation() False >>> NumberedLine(1, ' ').is_field_continuation() False >>> NumberedLine(1, ' foo').is_field_continuation() True >>> NumberedLine(1, ' .').is_field_continuation() True >>> NumberedLine(1, ' .').is_field_continuation() True >>> NumberedLine(1, ' "').is_field_continuation() True >>> NumberedLine(1, ' (').is_field_continuation() True
- is_field_declaration()
Return True if this is a continuation line.
For example:
>>> NumberedLine(1, 'foo').is_field_declaration() False >>> NumberedLine(1, '').is_field_declaration() False >>> NumberedLine(1, ' ').is_field_declaration() False >>> NumberedLine(1, ' Some: bar ').is_field_declaration() False >>> NumberedLine(1, 'Some:').is_field_declaration() True >>> NumberedLine(1, 'foo: bar').is_field_declaration() True >>> NumberedLine(1, 'foo:bar').is_field_declaration() True >>> NumberedLine(1, 'foo: ').is_field_declaration() True >>> NumberedLine(1, ' .').is_field_declaration() False >>> NumberedLine(1, ' .').is_field_declaration() False
- classmethod lines_from_text(text)
Return a list of Line from a
text
- number
- to_dict()
- value
- debian_inspector.deb822.clean_fields(fields)
Clean and return a
fields
list of Deb822Field.
- debian_inspector.deb822.get_paragraphs_as_field_groups(text)
Yield lists of Deb822Field for each paragraph in a
text
each separated by one or more empty lines. Raise Exceptions on errors.
- debian_inspector.deb822.get_paragraphs_as_field_groups_from_file(location)
Yield lists of Deb822Field for each paragraph in a control file at
location
. Raise Exceptions on errors.
- debian_inspector.deb822.get_paragraphs_as_field_groups_from_lines(numbered_lines)
Yield lists of Deb822Field for each paragraph in a
numbered_lines
list of NumberedLine. Raise Exceptions on errors.
- debian_inspector.deb822.is_field_continuation(string, pos=0, endpos=2147483647)
Matches zero or more characters at the beginning of the string.
- debian_inspector.deb822.is_field_declaration(string, pos=0, endpos=2147483647)
Matches zero or more characters at the beginning of the string.