comparison mercurial/pycompat.py @ 30300:42af0590f4b9

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
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 06 Nov 2016 03:12:40 +0530
parents f6dcda7505f9
children 3874ddba1ab4
comparison
equal deleted inserted replaced
30299:1e5346313963 30300:42af0590f4b9
34 if ispy3: 34 if ispy3:
35 import builtins 35 import builtins
36 import functools 36 import functools
37 import os 37 import os
38 fsencode = os.fsencode 38 fsencode = os.fsencode
39 fsdecode = os.fsdecode
39 40
40 def sysstr(s): 41 def sysstr(s):
41 """Return a keyword str to be passed to Python functions such as 42 """Return a keyword str to be passed to Python functions such as
42 getattr() and str.encode() 43 getattr() and str.encode()
43 44
73 if isinstance(filename, str): 74 if isinstance(filename, str):
74 return filename 75 return filename
75 else: 76 else:
76 raise TypeError( 77 raise TypeError(
77 "expect str, not %s" % type(filename).__name__) 78 "expect str, not %s" % type(filename).__name__)
79
80 # In Python 2, fsdecode() has a very chance to receive bytes. So it's
81 # better not to touch Python 2 part as it's already working fine.
82 def fsdecode(filename):
83 return filename
78 84
79 stringio = io.StringIO 85 stringio = io.StringIO
80 empty = _queue.Empty 86 empty = _queue.Empty
81 queue = _queue.Queue 87 queue = _queue.Queue
82 88