debian._deb822_repro._util module

class debian._deb822_repro._util.BufferingIterator(stream: Iterable[T])

Bases: Iterator[T], Generic[T]

_fill_buffer(number: int) bool
consume_many(count: int) List[T]
peek() T | None
peek_at(tokens_ahead: int) T | None
peek_buffer() List[T]
peek_find(predicate: Callable[[T], bool], limit: int | None = None) int | None
peek_many(number: int) List[T]
takewhile(predicate: Callable[[T], bool]) Iterable[T]

Variant of itertools.takewhile except it does not discard the first non-matching token

debian._deb822_repro._util.combine_into_replacement(source_class: Type[TE], replacement_class: Type[R], *, constructor: Callable[[List[TE]], R] | None = None) _combine_parts_ret_type[TE, R]

Combines runs of one type into another type

This is primarily useful for transforming tokens (e.g, Comment tokens) into the relevant element (such as the Comment element).

debian._deb822_repro._util.len_check_iterator(content: str, stream: Iterable[TE], content_len: int | None = None) Iterable[TE]

Flatten a parser’s output into tokens and verify it covers the entire line/text

debian._deb822_repro._util.print_ast(ast_tree: Iterable[TokenOrElement] | 'Deb822Element', *, end_marker_after: int | None = 5, output_function: Callable[[str], None] | None = None) None

Debugging aid, which can dump a Deb822Element or a list of tokens/elements

Parameters:
  • ast_tree – Either a Deb822Element or an iterable Deb822Token/Deb822Element entries (both types may be mixed in the same iterable, which enable it to dump the ast tree at different stages of parse_deb822_file method)

  • end_marker_after – The dump will add “end of element” markers if a given element spans at least this many tokens/elements. Can be disabled with by passing None as value. Use 0 for unconditionally marking all elements (note that tokens never get an “end of element” marker as they are not an elements).

  • output_function – Callable that receives a single str argument and is responsible for “displaying” that line. The callable may be invoked multiple times (one per line of output). Defaults to logging.info if omitted.