Patchwork [7,of,7] store: treat range as a generator instead of a list for py3 compat

login
register
mail settings
Submitter timeless@mozdev.org
Date April 11, 2016, 10:49 p.m.
Message ID <cb9b085c8911b9896f35.1460414941@waste.org>
Download mbox | patch
Permalink /patch/14536/
State Superseded
Commit 2f58975eb2cb9c41bef6358e355ae2e3f7c75af1
Headers show

Comments

timeless@mozdev.org - April 11, 2016, 10:49 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460273306 0
#      Sun Apr 10 07:28:26 2016 +0000
# Node ID cb9b085c8911b9896f3567593a7cb2e2b1e26852
# Parent  eefe59718f11944738153111debc79f8b926a80a
store: treat range as a generator instead of a list for py3 compat
Pierre-Yves David - April 13, 2016, 7:53 a.m.
On 04/11/2016 03:49 PM, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460273306 0
> #      Sun Apr 10 07:28:26 2016 +0000
> # Node ID cb9b085c8911b9896f3567593a7cb2e2b1e26852
> # Parent  eefe59718f11944738153111debc79f8b926a80a
> store: treat range as a generator instead of a list for py3 compat
>
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -57,6 +57,15 @@
>               .replace(".i.hg/", ".i/")
>               .replace(".hg.hg/", ".hg/"))
>   
> +def _reserved():

Can you document the goal of this function ? That would help people 
reading the code to understand what is going on here (including me).

> +    winreserved = [ord(x) for x in '\\:*?"<>|']
> +    for x in range(32):
> +        yield x
> +    for x in range(126, 256):
> +        yield x
> +    for x in winreserved:
> +        yield x
> +
>   def _buildencodefun():
>       '''
>       >>> enc, dec = _buildencodefun()
> @@ -82,11 +91,10 @@
>       'the\\x07quick\\xadshot'
>       '''
>       e = '_'
> -    winreserved = [ord(x) for x in '\\:*?"<>|']
>       cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
> -    for x in (range(32) + range(126, 256) + winreserved):
> +    for x in _reserved():
>           cmap[chr(x)] = "~%02x" % x
> -    for x in range(ord("A"), ord("Z") + 1) + [ord(e)]:
> +    for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
>           cmap[chr(x)] = e + chr(x).lower()
>       dmap = {}
>       for k, v in cmap.items():
> @@ -134,9 +142,8 @@
>       >>> f('the\x07quick\xADshot')
>       'the~07quick~adshot'
>       '''
> -    winreserved = [ord(x) for x in '\\:*?"<>|']
>       cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
> -    for x in (range(32) + range(126, 256) + winreserved):
> +    for x in _reserved():
>           cmap[chr(x)] = "~%02x" % x
>       for x in range(ord("A"), ord("Z") + 1):
>           cmap[chr(x)] = chr(x).lower()
> diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
> --- a/tests/test-check-py3-compat.t
> +++ b/tests/test-check-py3-compat.t
> @@ -177,8 +177,6 @@
>     mercurial/sshpeer.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
>     mercurial/sshserver.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
>     mercurial/statichttprepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
> -  mercurial/store.py: error importing module: <TypeError> unsupported operand type(s) for +: 'range' and 'range' (line *) (glob)
> -  mercurial/streamclone.py: error importing: <TypeError> unsupported operand type(s) for +: 'range' and 'range' (error at store.py:*) (glob)
>     mercurial/subrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
>     mercurial/templatefilters.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
>     mercurial/templatekw.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -57,6 +57,15 @@ 
             .replace(".i.hg/", ".i/")
             .replace(".hg.hg/", ".hg/"))
 
+def _reserved():
+    winreserved = [ord(x) for x in '\\:*?"<>|']
+    for x in range(32):
+        yield x
+    for x in range(126, 256):
+        yield x
+    for x in winreserved:
+        yield x
+
 def _buildencodefun():
     '''
     >>> enc, dec = _buildencodefun()
@@ -82,11 +91,10 @@ 
     'the\\x07quick\\xadshot'
     '''
     e = '_'
-    winreserved = [ord(x) for x in '\\:*?"<>|']
     cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
-    for x in (range(32) + range(126, 256) + winreserved):
+    for x in _reserved():
         cmap[chr(x)] = "~%02x" % x
-    for x in range(ord("A"), ord("Z") + 1) + [ord(e)]:
+    for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
         cmap[chr(x)] = e + chr(x).lower()
     dmap = {}
     for k, v in cmap.items():
@@ -134,9 +142,8 @@ 
     >>> f('the\x07quick\xADshot')
     'the~07quick~adshot'
     '''
-    winreserved = [ord(x) for x in '\\:*?"<>|']
     cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
-    for x in (range(32) + range(126, 256) + winreserved):
+    for x in _reserved():
         cmap[chr(x)] = "~%02x" % x
     for x in range(ord("A"), ord("Z") + 1):
         cmap[chr(x)] = chr(x).lower()
diff --git a/tests/test-check-py3-compat.t b/tests/test-check-py3-compat.t
--- a/tests/test-check-py3-compat.t
+++ b/tests/test-check-py3-compat.t
@@ -177,8 +177,6 @@ 
   mercurial/sshpeer.py: error importing: <SyntaxError> invalid syntax (bundle*.py, line *) (error at wireproto.py:*) (glob)
   mercurial/sshserver.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
   mercurial/statichttprepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
-  mercurial/store.py: error importing module: <TypeError> unsupported operand type(s) for +: 'range' and 'range' (line *) (glob)
-  mercurial/streamclone.py: error importing: <TypeError> unsupported operand type(s) for +: 'range' and 'range' (error at store.py:*) (glob)
   mercurial/subrepo.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
   mercurial/templatefilters.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)
   mercurial/templatekw.py: error importing: <AttributeError> module 'email' has no attribute 'Header' (error at mail.py:*) (glob)