Base filter class to be used with libgit2 filters. Inherit from this class and override the `check()`, `write()` and `close()` methods to define a filter which can then be registered via `pygit2.filter_register()`. A new Filter instance will be instantiated for each stream whi
| 40 | |
| 41 | |
| 42 | class Filter: |
| 43 | """ |
| 44 | Base filter class to be used with libgit2 filters. |
| 45 | |
| 46 | Inherit from this class and override the `check()`, `write()` and `close()` |
| 47 | methods to define a filter which can then be registered via |
| 48 | `pygit2.filter_register()`. |
| 49 | |
| 50 | A new Filter instance will be instantiated for each stream which needs to |
| 51 | be filtered. For each stream, filter methods will be called in this order: |
| 52 | |
| 53 | - `check()` |
| 54 | - `write()` (may be called multiple times) |
| 55 | - `close()` |
| 56 | |
| 57 | Filtered output data should be written to the next filter in the chain |
| 58 | during `write()` and `close()` via the `write_next` method. All output data |
| 59 | must be written to the next filter before returning from `close()`. |
| 60 | |
| 61 | If a filter is dependent on reading the complete input data stream, the |
| 62 | filter should only write output data in `close()`. |
| 63 | """ |
| 64 | |
| 65 | #: Space-separated string list of attributes to be used in `check()` |
| 66 | attributes: str = '' |
| 67 | |
| 68 | @classmethod |
| 69 | def nattrs(cls) -> int: |
| 70 | return len(cls.attributes.split()) |
| 71 | |
| 72 | def check(self, src: FilterSource, attr_values: list[str | None]) -> None: |
| 73 | """ |
| 74 | Check whether this filter should be applied to the given source. |
| 75 | |
| 76 | `check` will be called once per stream. |
| 77 | |
| 78 | If `Passthrough` is raised, the filter will not be applied. |
| 79 | |
| 80 | Parameters: |
| 81 | |
| 82 | src: The source of the filtered blob. |
| 83 | |
| 84 | attr_values: The values of each attribute for the blob being filtered. |
| 85 | `attr_values` will be a sorted list containing attributes in the |
| 86 | order they were defined in ``cls.attributes``. |
| 87 | """ |
| 88 | |
| 89 | def write( |
| 90 | self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None] |
| 91 | ) -> None: |
| 92 | """ |
| 93 | Write input `data` to this filter. |
| 94 | |
| 95 | `write()` may be called multiple times per stream. |
| 96 | |
| 97 | Parameters: |
| 98 | |
| 99 | data: Input data. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…