Patchwork [2,of,8] py3: add os.fsdecode() as pycompat.fsdecode()

login
register
mail settings
Submitter Pulkit Goyal
Date Nov. 5, 2016, 11:16 p.m.
Message ID <972b0c0175fc402ffe8b.1478387779@pulkit-goyal>
Download mbox | patch
Permalink /patch/17354/
State Accepted
Headers show

Comments

Pulkit Goyal - Nov. 5, 2016, 11:16 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1478382160 -19800
#      Sun Nov 06 03:12:40 2016 +0530
# Node ID 972b0c0175fc402ffe8beac276b737b32ce0df0b
# Parent  2d456de3a41ab961da8ae71dfefccdc9d7febe78
py3: add os.fsdecode() as pycompat.fsdecode()

We need to use os.fsdecode() but this was not present in Python 2. So added
the function in pycompat.py
Yuya Nishihara - Nov. 6, 2016, 3:20 a.m.
On Sun, 06 Nov 2016 04:46:19 +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1478382160 -19800
> #      Sun Nov 06 03:12:40 2016 +0530
> # Node ID 972b0c0175fc402ffe8beac276b737b32ce0df0b
> # Parent  2d456de3a41ab961da8ae71dfefccdc9d7febe78
> py3: add os.fsdecode() as pycompat.fsdecode()
> 
> We need to use os.fsdecode() but this was not present in Python 2. So added
> the function in pycompat.py

Queued 1, 2 and 5 as 2 and 1+5, thanks. We can't split 1 and 5 since they
depend on each other.
timeless - Nov. 6, 2016, 9:57 a.m.
Pulkit Goyal wrote:
> +    # In Python 2, fsdecode() have a very chances to recieve bytes. So it's

receive
Yuya Nishihara - Nov. 6, 2016, 12:26 p.m.
On Sun, 6 Nov 2016 04:57:40 -0500, timeless wrote:
> Pulkit Goyal wrote:
> > +    # In Python 2, fsdecode() have a very chances to recieve bytes. So it's
> 
> receive

Fixed as:

    # In Python 2, fsdecode() has a very chance to receive bytes. So it's
    # better not to touch Python 2 part as it's already working fine.

Patch

diff -r 2d456de3a41a -r 972b0c0175fc mercurial/pycompat.py
--- a/mercurial/pycompat.py	Sun Nov 06 02:59:43 2016 +0530
+++ b/mercurial/pycompat.py	Sun Nov 06 03:12:40 2016 +0530
@@ -36,6 +36,7 @@ 
     import functools
     import os
     fsencode = os.fsencode
+    fsdecode = os.fsdecode
 
     def sysstr(s):
         """Return a keyword str to be passed to Python functions such as
@@ -76,6 +77,11 @@ 
             raise TypeError(
                 "expect str, not %s" % type(filename).__name__)
 
+    # In Python 2, fsdecode() have a very chances to recieve bytes. So it's
+    # better not to touch Python 2 part as its already working fine.
+    def fsdecode(filename):
+        return filename
+
 stringio = io.StringIO
 empty = _queue.Empty
 queue = _queue.Queue