Patchwork [6,of,7,v2] import-checker: handle line continuation characters

login
register
mail settings
Submitter timeless@mozdev.org
Date April 13, 2016, 5:21 p.m.
Message ID <4fb9d603c45a64c98061.1460568109@waste.org>
Download mbox | patch
Permalink /patch/14595/
State Rejected
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - April 13, 2016, 5:21 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460495587 0
#      Tue Apr 12 21:13:07 2016 +0000
# Node ID 4fb9d603c45a64c98061abd264b3f691a6f336d0
# Parent  f34b5885cd74f453a0ca5706468584dfecbc5cae
import-checker: handle line continuation characters
Yuya Nishihara - April 15, 2016, 2:45 p.m.
On Wed, 13 Apr 2016 12:21:49 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460495587 0
> #      Tue Apr 12 21:13:07 2016 +0000
> # Node ID 4fb9d603c45a64c98061abd264b3f691a6f336d0
> # Parent  f34b5885cd74f453a0ca5706468584dfecbc5cae
> import-checker: handle line continuation characters

Is it necessary for our .t tests? or for doctests in .py?

I have comment about processing doctests.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -586,12 +586,18 @@ 
     ...   '  $ cat > foo.py <<EOF',
     ...   '  > from __future__ import print_function',
     ...   '  > EOF',
+    ...   'comment',
+    ...   '  >>> from __future__ import print_function\\\\',
+    ...   '      , absolute_import',
+    ...   '  ',
     ... ]
     >>> test("example.t", lines)
     example[2] doctest.py 2
     "from __future__ import print_function\\n' multiline\\nstring'\\n"
     example[7] foo.py 7
     'from __future__ import print_function\\n'
+    example[11] doctest.py 11
+    'from __future__ import print_function\\\\\\n, absolute_import\\n'
     """
     inlinepython = 0
     shpython = 0
@@ -599,6 +605,7 @@ 
     prefix = 6
     t = ''
     n = 0
+    linecont = False
     for l in src:
         n += 1
         if not l.endswith(b'\n'):
@@ -611,9 +618,11 @@ 
                 inlinepython = n
                 t = 'doctest.py'
             script.append(l[prefix:])
+            linecont = l.strip('\n').endswith('\\')
             continue
         if l.startswith(b'  ... '): # python inlines
             script.append(l[prefix:])
+            linecont = l.strip('\n').endswith('\\')
             continue
         cat = re.search("\$ \s*cat\s*>\s*(\S+.py)\s*<<\s*EOF", l)
         if cat:
@@ -622,6 +631,7 @@ 
                        (modname, inlinepython)), t, inlinepython
                 script = []
                 inlinepython = 0
+                linecont = False
             shpython = n
             t = cat.group(1)
             continue
@@ -631,14 +641,20 @@ 
                        (modname, shpython)), t, shpython
                 script = []
                 shpython = 0
+                linecont = False
             else:
                 script.append(l[4:])
             continue
-        if inlinepython and l == b'  \n':
+        if inlinepython and l.strip() == b'':
             yield ''.join(script), ("%s[%d]" %
                    (modname, inlinepython)), t, inlinepython
             script = []
             inlinepython = 0
+            linecont = False
+            continue
+        if linecont:
+            script.append(l[prefix:])
+            linecont = l.strip('\n').endswith('\\')
             continue
 
 def sources(f, modname):