--- a/mercurial/pycompat.py Sat Oct 05 10:29:34 2019 -0400
+++ b/mercurial/pycompat.py Sun Oct 06 09:45:02 2019 -0400
@@ -17,8 +17,8 @@
import sys
import tempfile
-ispy3 = (sys.version_info[0] >= 3)
-ispypy = (r'__pypy__' in sys.builtin_module_names)
+ispy3 = sys.version_info[0] >= 3
+ispypy = r'__pypy__' in sys.builtin_module_names
if not ispy3:
import cookielib
@@ -32,6 +32,8 @@
def future_set_exception_info(f, exc_info):
f.set_exception_info(*exc_info)
+
+
else:
import concurrent.futures as futures
import http.cookiejar as cookielib
@@ -44,9 +46,11 @@
def future_set_exception_info(f, exc_info):
f.set_exception(exc_info[0])
+
def identity(a):
return a
+
def _rapply(f, xs):
if xs is None:
# assume None means non-value of optional data
@@ -57,6 +61,7 @@
return type(xs)((_rapply(f, k), _rapply(f, v)) for k, v in xs.items())
return f(xs)
+
def rapply(f, xs):
"""Apply function recursively to every item preserving the data structure
@@ -80,6 +85,7 @@
return xs
return _rapply(f, xs)
+
if ispy3:
import builtins
import functools
@@ -195,8 +201,11 @@
def __new__(cls, s=b''):
if isinstance(s, bytestr):
return s
- if (not isinstance(s, (bytes, bytearray))
- and not hasattr(s, u'__bytes__')): # hasattr-py3-only
+ if not isinstance(
+ s, (bytes, bytearray)
+ ) and not hasattr( # hasattr-py3-only
+ s, u'__bytes__'
+ ):
s = str(s).encode(u'ascii')
return bytes.__new__(cls, s)
@@ -270,6 +279,7 @@
@functools.wraps(f)
def w(object, name, *args):
return f(object, sysstr(name), *args)
+
return w
# these wrappers are automagically imported by hgloader
@@ -296,8 +306,7 @@
shortlist = shortlist.decode('latin-1')
namelist = [a.decode('latin-1') for a in namelist]
opts, args = orig(args, shortlist, namelist)
- opts = [(a[0].encode('latin-1'), a[1].encode('latin-1'))
- for a in opts]
+ opts = [(a[0].encode('latin-1'), a[1].encode('latin-1')) for a in opts]
args = [a.encode('latin-1') for a in args]
return opts, args
@@ -347,8 +356,7 @@
bytesurl = identity
# this can't be parsed on Python 3
- exec('def raisewithtb(exc, tb):\n'
- ' raise exc, None, tb\n')
+ exec('def raisewithtb(exc, tb):\n' ' raise exc, None, tb\n')
def fsencode(filename):
"""
@@ -359,8 +367,7 @@
if isinstance(filename, str):
return filename
else:
- raise TypeError(
- r"expect str, not %s" % type(filename).__name__)
+ raise TypeError(r"expect str, not %s" % type(filename).__name__)
# 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.
@@ -412,23 +419,30 @@
isposix = osname == b'posix'
iswindows = osname == b'nt'
+
def getoptb(args, shortlist, namelist):
return _getoptbwrapper(getopt.getopt, args, shortlist, namelist)
+
def gnugetoptb(args, shortlist, namelist):
return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
+
def mkdtemp(suffix=b'', prefix=b'tmp', dir=None):
return tempfile.mkdtemp(suffix, prefix, dir)
+
# text=True is not supported; use util.from/tonativeeol() instead
def mkstemp(suffix=b'', prefix=b'tmp', dir=None):
return tempfile.mkstemp(suffix, prefix, dir)
+
# mode must include 'b'ytes as encoding= is not supported
-def namedtempfile(mode=b'w+b', bufsize=-1, suffix=b'', prefix=b'tmp', dir=None,
- delete=True):
+def namedtempfile(
+ mode=b'w+b', bufsize=-1, suffix=b'', prefix=b'tmp', dir=None, delete=True
+):
mode = sysstr(mode)
assert r'b' in mode
- return tempfile.NamedTemporaryFile(mode, bufsize, suffix=suffix,
- prefix=prefix, dir=dir, delete=delete)
+ return tempfile.NamedTemporaryFile(
+ mode, bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete
+ )