On Fri, 03 Mar 2017 15:34:11 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pul...@gmail.com>
> # Date 1488526472 -19800
> #      Fri Mar 03 13:04:32 2017 +0530
> # Node ID e815f7c4026f7e714b6e9bb59dce90020d9c56f2
> # Parent  b4cd912d7704cd976e1bee3a3c927e0e578ec88f
> py3: add pycompat.open and replace open() calls

Queued these with slight modification, thanks.

> --- a/mercurial/pycompat.py   Thu Mar 02 10:12:40 2017 -0800
> +++ b/mercurial/pycompat.py   Fri Mar 03 13:04:32 2017 +0530
> @@ -122,6 +122,9 @@
>          dic = dict((k.encode('latin-1'), v) for k, v in dic.iteritems())
>          return dic
>  
> +    def open(name, mode='r', buffering=-1):
> +        return builtins.open(name, sysstr(mode), buffering)
> +
>      # shlex.split() accepts unicodes on Python 3. This function takes bytes
>      # argument, convert it into unicodes, pass into shlex.split(), convert 
> the
>      # returned value to bytes and return that.
> @@ -131,6 +134,8 @@
>          return [a.encode('latin-1') for a in ret]
>  
>  else:
> +    import __builtin__
> +
>      def sysstr(s):
>          return s
>  
> @@ -170,6 +175,7 @@
>      getcwd = os.getcwd
>      sysexecutable = sys.executable
>      shlexsplit = shlex.split
> +    open = __builtin__.open

Since we use the importer hack, pycompat.open() isn't necessary for py2. I've
adjusted this patch to be more like del/get/has/setattr() wrappers.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to