MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / get_list

Function get_list

src_classic/__main__.py:112–156  ·  view source on GitHub ↗

Transform a page / xref specification into a list of integers. Args ---- rlist: (str) the specification limit: maximum number, i.e. number of pages, number of objects what: a string to be used in error messages Returns ------- A list of integers repre

(rlist, limit, what="page")

Source from the content-addressed store, hash-verified

110
111
112def get_list(rlist, limit, what="page"):
113 """Transform a page / xref specification into a list of integers.
114
115 Args
116 ----
117 rlist: (str) the specification
118 limit: maximum number, i.e. number of pages, number of objects
119 what: a string to be used in error messages
120 Returns
121 -------
122 A list of integers representing the specification.
123 """
124 N = str(limit - 1)
125 rlist = rlist.replace("N", N).replace(" ", "")
126 rlist_arr = rlist.split(",")
127 out_list = []
128 for seq, item in enumerate(rlist_arr):
129 n = seq + 1
130 if item.isdecimal(): # a single integer
131 i = int(item)
132 if 1 <= i < limit:
133 out_list.append(int(item))
134 else:
135 sys.exit("bad %s specification at item %i" % (what, n))
136 continue
137 try: # this must be a range now, and all of the following must work:
138 i1, i2 = item.split("-") # will fail if not 2 items produced
139 i1 = int(i1) # will fail on non-integers
140 i2 = int(i2)
141 except:
142 sys.exit("bad %s range specification at item %i" % (what, n))
143
144 if not (1 <= i1 < limit and 1 <= i2 < limit):
145 sys.exit("bad %s range specification at item %i" % (what, n))
146
147 if i1 == i2: # just in case: a range of equal numbers
148 out_list.append(i1)
149 continue
150
151 if i1 < i2: # first less than second
152 out_list += list(range(i1, i2 + 1))
153 else: # first larger than second
154 out_list += list(range(i1, i2 - 1, -1))
155
156 return out_list
157
158
159def show(args):

Callers 5

showFunction · 0.70
cleanFunction · 0.70
doc_joinFunction · 0.70
extract_objectsFunction · 0.70
gettextFunction · 0.70

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…