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

Function split_user_input

IPython/core/splitinput.py:53–78  ·  view source on GitHub ↗

Split user input into initial whitespace, escape character, function part and the rest.

(line, pattern=None)

Source from the content-addressed store, hash-verified

51
52
53def split_user_input(line, pattern=None):
54 """Split user input into initial whitespace, escape character, function part
55 and the rest.
56 """
57 # We need to ensure that the rest of this routine deals only with unicode
58 encoding = get_stream_enc(sys.stdin, 'utf-8')
59 line = py3compat.cast_unicode(line, encoding)
60
61 if pattern is None:
62 pattern = line_split
63 match = pattern.match(line)
64 if not match:
65 # print "match failed for line '%s'" % line
66 try:
67 ifun, the_rest = line.split(None,1)
68 except ValueError:
69 # print "split failed for line '%s'" % line
70 ifun, the_rest = line, u''
71 pre = re.match(r'^(\s*)(.*)',line).groups()[0]
72 esc = ""
73 else:
74 pre, esc, ifun, the_rest = match.groups()
75
76 #print 'line:<%s>' % line # dbg
77 #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest) # dbg
78 return pre, esc or '', ifun.strip(), the_rest.lstrip()
79
80
81class LineInfo(object):

Callers 1

__init__Method · 0.85

Calls 1

get_stream_encFunction · 0.90

Tested by

no test coverage detected