Mercurial > hg-stable
comparison mercurial/pycompat.py @ 31777:7d2cbe11ae48
pycompat: introduce identity function as a compat stub
I was sometimes too lazy to use 'str' instead of 'lambda a: a'. Let's add
a named function for that purpose.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 29 Mar 2017 21:13:55 +0900 |
parents | 55c6788c54e2 |
children | 8181f378b073 |
comparison
equal
deleted
inserted
replaced
31776:5646d7bcd823 | 31777:7d2cbe11ae48 |
---|---|
27 import http.client as httplib | 27 import http.client as httplib |
28 import pickle | 28 import pickle |
29 import queue as _queue | 29 import queue as _queue |
30 import socketserver | 30 import socketserver |
31 import xmlrpc.client as xmlrpclib | 31 import xmlrpc.client as xmlrpclib |
32 | |
33 def identity(a): | |
34 return a | |
32 | 35 |
33 if ispy3: | 36 if ispy3: |
34 import builtins | 37 import builtins |
35 import functools | 38 import functools |
36 import io | 39 import io |
204 import cStringIO | 207 import cStringIO |
205 | 208 |
206 bytechr = chr | 209 bytechr = chr |
207 bytestr = str | 210 bytestr = str |
208 iterbytestr = iter | 211 iterbytestr = iter |
209 | 212 sysstr = identity |
210 def sysstr(s): | |
211 return s | |
212 | 213 |
213 # Partial backport from os.py in Python 3, which only accepts bytes. | 214 # Partial backport from os.py in Python 3, which only accepts bytes. |
214 # In Python 2, our paths should only ever be bytes, a unicode path | 215 # In Python 2, our paths should only ever be bytes, a unicode path |
215 # indicates a bug. | 216 # indicates a bug. |
216 def fsencode(filename): | 217 def fsencode(filename): |
220 raise TypeError( | 221 raise TypeError( |
221 "expect str, not %s" % type(filename).__name__) | 222 "expect str, not %s" % type(filename).__name__) |
222 | 223 |
223 # In Python 2, fsdecode() has a very chance to receive bytes. So it's | 224 # In Python 2, fsdecode() has a very chance to receive bytes. So it's |
224 # better not to touch Python 2 part as it's already working fine. | 225 # better not to touch Python 2 part as it's already working fine. |
225 def fsdecode(filename): | 226 fsdecode = identity |
226 return filename | |
227 | 227 |
228 def getoptb(args, shortlist, namelist): | 228 def getoptb(args, shortlist, namelist): |
229 return getopt.getopt(args, shortlist, namelist) | 229 return getopt.getopt(args, shortlist, namelist) |
230 | 230 |
231 def strkwargs(dic): | 231 strkwargs = identity |
232 return dic | 232 byteskwargs = identity |
233 | |
234 def byteskwargs(dic): | |
235 return dic | |
236 | 233 |
237 osname = os.name | 234 osname = os.name |
238 ospathsep = os.pathsep | 235 ospathsep = os.pathsep |
239 ossep = os.sep | 236 ossep = os.sep |
240 osaltsep = os.altsep | 237 osaltsep = os.altsep |