Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STY: Run black #2370

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/user/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ The PDF form stores form fields as annotations with the subtype "\Widget". This

```python
from pypdf import PdfReader

reader = PdfReader("form.pdf")
fields = reader.get_fields()
```

```python
from pypdf import PdfReader
from pypdf.constants import AnnotationDictionaryAttributes

reader = PdfReader("form.pdf")
fields = []
for page in reader.pages:
Expand Down
1 change: 0 additions & 1 deletion pypdf/_text_extraction/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def handle_tj(
rtl_dir: bool,
visitor_text: Optional[Callable[[Any, Any, Any, Any, Any], None]],
) -> Tuple[str, bool]:

m = mult(tm_matrix, cm_matrix)
orientation = orient(m)
if orientation in orientations and len(operands) > 0:
Expand Down
8 changes: 6 additions & 2 deletions pypdf/_xobj_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,13 @@ def bits2byte(data: bytes, size: Tuple[int, int], bits: int) -> bytes:
expected_count = 2 * nb
if len(lookup) != expected_count:
if len(lookup) < expected_count:
raise PdfReadError(f"Not enough lookup values: Expected {expected_count}, got {len(lookup)}.")
raise PdfReadError(
f"Not enough lookup values: Expected {expected_count}, got {len(lookup)}."
)
if not check_if_whitespace_only(lookup[expected_count:]):
raise PdfReadError(f"Too many lookup values: Expected {expected_count}, got {len(lookup)}.")
raise PdfReadError(
f"Too many lookup values: Expected {expected_count}, got {len(lookup)}."
)
lookup = lookup[:expected_count]
colors_arr = [lookup[:nb], lookup[nb:]]
arr = b"".join(
Expand Down
54 changes: 41 additions & 13 deletions tests/test_xobject_image_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ def test_handle_flate__image_mode_1():
data = b"\x00\xe0\x00"
lookup = DecodedStreamObject()
expected_data = [
(66, 66, 66), (66, 66, 66), (66, 66, 66),
(0, 19, 55), (0, 19, 55), (0, 19, 55),
(66, 66, 66), (66, 66, 66), (66, 66, 66)
(66, 66, 66),
(66, 66, 66),
(66, 66, 66),
(0, 19, 55),
(0, 19, 55),
(0, 19, 55),
(66, 66, 66),
(66, 66, 66),
(66, 66, 66),
]

# No trailing data.
Expand All @@ -44,9 +50,11 @@ def test_handle_flate__image_mode_1():
size=(3, 3),
data=data,
mode="1",
color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]),
color_space=ArrayObject(
[NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]
),
colors=2,
obj_as_text="dummy"
obj_as_text="dummy",
)
assert expected_data == list(result[0].getdata())

Expand All @@ -56,32 +64,52 @@ def test_handle_flate__image_mode_1():
size=(3, 3),
data=data,
mode="1",
color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]),
color_space=ArrayObject(
[NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]
),
colors=2,
obj_as_text="dummy"
obj_as_text="dummy",
)
assert expected_data == list(result[0].getdata())

# Trailing non-whitespace character.
lookup.set_data(b"\x42\x42\x42\x00\x13\x37\x12")
with pytest.raises(PdfReadError, match=r"^Too many lookup values: Expected 6, got 7\.$"):
with pytest.raises(
PdfReadError, match=r"^Too many lookup values: Expected 6, got 7\.$"
):
_handle_flate(
size=(3, 3),
data=data,
mode="1",
color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]),
color_space=ArrayObject(
[
NameObject("/Indexed"),
NameObject("/DeviceRGB"),
NumberObject(1),
lookup,
]
),
colors=2,
obj_as_text="dummy"
obj_as_text="dummy",
)

# Not enough lookup data.
lookup.set_data(b"\x42\x42\x42\x00\x13")
with pytest.raises(PdfReadError, match=r"^Not enough lookup values: Expected 6, got 5\.$"):
with pytest.raises(
PdfReadError, match=r"^Not enough lookup values: Expected 6, got 5\.$"
):
_handle_flate(
size=(3, 3),
data=data,
mode="1",
color_space=ArrayObject([NameObject("/Indexed"), NameObject("/DeviceRGB"), NumberObject(1), lookup]),
color_space=ArrayObject(
[
NameObject("/Indexed"),
NameObject("/DeviceRGB"),
NumberObject(1),
lookup,
]
),
colors=2,
obj_as_text="dummy"
obj_as_text="dummy",
)
Loading