Show More
@@ -516,9 +516,17 b' def strip_encoding_cookie():' | |||||
516 | while line is not None: |
|
516 | while line is not None: | |
517 | line = (yield line) |
|
517 | line = (yield line) | |
518 |
|
518 | |||
|
519 | _assign_pat = \ | |||
|
520 | r'''(?P<lhs>(\s*) | |||
|
521 | ([\w\.]+) # Initial identifier | |||
|
522 | (\s*,\s* | |||
|
523 | \*?[\w\.]+)* # Further identifiers for unpacking | |||
|
524 | \s*?,? # Trailing comma | |||
|
525 | ) | |||
|
526 | \s*=\s* | |||
|
527 | ''' | |||
519 |
|
528 | |||
520 | assign_system_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))' |
|
529 | assign_system_re = re.compile(r'{}!\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE) | |
521 | r'\s*=\s*!\s*(?P<cmd>.*)') |
|
|||
522 | assign_system_template = '%s = get_ipython().getoutput(%r)' |
|
530 | assign_system_template = '%s = get_ipython().getoutput(%r)' | |
523 | @StatelessInputTransformer.wrap |
|
531 | @StatelessInputTransformer.wrap | |
524 | def assign_from_system(line): |
|
532 | def assign_from_system(line): | |
@@ -529,8 +537,7 b' def assign_from_system(line):' | |||||
529 |
|
537 | |||
530 | return assign_system_template % m.group('lhs', 'cmd') |
|
538 | return assign_system_template % m.group('lhs', 'cmd') | |
531 |
|
539 | |||
532 | assign_magic_re = re.compile(r'(?P<lhs>(\s*)([\w\.]+)((\s*,\s*[\w\.]+)*))' |
|
540 | assign_magic_re = re.compile(r'{}%\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE) | |
533 | r'\s*=\s*%\s*(?P<cmd>.*)') |
|
|||
534 | assign_magic_template = '%s = get_ipython().magic(%r)' |
|
541 | assign_magic_template = '%s = get_ipython().magic(%r)' | |
535 | @StatelessInputTransformer.wrap |
|
542 | @StatelessInputTransformer.wrap | |
536 | def assign_from_magic(line): |
|
543 | def assign_from_magic(line): |
@@ -41,16 +41,29 b' syntax = \\' | |||||
41 | [(i,py3compat.u_format(o)) for i,o in \ |
|
41 | [(i,py3compat.u_format(o)) for i,o in \ | |
42 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), |
|
42 | [(u'a =! ls', "a = get_ipython().getoutput({u}'ls')"), | |
43 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), |
|
43 | (u'b = !ls', "b = get_ipython().getoutput({u}'ls')"), | |
|
44 | (u'c= !ls', "c = get_ipython().getoutput({u}'ls')"), | |||
|
45 | (u'd == !ls', u'd == !ls'), # Invalid syntax, but we leave == alone. | |||
44 | ('x=1', 'x=1'), # normal input is unmodified |
|
46 | ('x=1', 'x=1'), # normal input is unmodified | |
45 | (' ',' '), # blank lines are kept intact |
|
47 | (' ',' '), # blank lines are kept intact | |
|
48 | # Tuple unpacking | |||
|
49 | (u"a, b = !echo 'a\\nb'", u"a, b = get_ipython().getoutput({u}\"echo 'a\\\\nb'\")"), | |||
|
50 | (u"a,= !echo 'a'", u"a, = get_ipython().getoutput({u}\"echo 'a'\")"), | |||
|
51 | (u"a, *bc = !echo 'a\\nb\\nc'", u"a, *bc = get_ipython().getoutput({u}\"echo 'a\\\\nb\\\\nc'\")"), | |||
|
52 | # Tuple unpacking with regular Python expressions, not our syntax. | |||
|
53 | (u"a, b = range(2)", u"a, b = range(2)"), | |||
|
54 | (u"a, = range(1)", u"a, = range(1)"), | |||
|
55 | (u"a, *bc = range(3)", u"a, *bc = range(3)"), | |||
46 | ]], |
|
56 | ]], | |
47 |
|
57 | |||
48 | assign_magic = |
|
58 | assign_magic = | |
49 | [(i,py3compat.u_format(o)) for i,o in \ |
|
59 | [(i,py3compat.u_format(o)) for i,o in \ | |
50 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), |
|
60 | [(u'a =% who', "a = get_ipython().magic({u}'who')"), | |
51 | (u'b = %who', "b = get_ipython().magic({u}'who')"), |
|
61 | (u'b = %who', "b = get_ipython().magic({u}'who')"), | |
|
62 | (u'c= %ls', "c = get_ipython().magic({u}'ls')"), | |||
|
63 | (u'd == %ls', u'd == %ls'), # Invalid syntax, but we leave == alone. | |||
52 | ('x=1', 'x=1'), # normal input is unmodified |
|
64 | ('x=1', 'x=1'), # normal input is unmodified | |
53 | (' ',' '), # blank lines are kept intact |
|
65 | (' ',' '), # blank lines are kept intact | |
|
66 | (u"a, b = %foo", u"a, b = get_ipython().magic({u}'foo')"), | |||
54 | ]], |
|
67 | ]], | |
55 |
|
68 | |||
56 | classic_prompt = |
|
69 | classic_prompt = |
General Comments 0
You need to be logged in to leave comments.
Login now