From f4222fee270170a63b6c0dab21c27a42fb35c716 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Fri, 27 May 2022 23:14:52 +0000 Subject: [PATCH 1/6] DEV: Create flake8 config file Signed-off-by: Matthew Peveler --- .flake8 | 3 +++ .github/workflows/github-ci.yaml | 2 +- PyPDF2/_reader.py | 2 +- PyPDF2/generic.py | 6 +++--- tests/test_generic.py | 8 ++++---- tests/test_workflows.py | 4 ++-- 6 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..8dfb6ec50 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +ignore = E203,E501,E741,W503,W504,F403,F405 +exclude = build,sample-files diff --git a/.github/workflows/github-ci.yaml b/.github/workflows/github-ci.yaml index 297be300d..2f794bfb8 100644 --- a/.github/workflows/github-ci.yaml +++ b/.github/workflows/github-ci.yaml @@ -43,7 +43,7 @@ jobs: pip install . - name: Test with flake8 run: | - flake8 . --ignore=E203,W503,W504,E,F403,F405 --exclude build,sample-files + flake8 . - name: Test with pytest run: | python -m coverage run --parallel-mode -m pytest tests -vv diff --git a/PyPDF2/_reader.py b/PyPDF2/_reader.py index 6c5085f70..c7519b246 100644 --- a/PyPDF2/_reader.py +++ b/PyPDF2/_reader.py @@ -1653,7 +1653,7 @@ def read_next_end_line(self, stream: StreamType, limit_offset: int = 0) -> bytes if stream.tell() < 2: raise PdfReadError("EOL marker not found") stream.seek(-2, 1) - if x == b_("\n") or x == b_("\r"): ## \n = LF; \r = CR + if x == b_("\n") or x == b_("\r"): # \n = LF; \r = CR crlf = False while x == b_("\n") or x == b_("\r"): x = stream.read(1) diff --git a/PyPDF2/generic.py b/PyPDF2/generic.py index c3fbfc80a..a30e26d9b 100644 --- a/PyPDF2/generic.py +++ b/PyPDF2/generic.py @@ -523,7 +523,7 @@ def write_to_stream( if encryption_key: from ._security import RC4_encrypt - bytearr = RC4_encrypt(encryption_key, bytearr) # type: ignore + bytearr = RC4_encrypt(encryption_key, bytearr) # type: ignore stream.write(b_("<")) stream.write(hexencode(bytearr)) stream.write(b_(">")) @@ -2144,7 +2144,7 @@ def decode_pdfdocencoding(byte_array: bytes) -> str: "\u0004", "\u0005", "\u0006", - "\u0007", # 0 - 7 + "\u0007", # 0 - 7 "\u0008", "\u0009", "\u000a", @@ -2152,7 +2152,7 @@ def decode_pdfdocencoding(byte_array: bytes) -> str: "\u000c", "\u000d", "\u000e", - "\u000f", # 8 - 15 + "\u000f", # 8 - 15 "\u0010", "\u0011", "\u0012", diff --git a/tests/test_generic.py b/tests/test_generic.py index 474436ca2..258420262 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -67,13 +67,13 @@ def test_boolean_object_write(): def test_boolean_eq(): boolobj = BooleanObject(True) - assert (boolobj == True) is True - assert (boolobj == False) is False + assert (boolobj == True) is True # noqa: E712 + assert (boolobj == False) is False # noqa: E712 assert (boolobj == "True") is False boolobj = BooleanObject(False) - assert (boolobj == True) is False - assert (boolobj == False) is True + assert (boolobj == True) is False # noqa: E712 + assert (boolobj == False) is True # noqa: E712 assert (boolobj == "True") is False diff --git a/tests/test_workflows.py b/tests/test_workflows.py index 98622a607..0c5f9492b 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -71,10 +71,10 @@ def test_decrypt(): os.path.join(RESOURCE_ROOT, "libreoffice-writer-password.pdf"), "rb" ) as inputfile: reader = PdfReader(inputfile) - assert reader.is_encrypted == True + assert reader.is_encrypted is True reader.decrypt("openpassword") assert len(reader.pages) == 1 - assert reader.is_encrypted == True + assert reader.is_encrypted is True metadict = reader.metadata assert dict(metadict) == { "/CreationDate": "D:20220403203552+02'00'", From d4a12860a285406ff79953151a8bea10d8d13e91 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Fri, 27 May 2022 23:23:33 +0000 Subject: [PATCH 2/6] clean up few more rules --- .flake8 | 2 +- PyPDF2/filters.py | 4 ++-- PyPDF2/xmp.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.flake8 b/.flake8 index 8dfb6ec50..079719d05 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,3 @@ [flake8] -ignore = E203,E501,E741,W503,W504,F403,F405 +ignore = E501,E741,W503,W604 exclude = build,sample-files diff --git a/PyPDF2/filters.py b/PyPDF2/filters.py index 6bf4619c3..f0dddbd00 100644 --- a/PyPDF2/filters.py +++ b/PyPDF2/filters.py @@ -61,7 +61,7 @@ def decompress(data: bytes) -> bytes: except zlib.error: d = zlib.decompressobj(zlib.MAX_WBITS | 32) result_str = b"" - for b in [data[i : i + 1] for i in range(len(data))]: + for b in [data[i: i + 1] for i in range(len(data))]: try: result_str += d.decompress(b) except zlib.error: @@ -126,7 +126,7 @@ def _decode_png_prediction(data: str, columns: int) -> str: prev_rowdata = (0,) * rowlength for row in range(len(data) // rowlength): rowdata = [ - ord_(x) for x in data[(row * rowlength) : ((row + 1) * rowlength)] + ord_(x) for x in data[(row * rowlength): ((row + 1) * rowlength)] ] filter_byte = rowdata[0] if filter_byte == 0: diff --git a/PyPDF2/xmp.py b/PyPDF2/xmp.py index ee81c06a4..aceec593c 100644 --- a/PyPDF2/xmp.py +++ b/PyPDF2/xmp.py @@ -427,8 +427,8 @@ def custom_properties(self) -> Dict[Any, Any]: break key = ( key[:idx] - + chr(int(key[idx + 1 : idx + 5], base=16)) - + key[idx + 5 :] + + chr(int(key[idx + 1: idx + 5], base=16)) + + key[idx + 5:] ) if node.nodeType == node.ATTRIBUTE_NODE: value = node.nodeValue From 78ae03c465edb3a5d23e74a1ef086d8eb11da220 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sat, 28 May 2022 11:39:09 -0400 Subject: [PATCH 3/6] Update .flake8 --- .flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 079719d05..452c42549 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,3 @@ [flake8] -ignore = E501,E741,W503,W604 +ignore = E203,E501,E741,W503,W604 exclude = build,sample-files From 2498247060aa6402ae67581eb7045d25eb08e536 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sat, 28 May 2022 11:39:51 -0400 Subject: [PATCH 4/6] revert change --- PyPDF2/filters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyPDF2/filters.py b/PyPDF2/filters.py index f0dddbd00..6bf4619c3 100644 --- a/PyPDF2/filters.py +++ b/PyPDF2/filters.py @@ -61,7 +61,7 @@ def decompress(data: bytes) -> bytes: except zlib.error: d = zlib.decompressobj(zlib.MAX_WBITS | 32) result_str = b"" - for b in [data[i: i + 1] for i in range(len(data))]: + for b in [data[i : i + 1] for i in range(len(data))]: try: result_str += d.decompress(b) except zlib.error: @@ -126,7 +126,7 @@ def _decode_png_prediction(data: str, columns: int) -> str: prev_rowdata = (0,) * rowlength for row in range(len(data) // rowlength): rowdata = [ - ord_(x) for x in data[(row * rowlength): ((row + 1) * rowlength)] + ord_(x) for x in data[(row * rowlength) : ((row + 1) * rowlength)] ] filter_byte = rowdata[0] if filter_byte == 0: From 1cda6fb8cc95d389bebb3b9b5c6a0a80afd01064 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sat, 28 May 2022 11:40:23 -0400 Subject: [PATCH 5/6] Update xmp.py --- PyPDF2/xmp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyPDF2/xmp.py b/PyPDF2/xmp.py index aceec593c..ee81c06a4 100644 --- a/PyPDF2/xmp.py +++ b/PyPDF2/xmp.py @@ -427,8 +427,8 @@ def custom_properties(self) -> Dict[Any, Any]: break key = ( key[:idx] - + chr(int(key[idx + 1: idx + 5], base=16)) - + key[idx + 5:] + + chr(int(key[idx + 1 : idx + 5], base=16)) + + key[idx + 5 :] ) if node.nodeType == node.ATTRIBUTE_NODE: value = node.nodeValue From c172684b1bcc583da614830146582cf9a7f67006 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Sat, 28 May 2022 11:46:00 -0400 Subject: [PATCH 6/6] update config file --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.flake8 b/.flake8 index 452c42549..fbc73fdc2 100644 --- a/.flake8 +++ b/.flake8 @@ -1,3 +1,5 @@ [flake8] +# The flake8 config should work well with black, +# see https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8 ignore = E203,E501,E741,W503,W604 exclude = build,sample-files