Show More
@@ -5,7 +5,6 b' from __future__ import absolute_import, ' | |||
|
5 | 5 | import ast |
|
6 | 6 | import collections |
|
7 | 7 | import os |
|
8 | import re | |
|
9 | 8 | import sys |
|
10 | 9 | |
|
11 | 10 | # Import a minimal set of stdlib modules needed for list_stdlib_modules() |
@@ -18,6 +17,8 b' if True: # disable lexical sorting check' | |||
|
18 | 17 | basehttpserver = None |
|
19 | 18 | import zlib |
|
20 | 19 | |
|
20 | import testparseutil | |
|
21 | ||
|
21 | 22 | # Whitelist of modules that symbols can be directly imported from. |
|
22 | 23 | allowsymbolimports = ( |
|
23 | 24 | '__future__', |
@@ -659,61 +660,21 b' def embedded(f, modname, src):' | |||
|
659 | 660 | ... b' > EOF', |
|
660 | 661 | ... ] |
|
661 | 662 | >>> test(b"example.t", lines) |
|
662 |
example[2] doctest.py |
|
|
663 | "from __future__ import print_function\\n' multiline\\nstring'\\n" | |
|
664 |
example[ |
|
|
663 | example[2] doctest.py 1 | |
|
664 | "from __future__ import print_function\\n' multiline\\nstring'\\n\\n" | |
|
665 | example[8] foo.py 7 | |
|
665 | 666 | 'from __future__ import print_function\\n' |
|
666 | 667 | """ |
|
667 | inlinepython = 0 | |
|
668 | shpython = 0 | |
|
669 | script = [] | |
|
670 | prefix = 6 | |
|
671 | t = '' | |
|
672 | n = 0 | |
|
673 | for l in src: | |
|
674 | n += 1 | |
|
675 | if not l.endswith(b'\n'): | |
|
676 | l += b'\n' | |
|
677 | if l.startswith(b' >>> '): # python inlines | |
|
678 | if shpython: | |
|
679 | print("%s:%d: Parse Error" % (f, n)) | |
|
680 | if not inlinepython: | |
|
681 | # We've just entered a Python block. | |
|
682 | inlinepython = n | |
|
683 | t = b'doctest.py' | |
|
684 | script.append(l[prefix:]) | |
|
685 | continue | |
|
686 | if l.startswith(b' ... '): # python inlines | |
|
687 | script.append(l[prefix:]) | |
|
688 | continue | |
|
689 | cat = re.search(br"\$ \s*cat\s*>\s*(\S+\.py)\s*<<\s*EOF", l) | |
|
690 | if cat: | |
|
691 | if inlinepython: | |
|
692 | yield b''.join(script), (b"%s[%d]" % | |
|
693 | (modname, inlinepython)), t, inlinepython | |
|
694 | script = [] | |
|
695 | inlinepython = 0 | |
|
696 | shpython = n | |
|
697 | t = cat.group(1) | |
|
698 | continue | |
|
699 | if shpython and l.startswith(b' > '): # sh continuation | |
|
700 | if l == b' > EOF\n': | |
|
701 | yield b''.join(script), (b"%s[%d]" % | |
|
702 | (modname, shpython)), t, shpython | |
|
703 | script = [] | |
|
704 | shpython = 0 | |
|
705 | else: | |
|
706 | script.append(l[4:]) | |
|
707 | continue | |
|
708 | # If we have an empty line or a command for sh, we end the | |
|
709 | # inline script. | |
|
710 | if inlinepython and (l == b' \n' | |
|
711 | or l.startswith(b' $ ')): | |
|
712 | yield b''.join(script), (b"%s[%d]" % | |
|
713 | (modname, inlinepython)), t, inlinepython | |
|
714 | script = [] | |
|
715 | inlinepython = 0 | |
|
716 | continue | |
|
668 | errors = [] | |
|
669 | for name, starts, ends, code in testparseutil.pyembedded(f, src, errors): | |
|
670 | if not name: | |
|
671 | # use 'doctest.py', in order to make already existing | |
|
672 | # doctest above pass instantly | |
|
673 | name = 'doctest.py' | |
|
674 | # "starts" is "line number" (1-origin), but embedded() is | |
|
675 | # expected to return "line offset" (0-origin). Therefore, this | |
|
676 | # yields "starts - 1". | |
|
677 | yield code, "%s[%d]" % (modname, starts), name, starts - 1 | |
|
717 | 678 | |
|
718 | 679 | def sources(f, modname): |
|
719 | 680 | """Yields possibly multiple sources from a filepath |
General Comments 0
You need to be logged in to leave comments.
Login now