Skip to content

Commit

Permalink
STY: Fix style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 13, 2022
1 parent e45e66b commit b2aae74
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Test with flake8
run: |
flake8 . --ignore=E203,W503,E501,F405,E226,E128,E225,F403,E201,E202,E231,W504,E241,F401,E261,E302,E211,E701,E228,E111,F841,E117,E127,E251,E266,E
flake8 . --ignore=E203,W503,W504,E,F403,F405
if: matrix.python-version != '2.7'

- name: Test with pytest
Expand Down
10 changes: 9 additions & 1 deletion PyPDF2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,12 @@
from .pagerange import PageRange, parse_filename_page_ranges
from ._version import __version__

__all__ = ["pdf", "PdfFileMerger"]
__all__ = [
"__version__",
"PageRange",
"parse_filename_page_ranges",
"pdf",
"PdfFileMerger",
"PdfFileReader",
"PdfFileWriter",
]
2 changes: 1 addition & 1 deletion PyPDF2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def compress(data):
# Unable to import zlib. Attempt to use the System.IO.Compression
# library from the .NET framework. (IronPython only)
import System
from System import IO, Collections, Array
from System import IO, Array

def _string_to_bytearr(buf):
retval = Array.CreateInstance(System.Byte, len(buf))
Expand Down
4 changes: 2 additions & 2 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,10 @@ def readFromStream(stream, pdf):
try:
try:
ret=name.decode('utf-8')
except (UnicodeEncodeError, UnicodeDecodeError) as e:
except (UnicodeEncodeError, UnicodeDecodeError):
ret=name.decode('gbk')
return NameObject(ret)
except (UnicodeEncodeError, UnicodeDecodeError) as e:
except (UnicodeEncodeError, UnicodeDecodeError):
# Name objects should represent irregular characters
# with a '#' followed by the symbol's hex number
if not pdf.strict:
Expand Down
5 changes: 2 additions & 3 deletions PyPDF2/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ def _trim_dests(self, pdf, dests, pages):
page set.
"""
new_dests = []
prev_header_added = True
for k, o in list(dests.items()):
for j in range(*pages):
if pdf.getPage(j).getObject() == o['/Page'].getObject():
Expand Down Expand Up @@ -356,7 +355,7 @@ def _write_dests(self):
if p.id == v['/Page']:
v[NameObject('/Page')] = p.out_pagedata
pageno = i
pdf = p.src
pdf = p.src # noqa: F841
break
if pageno is not None:
self.output.addNamedDestinationObject(v)
Expand Down Expand Up @@ -429,7 +428,7 @@ def _write_bookmarks(self, bookmarks=None, parent=None):
b[NameObject('/A')] = DictionaryObject({NameObject('/S'): NameObject('/GoTo'), NameObject('/D'): ArrayObject(args)})

pageno = i
pdf = p.src
pdf = p.src # noqa: F841
break
if pageno is not None:
del b['/Page'], b['/Type']
Expand Down
12 changes: 6 additions & 6 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
__maintainer__ = "Phaseit, Inc."
__maintainer_email = "[email protected]"

import string
import math
import struct
import sys
Expand All @@ -57,7 +56,6 @@
else:
from io import BytesIO

from . import filters
from . import utils
import warnings
import codecs
Expand Down Expand Up @@ -543,7 +541,6 @@ def _sweepIndirectReferences(self, externMap, data):
if debug: print((data, "TYPE", data.__class__.__name__))
if isinstance(data, DictionaryObject):
for key, value in list(data.items()):
origvalue = value
value = self._sweepIndirectReferences(externMap, value)
if isinstance(value, StreamObject):
# a dictionary value is a stream. streams must be indirect
Expand Down Expand Up @@ -1752,7 +1749,10 @@ def readObjectHeader(self, stream):
idnum = readUntilWhitespace(stream)
extra |= utils.skipOverWhitespace(stream); stream.seek(-1, 1)
generation = readUntilWhitespace(stream)
obj = stream.read(3)

# although it's not used, it might still be necessary to read
_obj = stream.read(3) # noqa: F841

readNonWhitespace(stream)
stream.seek(-1, 1)
if (extra and self.strict):
Expand Down Expand Up @@ -1938,8 +1938,8 @@ def used_before(num, generation):
# The rest of the elements depend on the xref_type
if xref_type == 0:
# linked list of free objects
next_free_object = getEntry(1)
next_generation = getEntry(2)
next_free_object = getEntry(1) # noqa: F841
next_generation = getEntry(2) # noqa: F841
elif xref_type == 1:
# objects that are in use but are not compressed
byte_offset = getEntry(1)
Expand Down
2 changes: 1 addition & 1 deletion PyPDF2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def b_(s):
if len(s) < 2:
bc[s] = r
return r
except Exception as e:
except Exception:
print(s)
r = s.encode('utf-8')
if len(s) < 2:
Expand Down
1 change: 0 additions & 1 deletion PyPDF2/xmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import datetime
import decimal
from .generic import PdfObject
from xml.dom import getDOMImplementation
from xml.dom.minidom import parseString
from .utils import u_

Expand Down
1 change: 0 additions & 1 deletion Tests/test_merger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import binascii
import sys

import PyPDF2
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import pytest
import PyPDF2.utils
from PyPDF2.filters import decodeStreamData, _xobj_to_image
from PyPDF2.filters import _xobj_to_image

TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.utils import PageSizeNotDefinedError
from PyPDF2.generic import IndirectObject, RectangleObject
from PyPDF2.generic import RectangleObject

TESTS_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(TESTS_ROOT)
Expand Down

0 comments on commit b2aae74

Please sign in to comment.