Patchwork [3,of,3,V2] py3: add pycompat.unicode and add it to importer

login
register
mail settings
Submitter Pulkit Goyal
Date April 7, 2017, 6:38 p.m.
Message ID <7ce54c695ff7a5637b67.1491590305@pulkit-goyal>
Download mbox | patch
Permalink /patch/20008/
State Accepted
Headers show

Comments

Pulkit Goyal - April 7, 2017, 6:38 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1491588351 -19800
#      Fri Apr 07 23:35:51 2017 +0530
# Node ID 7ce54c695ff7a5637b6798dec0fc6cf4f7b22098
# Parent  1724a314de7c22936d33b09066e9f06197437391
py3: add pycompat.unicode and add it to importer

On python 3, builtins.unicode does not exist.
Yuya Nishihara - April 8, 2017, 7:38 a.m.
On Sat, 08 Apr 2017 00:08:25 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1491588351 -19800
> #      Fri Apr 07 23:35:51 2017 +0530
> # Node ID 7ce54c695ff7a5637b6798dec0fc6cf4f7b22098
> # Parent  1724a314de7c22936d33b09066e9f06197437391
> py3: add pycompat.unicode and add it to importer

Queued these, thanks.

> @@ -323,7 +324,7 @@
>      # ``replacetoken`` or any mechanism that changes semantics of module
>      # loading is changed. Otherwise cached bytecode may get loaded without
>      # the new transformation mechanisms applied.
> -    BYTECODEHEADER = b'HG\x00\x09'
> +    BYTECODEHEADER = b'HG\x00\x10'

Nit: I did s/10/0a/ in flight.

Patch

diff -r 1724a314de7c -r 7ce54c695ff7 mercurial/__init__.py
--- a/mercurial/__init__.py	Fri Apr 07 16:00:44 2017 +0530
+++ b/mercurial/__init__.py	Fri Apr 07 23:35:51 2017 +0530
@@ -283,7 +283,8 @@ 
                     continue
                 r, c = t.start
                 l = (b'; from mercurial.pycompat import '
-                     b'delattr, getattr, hasattr, setattr, xrange, open\n')
+                     b'delattr, getattr, hasattr, setattr, xrange, '
+                     b'open, unicode\n')
                 for u in tokenize.tokenize(io.BytesIO(l).readline):
                     if u.type in (tokenize.ENCODING, token.ENDMARKER):
                         continue
@@ -323,7 +324,7 @@ 
     # ``replacetoken`` or any mechanism that changes semantics of module
     # loading is changed. Otherwise cached bytecode may get loaded without
     # the new transformation mechanisms applied.
-    BYTECODEHEADER = b'HG\x00\x09'
+    BYTECODEHEADER = b'HG\x00\x10'
 
     class hgloader(importlib.machinery.SourceFileLoader):
         """Custom module loader that transforms source code.
diff -r 1724a314de7c -r 7ce54c695ff7 mercurial/pycompat.py
--- a/mercurial/pycompat.py	Fri Apr 07 16:00:44 2017 +0530
+++ b/mercurial/pycompat.py	Fri Apr 07 23:35:51 2017 +0530
@@ -174,6 +174,7 @@ 
     hasattr = _wrapattrfunc(builtins.hasattr)
     setattr = _wrapattrfunc(builtins.setattr)
     xrange = builtins.range
+    unicode = str
 
     def open(name, mode='r', buffering=-1):
         return builtins.open(name, sysstr(mode), buffering)