Show More
@@ -201,7 +201,10 b' class InteractiveShellTestCase(unittest.TestCase):' | |||
|
201 | 201 | |
|
202 | 202 | def test_var_expand(self): |
|
203 | 203 | ip = get_ipython() |
|
204 |
ip.user_ns['f'] = 'Ca\x |
|
|
204 | ip.user_ns['f'] = u'Ca\xf1o' | |
|
205 | self.assertEqual(ip.var_expand(u'echo $f'), u'echo Ca\xf1o') | |
|
206 | ||
|
207 | ip.user_ns['f'] = b'Ca\xc3\xb1o' | |
|
205 | 208 | # This should not raise any exception: |
|
206 | 209 | ip.var_expand(u'echo $f') |
|
207 | 210 |
@@ -107,3 +107,7 b' def test_dollar_formatter():' | |||
|
107 | 107 | nt.assert_equals(s, "12") |
|
108 | 108 | s = f.format("$n/{stuff[:5]}", **ns) |
|
109 | 109 | nt.assert_equals(s, "12/hello") |
|
110 | s = f.format("$n $$HOME", **ns) | |
|
111 | nt.assert_equals(s, "12 $HOME") | |
|
112 | s = f.format("${foo}", foo="HOME") | |
|
113 | nt.assert_equals(s, "$HOME") |
@@ -663,20 +663,26 b' class DollarFormatter(FullEvalFormatter):' | |||
|
663 | 663 | In [4]: f.format('$a or {b}', a=1, b=2) |
|
664 | 664 | Out[4]: u'1 or 2' |
|
665 | 665 | """ |
|
666 | _dollar_pattern = re.compile("(.*)\$([\w\.]+)") | |
|
666 | _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)") | |
|
667 | 667 | def parse(self, fmt_string): |
|
668 | 668 | for literal_txt, field_name, format_spec, conversion \ |
|
669 | 669 | in Formatter.parse(self, fmt_string): |
|
670 | 670 | |
|
671 | 671 | # Find $foo patterns in the literal text. |
|
672 | 672 | continue_from = 0 |
|
673 | txt = "" | |
|
673 | 674 | for m in self._dollar_pattern.finditer(literal_txt): |
|
674 | 675 | new_txt, new_field = m.group(1,2) |
|
675 | yield (new_txt, new_field, "", None) | |
|
676 | # $$foo --> $foo | |
|
677 | if new_field.startswith("$"): | |
|
678 | txt += new_txt + new_field | |
|
679 | else: | |
|
680 | yield (txt + new_txt, new_field, "", None) | |
|
681 | txt = "" | |
|
676 | 682 | continue_from = m.end() |
|
677 | 683 | |
|
678 | 684 | # Re-yield the {foo} style pattern |
|
679 | yield (literal_txt[continue_from:], field_name, format_spec, conversion) | |
|
685 | yield (txt + literal_txt[continue_from:], field_name, format_spec, conversion) | |
|
680 | 686 | |
|
681 | 687 | |
|
682 | 688 | def columnize(items, separator=' ', displaywidth=80): |
General Comments 0
You need to be logged in to leave comments.
Login now