MCPcopy Index your code
hub / github.com/ipython/ipython / extract_code_ranges

Function extract_code_ranges

IPython/core/magics/code.py:57–83  ·  view source on GitHub ↗

Turn a string of range for %%load into 2-tuples of (start, stop) ready to use as a slice of the content split by lines. Examples -------- list(extract_input_ranges("5-10 2")) [(4, 10), (1, 2)]

(ranges_str)

Source from the content-addressed store, hash-verified

55
56
57def extract_code_ranges(ranges_str):
58 """Turn a string of range for %%load into 2-tuples of (start, stop)
59 ready to use as a slice of the content split by lines.
60
61 Examples
62 --------
63 list(extract_input_ranges("5-10 2"))
64 [(4, 10), (1, 2)]
65 """
66 for range_str in ranges_str.split():
67 rmatch = range_re.match(range_str)
68 if not rmatch:
69 continue
70 sep = rmatch.group("sep")
71 start = rmatch.group("start")
72 end = rmatch.group("end")
73
74 if sep == '-':
75 start = int(start) - 1 if start else None
76 end = int(end) if end else None
77 elif sep == ':':
78 start = int(start) - 1 if start else None
79 end = int(end) - 1 if end else None
80 else:
81 end = int(start)
82 start = int(start) - 1
83 yield (start, end)
84
85
86def extract_symbols(code, symbols):

Callers 1

loadMethod · 0.85

Calls 2

matchMethod · 0.80
groupMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…