Skip to content

Commit

Permalink
STY: Minor refactoring to simplify #1543
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Jan 21, 2023
1 parent c1f8742 commit bc49495
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,15 +576,25 @@ def _merge_resources(
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
new_res = DictionaryObject()
new_res.update(res1.get(resource, DictionaryObject()).get_object())

def compute_unique_key(base_key: str) -> Tuple[str, bool]:
computed_key = base_key + str(uuid.uuid4())
return computed_key, False

page2res = cast(
DictionaryObject, res2.get(resource, DictionaryObject()).get_object()
)
rename_res = {}
for key in list(page2res.keys()):
for key in sorted(page2res.keys()):
if key in new_res and new_res.raw_get(key) != page2res.raw_get(key):
newname = NameObject(key + str(uuid.uuid4()))
rename_res[key] = newname
new_res[newname] = page2res[key]
unique_key, same_value = compute_unique_key(key)
newname = NameObject(unique_key)
if key != unique_key:
# we have to use a different name for this
rename_res[key] = newname
if not same_value:
# the value wasn't already recorded
new_res[newname] = page2res[key]
elif key not in new_res:
new_res[key] = page2res.raw_get(key)
return new_res, rename_res
Expand Down

0 comments on commit bc49495

Please sign in to comment.