Skip to content

Commit

Permalink
DEP: PEP8 renaming
Browse files Browse the repository at this point in the history
* getXmpMetadata / xmpMetadata ➔ xmp_metadata
* get_outlines ➔ _get_outlines (use outlines property instead)
* getXmpMetadata ➔ xmp_metadata
* getDestArray ➔ dest_array
* additionalActions ➔ additional_actions
* defaultValue ➔ default_value
* mappingName ➔ mapping_name
* altName ➔ alternate_name
* fieldType ➔ field_type
* ensureIsNumber ➔ _ensure_is_number
* decodedSelf : decoded_self
* addChild / removeChild  ➔ add_child / remove_child
* flateEncode  ➔ flate_encode
* getData / setData  ➔ get_data / set_data

See #900
  • Loading branch information
MartinThoma committed May 26, 2022
1 parent 4fdbb3b commit b9a160d
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 114 deletions.
33 changes: 24 additions & 9 deletions PyPDF2/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def xmp_metadata(self):
"""
try:
self._override_encryption = True
return self.trailer[TK.ROOT].getXmpMetadata()
return self.trailer[TK.ROOT].xmp_metadata
finally:
self._override_encryption = False

Expand Down Expand Up @@ -729,9 +729,9 @@ def getNamedDestinations(self, tree=None, retval=None):
@property
def outlines(self):
"""Read-only property."""
return self.get_outlines()
return self._get_outlines()

def get_outlines(self, node=None, outlines=None):
def _get_outlines(self, node=None, outlines=None):
"""
Retrieve the document outline present in the document.
Expand Down Expand Up @@ -768,7 +768,7 @@ def get_outlines(self, node=None, outlines=None):
# check for sub-outlines
if "/First" in node:
sub_outlines = []
self.get_outlines(node["/First"], sub_outlines)
self._get_outlines(node["/First"], sub_outlines)
if sub_outlines:
outlines.append(sub_outlines)

Expand All @@ -778,18 +778,33 @@ def get_outlines(self, node=None, outlines=None):

return outlines

def get_outlines(self, node=None, outlines=None):
"""
.. deprecated:: 1.28.0
Use the property :py:attr:`outlines` instead.
"""
warnings.warn(
"get_outlines will be removed in PyPDF2 2.0.0. "
"Use the property :py:attr:`outlines` instead.",
PendingDeprecationWarning,
stacklevel=2,
)
return self._get_outlines(node, outlines)

def getOutlines(self, node=None, outlines=None):
"""
.. deprecated:: 1.28.0
Use :meth:`get_outlines` instead.
Use the property :py:attr:`outlines` instead.
"""
warnings.warn(
"getOutlines will be removed in PyPDF2 2.0.0. Use get_outlines instead.",
"getOutlines will be removed in PyPDF2 2.0.0. "
"Use the property 'outlines' instead.",
PendingDeprecationWarning,
stacklevel=2,
)
return self.get_outlines(node, outlines)
return self._get_outlines(node, outlines)

def _get_page_number_by_indirect(self, indirect_ref):
"""Generate _pageId2Num"""
Expand Down Expand Up @@ -1073,7 +1088,7 @@ def _get_object_from_stream(self, indirect_reference):
assert obj_stm["/Type"] == "/ObjStm"
# /N is the number of indirect objects in the stream
assert idx < obj_stm["/N"]
stream_data = BytesIO(b_(obj_stm.getData()))
stream_data = BytesIO(b_(obj_stm.get_data()))
for i in range(obj_stm["/N"]):
readNonWhitespace(stream_data)
stream_data.seek(-1, 1)
Expand Down Expand Up @@ -1515,7 +1530,7 @@ def _read_pdf15_xref_stream(self, stream):
xrefstream = read_object(stream, self)
assert xrefstream["/Type"] == "/XRef"
self.cache_indirect_object(generation, idnum, xrefstream)
stream_data = BytesIO(b_(xrefstream.getData()))
stream_data = BytesIO(b_(xrefstream.get_data()))
# Index pairs specify the subsections in the dictionary. If
# none create one subsection that spans everything.
idx_pairs = xrefstream.get("/Index", [0, xrefstream.get("/Size")])
Expand Down
4 changes: 2 additions & 2 deletions PyPDF2/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def add_bookmark(
dest = Destination(
NameObject("/" + title + " bookmark"), page_ref, NameObject(fit), *zoom_args
)
dest_array = dest.getDestArray()
dest_array = dest.dest_array
action.update(
{NameObject("/D"): dest_array, NameObject("/S"): NameObject("/GoTo")}
)
Expand Down Expand Up @@ -1470,7 +1470,7 @@ def add_link(self, pagenum, pagedest, rect, border=None, fit="/Fit", *args):
dest = Destination(
NameObject("/LinkName"), page_dest, NameObject(fit), *zoom_args
) # TODO: create a better name for the link
dest_array = dest.getDestArray()
dest_array = dest.dest_array

lnk = DictionaryObject()
lnk.update(
Expand Down
4 changes: 2 additions & 2 deletions PyPDF2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def _xobj_to_image(x_object_obj):
from PyPDF2.constants import GraphicsStateParameters as G

size = (x_object_obj[IA.WIDTH], x_object_obj[IA.HEIGHT])
data = x_object_obj.getData()
data = x_object_obj.get_data()
if x_object_obj[IA.COLOR_SPACE] == ColorSpaces.DEVICE_RGB:
mode = "RGB"
else:
Expand All @@ -564,7 +564,7 @@ def _xobj_to_image(x_object_obj):
extension = ".png"
img = Image.frombytes(mode, size, data)
if G.S_MASK in x_object_obj: # add alpha channel
alpha = Image.frombytes("L", size, x_object_obj[G.S_MASK].getData())
alpha = Image.frombytes("L", size, x_object_obj[G.S_MASK].get_data())
img.putalpha(alpha)
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format="PNG")
Expand Down
Loading

0 comments on commit b9a160d

Please sign in to comment.