-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEP: Rename names to be PEP8-compliant (#967)
All of the following get in [the deprecation process](https://pypdf2.readthedocs.io/en/latest/dev/deprecations.html). This means the old parameters will work for a while to give users a chance to migrate without service disruptions. `PdfWriter.get_page`: the pageNumber parameter is renamed to page_number `PyPDF2.filters`: * For all classes, a parameter rename: decodeParms ➔ decode_parms * decodeStreamData ➔ decode_stream_data `PyPDF2.xmp`: * XmpInformation.rdfRoot ➔ XmpInformation.rdf_root * XmpInformation.xmp_createDate ➔ XmpInformation.xmp_create_date * XmpInformation.xmp_creatorTool ➔ XmpInformation.xmp_creator_tool * XmpInformation.xmp_metadataDate ➔ XmpInformation.xmp_metadata_date * XmpInformation.xmp_modifyDate ➔ XmpInformation.xmp_modify_date * XmpInformation.xmpMetadata ➔ XmpInformation.xmp_metadata * XmpInformation.xmpmm_documentId ➔ XmpInformation.xmpmm_document_id * XmpInformation.xmpmm_instanceId ➔ XmpInformation.xmpmm_instance_id `PyPDF2.generic`: * readHexStringFromStream ➔ read_hex_string_from_stream * initializeFromDictionary ➔ initialize_from_dictionary * createStringObject ➔ create_string_object * TreeObject.hasChildren ➔ TreeObject.has_children * TreeObject.emptyTree ➔ TreeObject.empty_tree
- Loading branch information
1 parent
797963a
commit 953a11d
Showing
9 changed files
with
240 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,11 @@ | |
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
"""Implementation of stream filters for PDF.""" | ||
""" | ||
Implementation of stream filters for PDF. | ||
See TABLE H.1 Abbreviations for standard filter names | ||
""" | ||
__author__ = "Mathieu Fenniak" | ||
__author_email__ = "[email protected]" | ||
|
||
|
@@ -43,7 +47,7 @@ | |
except ImportError: | ||
from typing_extensions import Literal # type: ignore[misc] | ||
|
||
from ._utils import b_, ord_, paeth_predictor | ||
from ._utils import b_, deprecate_with_replacement, ord_, paeth_predictor | ||
from .constants import CcittFaxDecodeParameters as CCITT | ||
from .constants import ColorSpaces | ||
from .constants import FilterTypeAbbreviations as FTA | ||
|
@@ -76,40 +80,45 @@ def compress(data: bytes) -> bytes: | |
class FlateDecode: | ||
@staticmethod | ||
def decode( | ||
# TODO: PEP8 | ||
data: bytes, | ||
decodeParms: Union[None, ArrayObject, DictionaryObject], | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
**kwargs: Any, | ||
) -> bytes: | ||
""" | ||
:param data: flate-encoded data. | ||
:param decodeParms: a dictionary of values, understanding the | ||
:param decode_parms: a dictionary of values, understanding the | ||
"/Predictor":<int> key only | ||
:return: the flate-decoded data. | ||
""" | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] | ||
str_data = decompress(data) | ||
predictor = 1 | ||
|
||
if decodeParms: | ||
if decode_parms: | ||
try: | ||
if isinstance(decodeParms, ArrayObject): | ||
for decode_parm in decodeParms: | ||
if isinstance(decode_parms, ArrayObject): | ||
for decode_parm in decode_parms: | ||
if "/Predictor" in decode_parm: | ||
predictor = decode_parm["/Predictor"] | ||
else: | ||
predictor = decodeParms.get("/Predictor", 1) | ||
predictor = decode_parms.get("/Predictor", 1) | ||
except AttributeError: | ||
pass # Usually an array with a null object was read | ||
# predictor 1 == no predictor | ||
if predictor != 1: | ||
# The /Columns param. has 1 as the default value; see ISO 32000, | ||
# §7.4.4.3 LZWDecode and FlateDecode Parameters, Table 8 | ||
if isinstance(decodeParms, ArrayObject): | ||
if isinstance(decode_parms, ArrayObject): | ||
columns = 1 | ||
for decode_parm in decodeParms: | ||
for decode_parm in decode_parms: | ||
if "/Columns" in decode_parm: | ||
columns = decode_parm["/Columns"] | ||
else: | ||
columns = 1 if decodeParms is None else decodeParms.get(LZW.COLUMNS, 1) | ||
columns = ( | ||
1 if decode_parms is None else decode_parms.get(LZW.COLUMNS, 1) | ||
) | ||
|
||
# PNG prediction: | ||
if 10 <= predictor <= 15: | ||
|
@@ -171,17 +180,20 @@ class ASCIIHexDecode: | |
|
||
@staticmethod | ||
def decode( | ||
# TODO: PEP8 | ||
data: str, | ||
decodeParms: Union[None, ArrayObject, DictionaryObject] = None, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, # noqa: F841 | ||
**kwargs: Any, | ||
) -> str: | ||
""" | ||
:param data: a str sequence of hexadecimal-encoded values to be | ||
converted into a base-7 ASCII string | ||
:param decodeParms: | ||
:param decode_parms: | ||
:return: a string conversion in base-7 ASCII, where each of its values | ||
v is such that 0 <= ord(v) <= 127. | ||
""" | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] # noqa: F841 | ||
retval = "" | ||
hex_pair = "" | ||
index = 0 | ||
|
@@ -288,16 +300,19 @@ def decode(self) -> str: | |
|
||
@staticmethod | ||
def decode( | ||
# TODO: PEP8 | ||
data: bytes, | ||
decodeParms: Union[None, ArrayObject, DictionaryObject] = None, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
**kwargs: Any, | ||
) -> str: | ||
""" | ||
:param data: ``bytes`` or ``str`` text to decode. | ||
:param decodeParms: a dictionary of parameter values. | ||
:param decode_parms: a dictionary of parameter values. | ||
:return: decoded data. | ||
:rtype: bytes | ||
""" | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] # noqa: F841 | ||
return LZWDecode.Decoder(data).decode() | ||
|
||
|
||
|
@@ -307,8 +322,12 @@ class ASCII85Decode: | |
@staticmethod | ||
def decode( | ||
data: Union[str, bytes], | ||
decodeParms: Union[None, ArrayObject, DictionaryObject] = None, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
**kwargs: Any, | ||
) -> bytes: | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] # noqa: F841 | ||
if isinstance(data, str): | ||
data = data.encode("ascii") | ||
group_index = b = 0 | ||
|
@@ -335,16 +354,26 @@ def decode( | |
class DCTDecode: | ||
@staticmethod | ||
def decode( | ||
data: bytes, decodeParms: Union[None, ArrayObject, DictionaryObject] = None | ||
data: bytes, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
**kwargs: Any, | ||
) -> bytes: | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] # noqa: F841 | ||
return data | ||
|
||
|
||
class JPXDecode: | ||
@staticmethod | ||
def decode( | ||
data: bytes, decodeParms: Union[None, ArrayObject, DictionaryObject] = None | ||
data: bytes, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
**kwargs: Any, | ||
) -> bytes: | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] # noqa: F841 | ||
return data | ||
|
||
|
||
|
@@ -403,11 +432,14 @@ def _get_parameters( | |
@staticmethod | ||
def decode( | ||
data: bytes, | ||
# TODO: PEP8 | ||
decodeParms: Union[None, ArrayObject, DictionaryObject] = None, | ||
decode_parms: Union[None, ArrayObject, DictionaryObject] = None, | ||
height: int = 0, | ||
**kwargs: Any, | ||
) -> bytes: | ||
parms = CCITTFaxDecode._get_parameters(decodeParms, height) | ||
if "decodeParms" in kwargs: # pragma: no cover | ||
deprecate_with_replacement("decodeParms", "parameters", "4.0.0") | ||
decode_parms = kwargs["decodeParms"] | ||
parms = CCITTFaxDecode._get_parameters(decode_parms, height) | ||
|
||
img_size = len(data) | ||
tiff_header_struct = "<2shlh" + "hhll" * 8 + "h" | ||
|
@@ -457,7 +489,7 @@ def decode( | |
return tiff_header + data | ||
|
||
|
||
def decodeStreamData(stream: Any) -> Union[str, bytes]: # utils.StreamObject | ||
def decode_stream_data(stream: Any) -> Union[str, bytes]: # utils.StreamObject | ||
filters = stream.get(SA.FILTER, ()) | ||
|
||
if len(filters) and not isinstance(filters[0], NameObject): | ||
|
@@ -496,6 +528,11 @@ def decodeStreamData(stream: Any) -> Union[str, bytes]: # utils.StreamObject | |
return data | ||
|
||
|
||
def decodeStreamData(stream: Any) -> Union[str, bytes]: # pragma: no cover | ||
deprecate_with_replacement("decodeStreamData", "decode_stream_data", "4.0.0") | ||
return decode_stream_data(stream) | ||
|
||
|
||
def _xobj_to_image(x_object_obj: Dict[str, Any]) -> Tuple[Optional[str], bytes]: | ||
""" | ||
Users need to have the pillow package installed. | ||
|
Oops, something went wrong.