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

timeless timeless at mozdev.org
Mon Apr 11 18:49:01 EDT 2016


# HG changeset patch
# User timeless <timeless at 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():
+    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)


More information about the Mercurial-devel mailing list