Commit d8be3ad8 authored by Stefan Behnel's avatar Stefan Behnel

fix exception in cython.inline() when text block to dedent starts without initial indentation

parent 762b3151
......@@ -221,27 +221,29 @@ def __invoke(%(params)s):
# overridden with actual value upon the first cython_inline invocation
cython_inline.so_ext = None
non_space = re.compile('[^ ]')
_find_non_space = re.compile('[^ ]').search
def strip_common_indent(code):
min_indent = None
lines = code.split('\n')
lines = code.splitlines()
for line in lines:
match = non_space.search(line)
match = _find_non_space(line)
if not match:
continue # blank
continue # blank
indent = match.start()
if line[indent] == '#':
continue # comment
elif min_indent is None or min_indent > indent:
continue # comment
if min_indent is None or min_indent > indent:
min_indent = indent
for ix, line in enumerate(lines):
match = non_space.search(line)
if not match or line[indent] == '#':
match = _find_non_space(line)
if not match or not line or line[indent:indent+1] == '#':
continue
else:
lines[ix] = line[min_indent:]
lines[ix] = line[min_indent:]
return '\n'.join(lines)
module_statement = re.compile(r'^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))')
def extract_func_code(code):
module = []
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment