diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml index 6884f8b6f..d32032ad9 100644 --- a/.github/workflows/unit-tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -43,7 +43,7 @@ jobs: - name: Test with flake8 run: | - flake8 . --ignore E,F,I,SIM,C,PT,N,ASS,A,P,R,W + flake8 . --ignore E,I,SIM,C,PT,N,ASS,A,P,R,W,F401,F841 if: matrix.python-version != '2.7' - name: Test with pytest diff --git a/PyPDF2/generic.py b/PyPDF2/generic.py index 5340353c4..8e3e28cf4 100644 --- a/PyPDF2/generic.py +++ b/PyPDF2/generic.py @@ -34,15 +34,14 @@ __author__ = "Mathieu Fenniak" __author_email__ = "biziqe@mathieu.fenniak.net" +import codecs +import decimal import re -from .utils import readNonWhitespace, RC4_encrypt, skipOverComment -from .utils import b_, u_, chr_, ord_ -from .utils import PdfStreamError import warnings -from . import filters -from . import utils -import decimal -import codecs + +from . import filters, utils +from .utils import (PdfStreamError, RC4_encrypt, b_, chr_, ord_, + readNonWhitespace, skipOverComment, u_) ObjectPrefix = b_('/<[tf(n%') NumberSigns = b_('+-') @@ -631,7 +630,6 @@ def readFromStream(stream, pdf): # we found it by looking back one character further. data["__streamdata__"] = data["__streamdata__"][:-1] else: - if debug: print(("E", e, ndstream, debugging.toHex(end))) stream.seek(pos, 0) raise utils.PdfReadError("Unable to find 'endstream' marker after stream at byte %s." % utils.hexStr(stream.tell())) else: diff --git a/PyPDF2/merger.py b/PyPDF2/merger.py index e362732e8..c936f85d4 100644 --- a/PyPDF2/merger.py +++ b/PyPDF2/merger.py @@ -27,11 +27,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from .generic import * -from .utils import isString, str_ -from .pdf import PdfFileReader, PdfFileWriter -from .pagerange import PageRange from sys import version_info + +from .generic import (ArrayObject, Bookmark, Destination, DictionaryObject, + Field, FloatObject, NameObject, NullObject, NumberObject, + TextStringObject, TreeObject, createStringObject) +from .pagerange import PageRange +from .pdf import PdfFileReader, PdfFileWriter +from .utils import isString, str_ + if version_info < ( 3, 0 ): from cStringIO import StringIO StreamIO = StringIO diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index 7b7f08bf3..0f5504762 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -41,12 +41,13 @@ __maintainer__ = "Phaseit, Inc." __maintainer_email = "PyPDF2@phaseit.net" -import string import math +import string import struct import sys import uuid from sys import version_info + if version_info < ( 3, 0 ): from cStringIO import StringIO else: @@ -57,13 +58,18 @@ else: from io import BytesIO -from . import filters -from . import utils -import warnings import codecs -from .generic import * -from .utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirtualList -from .utils import isString, b_, u_, ord_, str_, formatWarning +import warnings + +from . import filters, utils +from .generic import (ArrayObject, BooleanObject, ByteStringObject, + DecodedStreamObject, Destination, DictionaryObject, + Field, FloatObject, IndirectObject, NameObject, + NullObject, NumberObject, RectangleObject, StreamObject, + TextStringObject, TreeObject, createStringObject, + readObject) +from .utils import (ConvertFunctionsToVirtualList, b_, formatWarning, isString, + ord_, readNonWhitespace, readUntilWhitespace, str_, u_) if version_info < ( 2, 4 ): from sets import ImmutableSet as frozenset @@ -72,7 +78,6 @@ from md5 import md5 else: from hashlib import md5 -import uuid class PdfFileWriter(object): @@ -406,7 +411,8 @@ def encrypt(self, user_pwd, owner_pwd = None, use_128bit = True): encryption. When false, 40bit encryption will be used. By default, this flag is on. """ - import time, random + import random + import time if owner_pwd == None: owner_pwd = user_pwd if use_128bit: diff --git a/PyPDF2/utils.py b/PyPDF2/utils.py index e104c394e..81abf0eb2 100644 --- a/PyPDF2/utils.py +++ b/PyPDF2/utils.py @@ -45,7 +45,7 @@ bytes_type = type(bytes()) # Works the same in Python 2.X and 3.X string_type = getattr(builtins, "unicode", str) -int_types = (int, long) if sys.version_info[0] < 3 else (int,) +int_types = (int, long) if sys.version_info[0] < 3 else (int,) # noqa # Make basic type tests more consistent @@ -252,7 +252,7 @@ def b_(s): def u_(s): if sys.version_info[0] < 3: - return unicode(s, 'unicode_escape') + return unicode(s, 'unicode_escape') # noqa else: return s