MCPcopy Create free account
hub / github.com/ipython/ipython / extract_code_ranges

Function extract_code_ranges

IPython/core/magics/code.py:55–81  ·  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

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

Callers 1

loadMethod · 0.85

Calls 1

groupMethod · 0.80

Tested by

no test coverage detected