Skip to content

Commit

Permalink
[skip ci]: black/isort
Browse files Browse the repository at this point in the history
  • Loading branch information
black-isort-bot committed Jan 16, 2025
1 parent c233015 commit 08ca94a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
12 changes: 9 additions & 3 deletions PyPDFForm/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from reportlab.pdfbase.pdfmetrics import stringWidth

from .constants import (COMB, DEFAULT_FONT_SIZE, MULTILINE, NEW_LINE_SYMBOL,
WIDGET_TYPES, Annots, MaxLen, Rect, Parent, T)
WIDGET_TYPES, Annots, MaxLen, Parent, Rect, T)
from .font import (adjust_paragraph_font_size, adjust_text_field_font_size,
auto_detect_font, get_text_field_font_color,
get_text_field_font_size, text_field_font_size)
Expand Down Expand Up @@ -43,7 +43,9 @@ def set_character_x_paddings(
return widgets


def build_widgets(pdf_stream: bytes, use_full_widget_name: bool) -> Dict[str, WIDGET_TYPES]:
def build_widgets(
pdf_stream: bytes, use_full_widget_name: bool
) -> Dict[str, WIDGET_TYPES]:
"""Builds a widget dict given a PDF form stream."""

results = {}
Expand Down Expand Up @@ -201,7 +203,11 @@ def get_widget_full_key(widget: dict) -> Union[str, None]:

key = get_widget_key(widget)

if Parent in widget and T in widget[Parent].get_object() and widget[Parent][T] != key:
if (
Parent in widget
and T in widget[Parent].get_object()
and widget[Parent][T] != key
):
return f"{widget[Parent][T]}.{key}"

return None
Expand Down
4 changes: 3 additions & 1 deletion PyPDFForm/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def _init_helper(self, key_to_refresh: str = None) -> None:
"""Updates all attributes when the state of the PDF stream changes."""

refresh_not_needed = {}
new_widgets = build_widgets(self.read(), self.use_full_widget_name) if self.read() else {}
new_widgets = (
build_widgets(self.read(), self.use_full_widget_name) if self.read() else {}
)
for k, v in self.widgets.items():
if k in new_widgets:
new_widgets[k] = v
Expand Down
17 changes: 7 additions & 10 deletions tests/test_use_full_widget_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@ def test_fill(sample_template_with_full_key):
obj_1 = PdfWrapper(sample_template_with_full_key, use_full_widget_name=True)
obj_2 = PdfWrapper(sample_template_with_full_key, use_full_widget_name=True)

assert obj_1.fill(
{
"Gain de 2 classes.0": True
}
).read() == obj_2.fill(
{
"0": True
}
).read()
assert (
obj_1.fill({"Gain de 2 classes.0": True}).read()
== obj_2.fill({"0": True}).read()
)


def test_update_widget_key(sample_template_with_full_key):
Expand All @@ -49,4 +44,6 @@ def test_commit_widget_key_updates(sample_template_with_full_key):
def test_schema(sample_template_with_full_key):
obj = PdfWrapper(sample_template_with_full_key, use_full_widget_name=True)
assert "Gain de 2 classes.0" in obj.schema["properties"]
assert obj.schema["properties"]["Gain de 2 classes.0"] == obj.schema["properties"]["0"]
assert (
obj.schema["properties"]["Gain de 2 classes.0"] == obj.schema["properties"]["0"]
)

0 comments on commit 08ca94a

Please sign in to comment.