Skip to content

Commit

Permalink
Make utils module private
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed May 14, 2022
1 parent 0a1c2c6 commit c3f8f46
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 409 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ PyPDF2 2.0.0 release. The changes are mostly using snake_case function-, method-
and variable-names as well as using properties instead of getter-methods.

### Deprecations (DEP)

* Make the `PyPDF2.utils` module private
* Rename of core classes:
* PdfFileReader ➔ PdfReader
* PdfFileWriter ➔ PdfWriter
* PdfFileMerger ➔ PdfMerger
* Use PEP8 conventions for function names and parameters
* If a property and a getter-method are both present, use the property

#### Details

In many places:
- getObject ➔ get_object
- writeToStream ➔ write_to_stream
Expand Down
21 changes: 13 additions & 8 deletions PyPDF2/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
import uuid
import warnings

from PyPDF2 import utils
from PyPDF2._utils import (
DEPR_MSG,
DEPR_MSG_NO_REPLACEMENT,
b_,
matrix_multiply,
u_,
)
from PyPDF2.constants import PageAttributes as PG
from PyPDF2.constants import Ressources as RES
from PyPDF2.errors import PageSizeNotDefinedError
Expand All @@ -49,7 +55,6 @@
RectangleObject,
TextStringObject,
)
from PyPDF2.utils import DEPR_MSG, DEPR_MSG_NO_REPLACEMENT, b_, u_


def _get_rectangle(self, name, defaults):
Expand Down Expand Up @@ -546,8 +551,8 @@ def mergeRotatedTranslatedPage(self, page2, rotation, tx, ty, expand=False):
[0, 0, 1],
]
rtranslation = [[1, 0, 0], [0, 1, 0], [tx, ty, 1]]
ctm = utils.matrix_multiply(translation, rotating)
ctm = utils.matrix_multiply(ctm, rtranslation)
ctm = matrix_multiply(translation, rotating)
ctm = matrix_multiply(ctm, rtranslation)

return self.mergeTransformedPage(
page2,
Expand All @@ -574,7 +579,7 @@ def mergeRotatedScaledPage(self, page2, rotation, scale, expand=False):
[0, 0, 1],
]
scaling = [[scale, 0, 0], [0, scale, 0], [0, 0, 1]]
ctm = utils.matrix_multiply(rotating, scaling)
ctm = matrix_multiply(rotating, scaling)

return self.mergeTransformedPage(
page2,
Expand All @@ -598,7 +603,7 @@ def mergeScaledTranslatedPage(self, page2, scale, tx, ty, expand=False):

translation = [[1, 0, 0], [0, 1, 0], [tx, ty, 1]]
scaling = [[scale, 0, 0], [0, scale, 0], [0, 0, 1]]
ctm = utils.matrix_multiply(scaling, translation)
ctm = matrix_multiply(scaling, translation)

return self.mergeTransformedPage(
page2,
Expand Down Expand Up @@ -631,8 +636,8 @@ def mergeRotatedScaledTranslatedPage(
[0, 0, 1],
]
scaling = [[scale, 0, 0], [0, scale, 0], [0, 0, 1]]
ctm = utils.matrix_multiply(rotating, scaling)
ctm = utils.matrix_multiply(ctm, translation)
ctm = matrix_multiply(rotating, scaling)
ctm = matrix_multiply(ctm, translation)

return self.mergeTransformedPage(
page2,
Expand Down
29 changes: 14 additions & 15 deletions PyPDF2/_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@
from hashlib import md5
from sys import version_info

from PyPDF2 import utils
from PyPDF2 import _utils
from PyPDF2._page import PageObject
from PyPDF2._security import RC4_encrypt, _alg33_1, _alg34, _alg35
from PyPDF2._utils import (
ConvertFunctionsToVirtualList,
b_,
formatWarning,
isString,
readUntilWhitespace,
)
from PyPDF2.constants import CatalogAttributes as CA
from PyPDF2.constants import Core as CO
from PyPDF2.constants import DocumentInformationAttributes as DI
Expand All @@ -64,13 +71,6 @@
read_object,
readNonWhitespace,
)
from PyPDF2.utils import (
ConvertFunctionsToVirtualList,
b_,
formatWarning,
isString,
readUntilWhitespace,
)

if version_info < (3, 0):
from cStringIO import StringIO
Expand Down Expand Up @@ -1053,14 +1053,14 @@ def read_object_header(self, stream):
# object header. In reality... some files have stupid cross reference
# tables that are off by whitespace bytes.
extra = False
utils.skipOverComment(stream)
extra |= utils.skipOverWhitespace(stream)
_utils.skipOverComment(stream)
extra |= _utils.skipOverWhitespace(stream)
stream.seek(-1, 1)
idnum = readUntilWhitespace(stream)
extra |= utils.skipOverWhitespace(stream)
extra |= _utils.skipOverWhitespace(stream)
stream.seek(-1, 1)
generation = readUntilWhitespace(stream)
extra |= utils.skipOverWhitespace(stream)
extra |= _utils.skipOverWhitespace(stream)
stream.seek(-1, 1)

# although it's not used, it might still be necessary to read
Expand All @@ -1085,8 +1085,7 @@ def readObjectHeader(self, stream):
return self.read_object_header(stream)

def cache_get_indirect_object(self, generation, idnum):
out = self.resolved_objects.get((generation, idnum))
return out
return self.resolved_objects.get((generation, idnum))

def cacheGetIndirectObject(self, generation, idnum):
warnings.warn(
Expand Down Expand Up @@ -1582,7 +1581,7 @@ def _decrypt(self, password):
for i in range(19, -1, -1):
new_key = b_("")
for l in range(len(key)):
new_key += b_(chr(utils.ord_(key[l]) ^ i))
new_key += b_(chr(_utils.ord_(key[l]) ^ i))
val = RC4_encrypt(new_key, val)
userpass = val
owner_password, key = self._authenticate_user_password(userpass)
Expand Down
2 changes: 1 addition & 1 deletion PyPDF2/_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import struct
from hashlib import md5

from PyPDF2.utils import b_, ord_, str_
from PyPDF2._utils import b_, ord_, str_

# ref: pdf1.8 spec section 3.5.2 algorithm 3.2
_encryption_padding = (
Expand Down
Loading

0 comments on commit c3f8f46

Please sign in to comment.