Re: [PATCH 2 of 2] py3: make encodefun in store.py compatible with py3k

2016-10-08 Thread Yuya Nishihara
On Sat, 8 Oct 2016 08:55:46 -0700, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich 
> # Date 1475942045 25200
> #  Sat Oct 08 08:54:05 2016 -0700
> # Node ID 086b25d1866e33fb7ebbe6c51522e6b573e281e2
> # Parent  225efa4bf7f497e55f0ba57f64a33dce39eaeb29
> py3: make encodefun in store.py compatible with py3k
> 
> This ensures that the filename encoding functions always map bytestrings
> to bytestrings regardless of python version.
> 
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -16,6 +16,7 @@ from .i18n import _
>  from . import (
>  error,
>  parsers,
> +pycompat,
>  scmutil,
>  util,
>  )
> @@ -98,11 +99,20 @@ def _buildencodefun():
>  'the\\x07quick\\xadshot'
>  '''
>  e = '_'
> -cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
> +if pycompat.ispy3:
> +xchr = lambda x: bytes([x])
> +asciistr = bytes(xrange(127))
> +else:
> +xchr = chr
> +asciistr = map(chr, xrange(127))
> +capitals = list(range(ord("A"), ord("Z") + 1))
> +
> +cmap = {x:x for x in asciistr}

Dict comprehension isn't available in Python 2.6.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] py3: make encodefun in store.py compatible with py3k

2016-10-08 Thread Augie Fackler
On Sat, Oct 08, 2016 at 08:55:46AM -0700, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich 
> # Date 1475942045 25200
> #  Sat Oct 08 08:54:05 2016 -0700
> # Node ID 086b25d1866e33fb7ebbe6c51522e6b573e281e2
> # Parent  225efa4bf7f497e55f0ba57f64a33dce39eaeb29
> py3: make encodefun in store.py compatible with py3k

Queued thanks

>
> This ensures that the filename encoding functions always map bytestrings
> to bytestrings regardless of python version.
>
> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -16,6 +16,7 @@ from .i18n import _
>  from . import (
>  error,
>  parsers,
> +pycompat,
>  scmutil,
>  util,
>  )
> @@ -98,11 +99,20 @@ def _buildencodefun():
>  'the\\x07quick\\xadshot'
>  '''
>  e = '_'
> -cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
> +if pycompat.ispy3:
> +xchr = lambda x: bytes([x])
> +asciistr = bytes(xrange(127))
> +else:
> +xchr = chr
> +asciistr = map(chr, xrange(127))
> +capitals = list(range(ord("A"), ord("Z") + 1))
> +
> +cmap = {x:x for x in asciistr}
>  for x in _reserved():
> -cmap[chr(x)] = "~%02x" % x
> -for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
> -cmap[chr(x)] = e + chr(x).lower()
> +cmap[xchr(x)] = "~%02x" % x
> +for x in capitals + [ord(e)]:
> +cmap[xchr(x)] = e + xchr(x).lower()
> +
>  dmap = {}
>  for k, v in cmap.iteritems():
>  dmap[v] = k
> 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
> @@ -134,7 +134,6 @@
>mercurial/sshserver.py: error importing:  module 
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/statichttprepo.py: error importing:  module 
> 'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*)
>mercurial/store.py: error importing module:  name 'xrange' is 
> not defined (line *)
> -  mercurial/streamclone.py: error importing:  can't concat bytes 
> to str (error at store.py:*)
>mercurial/subrepo.py: error importing:  module 
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/templatefilters.py: error importing:  module 
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/templatekw.py: error importing:  module 
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
> ___
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 2 of 2] py3: make encodefun in store.py compatible with py3k

2016-10-08 Thread Martijn Pieters
On 8 October 2016 at 17:55, Mateusz Kwapich  wrote:

> # HG changeset patch
> # User Mateusz Kwapich 
> # Date 1475942045 25200
> #  Sat Oct 08 08:54:05 2016 -0700
> # Node ID 086b25d1866e33fb7ebbe6c51522e6b573e281e2
> # Parent  225efa4bf7f497e55f0ba57f64a33dce39eaeb29
> py3: make encodefun in store.py compatible with py3k
>
> This ensures that the filename encoding functions always map bytestrings
> to bytestrings regardless of python version.
>

These two look good.



> diff --git a/mercurial/store.py b/mercurial/store.py
> --- a/mercurial/store.py
> +++ b/mercurial/store.py
> @@ -16,6 +16,7 @@ from .i18n import _
>  from . import (
>  error,
>  parsers,
> +pycompat,
>  scmutil,
>  util,
>  )
> @@ -98,11 +99,20 @@ def _buildencodefun():
>  'the\\x07quick\\xadshot'
>  '''
>  e = '_'
> -cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
> +if pycompat.ispy3:
> +xchr = lambda x: bytes([x])
> +asciistr = bytes(xrange(127))
> +else:
> +xchr = chr
> +asciistr = map(chr, xrange(127))
> +capitals = list(range(ord("A"), ord("Z") + 1))
> +
> +cmap = {x:x for x in asciistr}
>  for x in _reserved():
> -cmap[chr(x)] = "~%02x" % x
> -for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
> -cmap[chr(x)] = e + chr(x).lower()
> +cmap[xchr(x)] = "~%02x" % x
> +for x in capitals + [ord(e)]:
> +cmap[xchr(x)] = e + xchr(x).lower()
> +
>  dmap = {}
>  for k, v in cmap.iteritems():
>  dmap[v] = k
> 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
> @@ -134,7 +134,6 @@
>mercurial/sshserver.py: error importing:  module
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/statichttprepo.py: error importing:  module
> 'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*)
>mercurial/store.py: error importing module:  name 'xrange'
> is not defined (line *)
> -  mercurial/streamclone.py: error importing:  can't concat
> bytes to str (error at store.py:*)
>mercurial/subrepo.py: error importing:  module
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/templatefilters.py: error importing:  module
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
>mercurial/templatekw.py: error importing:  module
> 'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
> ___
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>



-- 
Martijn Pieters
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 2 of 2] py3: make encodefun in store.py compatible with py3k

2016-10-08 Thread Mateusz Kwapich
# HG changeset patch
# User Mateusz Kwapich 
# Date 1475942045 25200
#  Sat Oct 08 08:54:05 2016 -0700
# Node ID 086b25d1866e33fb7ebbe6c51522e6b573e281e2
# Parent  225efa4bf7f497e55f0ba57f64a33dce39eaeb29
py3: make encodefun in store.py compatible with py3k

This ensures that the filename encoding functions always map bytestrings
to bytestrings regardless of python version.

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -16,6 +16,7 @@ from .i18n import _
 from . import (
 error,
 parsers,
+pycompat,
 scmutil,
 util,
 )
@@ -98,11 +99,20 @@ def _buildencodefun():
 'the\\x07quick\\xadshot'
 '''
 e = '_'
-cmap = dict([(chr(x), chr(x)) for x in xrange(127)])
+if pycompat.ispy3:
+xchr = lambda x: bytes([x])
+asciistr = bytes(xrange(127))
+else:
+xchr = chr
+asciistr = map(chr, xrange(127))
+capitals = list(range(ord("A"), ord("Z") + 1))
+
+cmap = {x:x for x in asciistr}
 for x in _reserved():
-cmap[chr(x)] = "~%02x" % x
-for x in list(range(ord("A"), ord("Z") + 1)) + [ord(e)]:
-cmap[chr(x)] = e + chr(x).lower()
+cmap[xchr(x)] = "~%02x" % x
+for x in capitals + [ord(e)]:
+cmap[xchr(x)] = e + xchr(x).lower()
+
 dmap = {}
 for k, v in cmap.iteritems():
 dmap[v] = k
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
@@ -134,7 +134,6 @@
   mercurial/sshserver.py: error importing:  module 
'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/statichttprepo.py: error importing:  module 
'mercurial.util' has no attribute 'urlerr' (error at byterange.py:*)
   mercurial/store.py: error importing module:  name 'xrange' is not 
defined (line *)
-  mercurial/streamclone.py: error importing:  can't concat bytes to 
str (error at store.py:*)
   mercurial/subrepo.py: error importing:  module 
'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/templatefilters.py: error importing:  module 
'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
   mercurial/templatekw.py: error importing:  module 
'mercurial.util' has no attribute 'stringio' (error at patch.py:*)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel