Show More
@@ -19,7 +19,6 b' except ImportError:' | |||||
19 | # Python 2 backport |
|
19 | # Python 2 backport | |
20 | from pathlib2 import Path |
|
20 | from pathlib2 import Path | |
21 |
|
21 | |||
22 | from IPython.testing.skipdoctest import skip_doctest |
|
|||
23 | from IPython.utils import py3compat |
|
22 | from IPython.utils import py3compat | |
24 |
|
23 | |||
25 | # datetime.strftime date format for ipython |
|
24 | # datetime.strftime date format for ipython | |
@@ -516,7 +515,6 b' class EvalFormatter(Formatter):' | |||||
516 | # inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and |
|
515 | # inside [], so EvalFormatter can handle slicing. Once we only support 3.4 and | |
517 | # above, it should be possible to remove FullEvalFormatter. |
|
516 | # above, it should be possible to remove FullEvalFormatter. | |
518 |
|
517 | |||
519 | @skip_doctest |
|
|||
520 | class FullEvalFormatter(Formatter): |
|
518 | class FullEvalFormatter(Formatter): | |
521 | """A String Formatter that allows evaluation of simple expressions. |
|
519 | """A String Formatter that allows evaluation of simple expressions. | |
522 |
|
520 | |||
@@ -532,13 +530,13 b' class FullEvalFormatter(Formatter):' | |||||
532 |
|
530 | |||
533 | In [1]: f = FullEvalFormatter() |
|
531 | In [1]: f = FullEvalFormatter() | |
534 | In [2]: f.format('{n//4}', n=8) |
|
532 | In [2]: f.format('{n//4}', n=8) | |
535 |
Out[2]: |
|
533 | Out[2]: '2' | |
536 |
|
534 | |||
537 | In [3]: f.format('{list(range(5))[2:4]}') |
|
535 | In [3]: f.format('{list(range(5))[2:4]}') | |
538 |
Out[3]: |
|
536 | Out[3]: '[2, 3]' | |
539 |
|
537 | |||
540 | In [4]: f.format('{3*2}') |
|
538 | In [4]: f.format('{3*2}') | |
541 |
Out[4]: |
|
539 | Out[4]: '6' | |
542 | """ |
|
540 | """ | |
543 | # copied from Formatter._vformat with minor changes to allow eval |
|
541 | # copied from Formatter._vformat with minor changes to allow eval | |
544 | # and replace the format_spec code with slicing |
|
542 | # and replace the format_spec code with slicing | |
@@ -573,7 +571,6 b' class FullEvalFormatter(Formatter):' | |||||
573 | return u''.join(py3compat.cast_unicode(s) for s in result) |
|
571 | return u''.join(py3compat.cast_unicode(s) for s in result) | |
574 |
|
572 | |||
575 |
|
573 | |||
576 | @skip_doctest |
|
|||
577 | class DollarFormatter(FullEvalFormatter): |
|
574 | class DollarFormatter(FullEvalFormatter): | |
578 | """Formatter allowing Itpl style $foo replacement, for names and attribute |
|
575 | """Formatter allowing Itpl style $foo replacement, for names and attribute | |
579 | access only. Standard {foo} replacement also works, and allows full |
|
576 | access only. Standard {foo} replacement also works, and allows full | |
@@ -585,13 +582,13 b' class DollarFormatter(FullEvalFormatter):' | |||||
585 |
|
582 | |||
586 | In [1]: f = DollarFormatter() |
|
583 | In [1]: f = DollarFormatter() | |
587 | In [2]: f.format('{n//4}', n=8) |
|
584 | In [2]: f.format('{n//4}', n=8) | |
588 |
Out[2]: |
|
585 | Out[2]: '2' | |
589 |
|
586 | |||
590 | In [3]: f.format('23 * 76 is $result', result=23*76) |
|
587 | In [3]: f.format('23 * 76 is $result', result=23*76) | |
591 |
Out[3]: |
|
588 | Out[3]: '23 * 76 is 1748' | |
592 |
|
589 | |||
593 | In [4]: f.format('$a or {b}', a=1, b=2) |
|
590 | In [4]: f.format('$a or {b}', a=1, b=2) | |
594 |
Out[4]: |
|
591 | Out[4]: '1 or 2' | |
595 | """ |
|
592 | """ | |
596 | _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)") |
|
593 | _dollar_pattern = re.compile("(.*?)\$(\$?[\w\.]+)") | |
597 | def parse(self, fmt_string): |
|
594 | def parse(self, fmt_string): |
General Comments 0
You need to be logged in to leave comments.
Login now