diff --git a/pypdf/filters.py b/pypdf/filters.py index 4d01b7552..0b1e6c041 100644 --- a/pypdf/filters.py +++ b/pypdf/filters.py @@ -46,6 +46,7 @@ from ._utils import ( WHITESPACES_AS_BYTES, deprecate, + deprecate_with_replacement, deprecation_no_replacement, logger_warning, ) @@ -479,7 +480,7 @@ def decode( @dataclass -class CCITParameters: +class CCITTParameters: """§7.4.6, optional parameters for the CCITTFaxDecode filter.""" K: int = 0 @@ -501,6 +502,19 @@ def group(self) -> int: return CCITTgroup +def __create_old_class_instance( + K: int = 0, + columns: int = 0, + rows: int = 0 +) -> CCITTParameters: + deprecate_with_replacement("CCITParameters", "CCITTParameters", "6.0.0") + return CCITTParameters(K, columns, rows) + + +# Create an alias for the old class name +CCITParameters = __create_old_class_instance + + class CCITTFaxDecode: """ §7.4.6, CCITTFaxDecode filter (ISO 32000). @@ -515,7 +529,7 @@ class CCITTFaxDecode: def _get_parameters( parameters: Union[None, ArrayObject, DictionaryObject, IndirectObject], rows: Union[int, IndirectObject], - ) -> CCITParameters: + ) -> CCITTParameters: # §7.4.6, optional parameters for the CCITTFaxDecode filter k = 0 columns = 1728 @@ -535,7 +549,7 @@ def _get_parameters( if CCITT.K in parameters_unwrapped: k = parameters_unwrapped[CCITT.K].get_object() # type: ignore - return CCITParameters(K=k, columns=columns, rows=int(rows)) + return CCITTParameters(K=k, columns=columns, rows=int(rows)) @staticmethod def decode( diff --git a/tests/test_filters.py b/tests/test_filters.py index 4e4bdfd56..395f52cb2 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -17,6 +17,7 @@ ASCIIHexDecode, CCITParameters, CCITTFaxDecode, + CCITTParameters, FlateDecode, ) from pypdf.generic import ArrayObject, DictionaryObject, IndirectObject, NameObject, NumberObject @@ -188,7 +189,17 @@ def test_ascii85decode_five_zero_bytes(): def test_ccitparameters(): - params = CCITParameters() + with pytest.raises( + DeprecationWarning, + match="CCITParameters is deprecated and will be removed in pypdf 6.0.0. Use CCITTParameters instead", + ): + params = CCITParameters() + assert params.K == 0 # zero is the default according to page 78 + assert params.group == 3 + + +def test_ccittparameters(): + params = CCITTParameters() assert params.K == 0 # zero is the default according to page 78 assert params.group == 3