fitzzftw.patch.parser.PatchParser¶
- class PatchParser[source]¶
Bases:
objectHandles the parsing of the diff or patch file content.
This class is responsible for reading the file, handling potential encoding issues, and iterating over the hunks and files defined in the patch.
Public Methods:
__init__()Initializes the PatchParser instance.
__repr__()Return repr(self).
create_line(raw_line)Factory method that maps a raw patch line to its specialized class.
get_lines(stream)A generator that transforms a stream of raw strings into PatchLine objects.
iter_files(stream)Iterates over all file-level patches within the provided stream.
- static create_line(raw_line)[source]¶
Factory method that maps a raw patch line to its specialized class.
This method analyzes the line prefix to determine the semantic role of the line (Header, Hunk, or Data). It is designed to be the central entry point for line instantiation to ensure consistent parsing and high testability.
- classmethod get_lines(stream)[source]¶
A generator that transforms a stream of raw strings into PatchLine objects.
- iter_files(stream)[source]¶
Iterates over all file-level patches within the provided stream.
This method acts as a high-speed state machine, assembling objects directly from raw strings using an efficient if-elif-else sieve.
- Parameters:
stream (Iterable[str]) – An iterable source of raw patch strings.
- Raises:
FtwPatchError – If the diff sequence is invalid or corrupted.
- Returns:
A generator yielding complete DiffCodeFile objects.
- Return type:
Generator[DiffCodeFile, None, None]