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

login
register
mail settings
Submitter timeless
Date April 15, 2016, 9:22 p.m.
Message ID <573e82339367c562d1ae.1460755333@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/14654/
State Accepted
Commit 2f58975eb2cb9c41bef6358e355ae2e3f7c75af1
Headers show

Comments

timeless - April 15, 2016, 9:22 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1460273306 0
#      Sun Apr 10 07:28:26 2016 +0000
# Node ID 573e82339367c562d1ae0f8ed2b1ad611be8a77e
# Parent  d9539959167df7cb3acd08c4ab53d8e8a7f027cb
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r 573e82339367
store: treat range as a generator instead of a list for py3 compat
Augie Fackler - May 5, 2016, 3:30 a.m.
On Fri, Apr 15, 2016 at 09:22:13PM +0000, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1460273306 0
> #      Sun Apr 10 07:28:26 2016 +0000
> # Node ID 573e82339367c562d1ae0f8ed2b1ad611be8a77e
> # Parent  d9539959167df7cb3acd08c4ab53d8e8a7f027cb
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r 573e82339367
> store: treat range as a generator instead of a list for py3 compat

Queued this, thanks.

>
> diff -r d9539959167d -r 573e82339367 mercurial/store.py
> --- a/mercurial/store.py	Fri Apr 15 20:37:11 2016 +0900
> +++ b/mercurial/store.py	Sun Apr 10 07:28:26 2016 +0000
> @@ -57,6 +57,23 @@
>              .replace(".i.hg/", ".i/")
>              .replace(".hg.hg/", ".hg/"))
>
> +def _reserved():
> +    ''' characters that are problematic for filesystems
> +
> +    * ascii escapes (0..31)
> +    * ascii hi (126..255)
> +    * windows specials
> +
> +    these characters will be escaped by encodefunctions
> +    '''
> +    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 +99,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.iteritems():
> @@ -134,9 +150,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()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r d9539959167d -r 573e82339367 mercurial/store.py
--- a/mercurial/store.py	Fri Apr 15 20:37:11 2016 +0900
+++ b/mercurial/store.py	Sun Apr 10 07:28:26 2016 +0000
@@ -57,6 +57,23 @@ 
             .replace(".i.hg/", ".i/")
             .replace(".hg.hg/", ".hg/"))
 
+def _reserved():
+    ''' characters that are problematic for filesystems
+
+    * ascii escapes (0..31)
+    * ascii hi (126..255)
+    * windows specials
+
+    these characters will be escaped by encodefunctions
+    '''
+    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 +99,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.iteritems():
@@ -134,9 +150,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()