2019-11-01 22:33:28 +03:00
|
|
|
# Portions Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
2016-04-06 23:00:49 +03:00
|
|
|
# pycompat.py - portability shim for python 3
|
|
|
|
#
|
2019-11-01 22:33:28 +03:00
|
|
|
# Copyright Matt Mackall <mpm@selenic.com> and others
|
|
|
|
#
|
2016-04-06 23:00:49 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
|
|
|
|
"""Mercurial portability shim for python 3.
|
|
|
|
|
|
|
|
This contains aliases to hide python version-specific details from the core.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2018-05-26 03:39:09 +03:00
|
|
|
import errno
|
2016-12-06 04:06:36 +03:00
|
|
|
import getopt
|
2016-11-06 01:03:22 +03:00
|
|
|
import os
|
2016-12-25 00:36:55 +03:00
|
|
|
import shlex
|
2016-07-17 17:18:04 +03:00
|
|
|
import sys
|
2016-06-04 12:08:00 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
|
|
|
ispypy = r"__pypy__" in sys.builtin_module_names
|
2016-09-28 14:01:23 +03:00
|
|
|
|
2019-12-05 04:02:25 +03:00
|
|
|
if sys.version_info[0] < 3:
|
2017-03-10 08:35:21 +03:00
|
|
|
import cookielib
|
2019-12-04 21:53:06 +03:00
|
|
|
|
2016-07-17 17:18:04 +03:00
|
|
|
import cPickle as pickle
|
2019-12-04 21:53:06 +03:00
|
|
|
|
2016-06-28 13:31:53 +03:00
|
|
|
import httplib
|
2019-12-04 21:53:06 +03:00
|
|
|
|
2016-07-17 17:18:04 +03:00
|
|
|
import Queue as _queue
|
2019-12-04 21:53:06 +03:00
|
|
|
|
2016-06-27 14:18:54 +03:00
|
|
|
import SocketServer as socketserver
|
2016-07-17 17:18:04 +03:00
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
import http.cookiejar as cookielib # noqa: F401
|
|
|
|
import http.client as httplib # noqa: F401
|
|
|
|
import pickle # noqa: F401
|
2016-04-06 23:00:49 +03:00
|
|
|
import queue as _queue
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
import socketserver # noqa: F401
|
2016-07-17 17:18:04 +03:00
|
|
|
|
2017-06-16 00:31:22 +03:00
|
|
|
empty = _queue.Empty
|
2019-09-27 01:28:09 +03:00
|
|
|
queue = _queue
|
2017-06-16 00:31:22 +03:00
|
|
|
|
2020-01-30 00:43:25 +03:00
|
|
|
basestring = tuple({type(""), type(b""), type(u"")})
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-03-29 15:13:55 +03:00
|
|
|
def identity(a):
|
|
|
|
return a
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2019-12-05 04:02:25 +03:00
|
|
|
if sys.version_info[0] >= 3:
|
2016-08-14 06:41:54 +03:00
|
|
|
import builtins
|
2016-08-14 06:51:21 +03:00
|
|
|
import functools
|
2017-03-12 22:54:11 +03:00
|
|
|
import io
|
2017-03-15 19:30:50 +03:00
|
|
|
import struct
|
2017-03-12 22:54:11 +03:00
|
|
|
|
2020-01-29 18:38:41 +03:00
|
|
|
fsencode = identity
|
|
|
|
fsdecode = identity
|
2020-01-28 21:21:58 +03:00
|
|
|
oslinesep = os.linesep
|
|
|
|
osname = os.name
|
|
|
|
ospathsep = os.pathsep
|
|
|
|
ossep = os.sep
|
2016-12-17 22:14:21 +03:00
|
|
|
osaltsep = os.altsep
|
2020-01-28 21:21:58 +03:00
|
|
|
getcwd = os.getcwd
|
|
|
|
sysplatform = sys.platform
|
2016-12-19 21:32:24 +03:00
|
|
|
sysexecutable = sys.executable
|
2017-03-12 22:25:14 +03:00
|
|
|
stringio = io.BytesIO
|
2017-03-19 21:12:38 +03:00
|
|
|
maplist = lambda *args: list(map(*args))
|
2017-12-11 03:26:35 +03:00
|
|
|
ziplist = lambda *args: list(zip(*args))
|
2017-08-16 07:54:24 +03:00
|
|
|
rawinput = input
|
2019-12-05 04:02:25 +03:00
|
|
|
range = range
|
2016-11-09 16:06:09 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
stdin = sys.stdin
|
|
|
|
stdout = sys.stdout
|
|
|
|
stderr = sys.stderr
|
2016-09-28 16:32:09 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
sysargv = sys.argv
|
2017-06-15 22:02:52 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
bytechr = chr
|
|
|
|
bytestr = str
|
|
|
|
iterbytestr = iter
|
|
|
|
sysbytes = identity
|
|
|
|
sysstr = identity
|
|
|
|
strurl = identity
|
|
|
|
bytesurl = identity
|
2017-06-15 22:06:17 +03:00
|
|
|
|
2017-04-20 16:16:12 +03:00
|
|
|
def raisewithtb(exc, tb):
|
|
|
|
"""Raise exception with the given traceback"""
|
|
|
|
raise exc.with_traceback(tb)
|
|
|
|
|
2017-06-01 16:24:15 +03:00
|
|
|
def getdoc(obj):
|
|
|
|
"""Get docstring as bytes; may be None so gettext() won't confuse it
|
|
|
|
with _('')"""
|
2019-07-27 06:34:57 +03:00
|
|
|
if isinstance(obj, str):
|
|
|
|
return obj
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
doc = getattr(obj, u"__doc__", None)
|
2017-06-01 16:24:15 +03:00
|
|
|
if doc is None:
|
|
|
|
return doc
|
|
|
|
return sysbytes(doc)
|
|
|
|
|
2017-04-07 21:05:51 +03:00
|
|
|
unicode = str
|
2016-08-14 06:51:21 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
strkwargs = identity
|
|
|
|
byteskwargs = identity
|
|
|
|
shlexsplit = shlex.split
|
2016-12-07 19:23:03 +03:00
|
|
|
|
2020-01-29 18:38:41 +03:00
|
|
|
def encodeutf8(s):
|
|
|
|
# type: (str) -> bytes
|
|
|
|
return s.encode("utf-8")
|
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
def decodeutf8(s):
|
|
|
|
# type: (bytes) -> str
|
|
|
|
return s.decode("utf-8")
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2020-01-29 03:25:29 +03:00
|
|
|
def iteritems(s):
|
|
|
|
return s.items()
|
|
|
|
|
|
|
|
def iterkeys(s):
|
|
|
|
return s.keys()
|
|
|
|
|
|
|
|
def itervalues(s):
|
|
|
|
return s.values()
|
|
|
|
|
2016-12-25 00:36:55 +03:00
|
|
|
|
2016-09-28 16:32:09 +03:00
|
|
|
else:
|
2017-03-12 22:54:11 +03:00
|
|
|
import cStringIO
|
|
|
|
|
2017-03-08 16:30:12 +03:00
|
|
|
bytechr = chr
|
2017-03-08 16:48:26 +03:00
|
|
|
bytestr = str
|
2017-03-13 03:04:45 +03:00
|
|
|
iterbytestr = iter
|
2017-04-04 18:34:58 +03:00
|
|
|
sysbytes = identity
|
2017-03-29 15:13:55 +03:00
|
|
|
sysstr = identity
|
2017-06-15 22:02:52 +03:00
|
|
|
strurl = identity
|
2017-06-15 22:06:17 +03:00
|
|
|
bytesurl = identity
|
2019-09-27 01:28:09 +03:00
|
|
|
range = xrange # noqa: F821
|
2019-12-05 04:02:25 +03:00
|
|
|
unicode = unicode
|
2016-09-28 16:32:09 +03:00
|
|
|
|
2017-04-20 16:16:12 +03:00
|
|
|
# this can't be parsed on Python 3
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
exec("def raisewithtb(exc, tb):\n" " raise exc, None, tb\n")
|
2017-04-20 16:16:12 +03:00
|
|
|
|
2016-10-11 01:11:15 +03:00
|
|
|
def fsencode(filename):
|
2017-06-16 00:18:17 +03:00
|
|
|
"""
|
|
|
|
Partial backport from os.py in Python 3, which only accepts bytes.
|
|
|
|
In Python 2, our paths should only ever be bytes, a unicode path
|
|
|
|
indicates a bug.
|
|
|
|
"""
|
2016-10-11 01:11:15 +03:00
|
|
|
if isinstance(filename, str):
|
|
|
|
return filename
|
2016-10-09 18:44:23 +03:00
|
|
|
else:
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
raise TypeError("expect str, not %s" % type(filename).__name__)
|
2016-10-09 18:44:23 +03:00
|
|
|
|
2016-11-06 00:42:40 +03:00
|
|
|
# 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.
|
2017-03-29 15:13:55 +03:00
|
|
|
fsdecode = identity
|
2016-11-06 00:42:40 +03:00
|
|
|
|
2017-06-01 16:24:15 +03:00
|
|
|
def getdoc(obj):
|
2019-07-27 06:34:57 +03:00
|
|
|
if isinstance(obj, str):
|
|
|
|
return obj
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
return getattr(obj, "__doc__", None)
|
2017-06-01 16:24:15 +03:00
|
|
|
|
2017-11-23 19:09:00 +03:00
|
|
|
def _getoptbwrapper(orig, args, shortlist, namelist):
|
|
|
|
return orig(args, shortlist, namelist)
|
2016-12-06 04:06:36 +03:00
|
|
|
|
2017-03-29 15:13:55 +03:00
|
|
|
strkwargs = identity
|
|
|
|
byteskwargs = identity
|
2016-12-07 19:23:03 +03:00
|
|
|
|
2017-03-29 15:23:28 +03:00
|
|
|
oslinesep = os.linesep
|
2016-11-06 01:03:22 +03:00
|
|
|
osname = os.name
|
2016-11-06 01:14:44 +03:00
|
|
|
ospathsep = os.pathsep
|
|
|
|
ossep = os.sep
|
2016-12-17 22:14:21 +03:00
|
|
|
osaltsep = os.altsep
|
2016-10-20 17:40:24 +03:00
|
|
|
stdin = sys.stdin
|
|
|
|
stdout = sys.stdout
|
|
|
|
stderr = sys.stderr
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
if getattr(sys, "argv", None) is not None:
|
2017-03-07 21:24:24 +03:00
|
|
|
sysargv = sys.argv
|
2016-12-17 22:22:05 +03:00
|
|
|
sysplatform = sys.platform
|
2016-11-22 16:16:50 +03:00
|
|
|
getcwd = os.getcwd
|
2016-12-19 21:32:24 +03:00
|
|
|
sysexecutable = sys.executable
|
2016-12-25 00:36:55 +03:00
|
|
|
shlexsplit = shlex.split
|
2017-03-12 22:54:11 +03:00
|
|
|
stringio = cStringIO.StringIO
|
2017-03-19 21:12:38 +03:00
|
|
|
maplist = map
|
2017-12-11 03:26:35 +03:00
|
|
|
ziplist = zip
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
rawinput = raw_input # noqa
|
|
|
|
|
2020-01-29 18:38:41 +03:00
|
|
|
def encodeutf8(s):
|
|
|
|
# type: (bytes) -> bytes
|
|
|
|
assert isinstance(s, bytes)
|
|
|
|
return s
|
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
def decodeutf8(s):
|
|
|
|
# type: (bytes) -> bytes
|
|
|
|
assert isinstance(s, bytes)
|
|
|
|
return s
|
|
|
|
|
2020-01-29 03:25:29 +03:00
|
|
|
def iteritems(s):
|
|
|
|
return s.iteritems()
|
|
|
|
|
|
|
|
def iterkeys(s):
|
|
|
|
return s.iterkeys()
|
|
|
|
|
|
|
|
def itervalues(s):
|
|
|
|
return s.itervalues()
|
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
|
|
|
|
isjython = sysplatform.startswith("java")
|
2017-10-12 03:27:21 +03:00
|
|
|
|
2020-01-28 21:21:58 +03:00
|
|
|
isdarwin = sysplatform == "darwin"
|
|
|
|
islinux = sysplatform.startswith("linux")
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
isposix = osname == "posix"
|
|
|
|
iswindows = osname == "nt"
|
2017-10-13 05:20:04 +03:00
|
|
|
|
2017-11-23 19:09:00 +03:00
|
|
|
|
|
|
|
def getoptb(args, shortlist, namelist):
|
|
|
|
return _getoptbwrapper(getopt.getopt, args, shortlist, namelist)
|
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2017-11-23 19:09:00 +03:00
|
|
|
def gnugetoptb(args, shortlist, namelist):
|
|
|
|
return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
|
2018-05-26 03:39:09 +03:00
|
|
|
|
codemod: join the auto-formatter party
Summary:
Turned on the auto formatter. Ran `arc lint --apply-patches --take BLACK **/*.py`.
Then run `arc lint` again so some other autofixers like spellchecker etc. looked
at the code base. Manually accept the changes whenever they make sense, or use
a workaround (ex. changing "dict()" to "dict constructor") where autofix is false
positive. Disabled linters on files that are hard (i18n/polib.py) to fix, or less
interesting to fix (hgsubversion tests), or cannot be fixed without breaking
OSS build (FBPYTHON4).
Conflicted linters (test-check-module-imports.t, part of test-check-code.t,
test-check-pyflakes.t) are removed or disabled.
Duplicated linters (test-check-pyflakes.t, test-check-pylint.t) are removed.
An issue of the auto-formatter is lines are no longer guarnateed to be <= 80
chars. But that seems less important comparing with the benefit auto-formatter
provides.
As we're here, also remove test-check-py3-compat.t, as it is currently broken
if `PYTHON3=/bin/python3` is set.
Reviewed By: wez, phillco, simpkins, pkaush, singhsrb
Differential Revision: D8173629
fbshipit-source-id: 90e248ae0c5e6eaadbe25520a6ee42d32005621b
2018-05-26 07:34:37 +03:00
|
|
|
|
2018-05-26 03:39:09 +03:00
|
|
|
def getcwdsafe():
|
|
|
|
"""Returns the current working dir, or None if it has been deleted"""
|
|
|
|
try:
|
|
|
|
return getcwd()
|
|
|
|
except OSError as err:
|
|
|
|
if err.errno == errno.ENOENT:
|
|
|
|
return None
|
|
|
|
raise
|