Make a Python dict from a PDF page label rule. Args: item -- a tuple (pno, rule) with the start page number and the rule string like < >. Returns: A dict like {'startpage': int, 'prefix': str, 'style': str, 'firstpagenum': int}.
(item)
| 4721 | |
| 4722 | |
| 4723 | def rule_dict(item): |
| 4724 | """Make a Python dict from a PDF page label rule. |
| 4725 | |
| 4726 | Args: |
| 4727 | item -- a tuple (pno, rule) with the start page number and the rule |
| 4728 | string like <</S/D...>>. |
| 4729 | Returns: |
| 4730 | A dict like |
| 4731 | {'startpage': int, 'prefix': str, 'style': str, 'firstpagenum': int}. |
| 4732 | """ |
| 4733 | # Jorj McKie, 2021-01-06 |
| 4734 | |
| 4735 | pno, rule = item |
| 4736 | rule = rule[2:-2].split("/")[1:] # strip "<<" and ">>" |
| 4737 | d = {"startpage": pno, "prefix": "", "firstpagenum": 1} |
| 4738 | skip = False |
| 4739 | for i, item in enumerate(rule): |
| 4740 | if skip: # this item has already been processed |
| 4741 | skip = False # deactivate skipping again |
| 4742 | continue |
| 4743 | if item == "S": # style specification |
| 4744 | d["style"] = rule[i + 1] # next item has the style |
| 4745 | skip = True # do not process next item again |
| 4746 | continue |
| 4747 | if item.startswith("P"): # prefix specification: extract the string |
| 4748 | x = item[1:].replace("(", "").replace(")", "") |
| 4749 | d["prefix"] = x |
| 4750 | continue |
| 4751 | if item.startswith("St"): # start page number specification |
| 4752 | x = int(item[2:]) |
| 4753 | d["firstpagenum"] = x |
| 4754 | return d |
| 4755 | |
| 4756 | |
| 4757 | def get_label_pno(pgNo, labels): |
no outgoing calls
no test coverage detected
searching dependent graphs…