2016-04-06 23:00:49 +03:00
|
|
|
# pycompat.py - portability shim for python 3
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
ispy3 = sys.version_info[0] >= 3
|
|
|
|
ispypy = r"__pypy__" in sys.builtin_module_names
|
2016-09-28 14:01:23 +03:00
|
|
|
|
|
|
|
if not ispy3:
|
2017-03-10 08:35:21 +03:00
|
|
|
import cookielib
|
2016-07-17 17:18:04 +03:00
|
|
|
import cPickle as pickle
|
2016-06-28 13:31:53 +03:00
|
|
|
import httplib
|
2016-07-17 17:18:04 +03:00
|
|
|
import Queue as _queue
|
2016-06-27 14:18:54 +03:00
|
|
|
import SocketServer as socketserver
|
2016-07-17 17:18:04 +03:00
|
|
|
import xmlrpclib
|
|
|
|
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
|
|
|
|
import xmlrpc.client as xmlrpclib # noqa: F401
|
2016-07-17 17:18:04 +03:00
|
|
|
|
2017-06-16 00:31:22 +03:00
|
|
|
empty = _queue.Empty
|
|
|
|
queue = _queue.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
|
|
|
|
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
|
|
|
|
2016-09-28 14:01:23 +03:00
|
|
|
if ispy3:
|
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
|
|
|
|
2016-10-09 18:44:23 +03:00
|
|
|
fsencode = os.fsencode
|
2016-11-06 00:42:40 +03:00
|
|
|
fsdecode = os.fsdecode
|
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
|
|
|
oslinesep = os.linesep.encode("ascii")
|
|
|
|
osname = os.name.encode("ascii")
|
|
|
|
ospathsep = os.pathsep.encode("ascii")
|
|
|
|
ossep = os.sep.encode("ascii")
|
2016-12-17 22:14:21 +03:00
|
|
|
osaltsep = os.altsep
|
|
|
|
if osaltsep:
|
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
|
|
|
osaltsep = osaltsep.encode("ascii")
|
2016-11-22 16:16:50 +03:00
|
|
|
# os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
|
|
|
|
# returns bytes.
|
|
|
|
getcwd = os.getcwdb
|
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
|
|
|
sysplatform = sys.platform.encode("ascii")
|
2016-12-19 21:32:24 +03:00
|
|
|
sysexecutable = sys.executable
|
|
|
|
if sysexecutable:
|
|
|
|
sysexecutable = os.fsencode(sysexecutable)
|
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
|
2016-11-09 16:06:09 +03:00
|
|
|
|
2016-10-20 17:40:24 +03:00
|
|
|
# TODO: .buffer might not exist if std streams were replaced; we'll need
|
|
|
|
# a silly wrapper to make a bytes stream backed by a unicode one.
|
|
|
|
stdin = sys.stdin.buffer
|
|
|
|
stdout = sys.stdout.buffer
|
|
|
|
stderr = sys.stderr.buffer
|
|
|
|
|
2016-11-09 16:06:09 +03:00
|
|
|
# Since Python 3 converts argv to wchar_t type by Py_DecodeLocale() on Unix,
|
|
|
|
# we can use os.fsencode() to get back bytes argv.
|
|
|
|
#
|
|
|
|
# https://hg.python.org/cpython/file/v3.5.1/Programs/python.c#l55
|
|
|
|
#
|
|
|
|
# TODO: On Windows, the native argv is wchar_t, so we'll need a different
|
|
|
|
# workaround to simulate the Python 2 (i.e. ANSI Win32 API) behavior.
|
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 = list(map(os.fsencode, sys.argv))
|
2016-08-14 06:41:54 +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
|
|
|
bytechr = struct.Struct(">B").pack
|
2017-03-08 16:30:12 +03:00
|
|
|
|
2017-03-08 16:48:26 +03:00
|
|
|
class bytestr(bytes):
|
|
|
|
"""A bytes which mostly acts as a Python 2 str
|
|
|
|
|
|
|
|
>>> bytestr(), bytestr(bytearray(b'foo')), bytestr(u'ascii'), bytestr(1)
|
|
|
|
(b'', b'foo', b'ascii', b'1')
|
|
|
|
>>> s = bytestr(b'foo')
|
|
|
|
>>> assert s is bytestr(s)
|
|
|
|
|
2017-05-04 05:51:07 +03:00
|
|
|
__bytes__() should be called if provided:
|
|
|
|
|
|
|
|
>>> class bytesable(object):
|
|
|
|
... def __bytes__(self):
|
|
|
|
... return b'bytes'
|
|
|
|
>>> bytestr(bytesable())
|
|
|
|
b'bytes'
|
|
|
|
|
2017-03-08 16:48:26 +03:00
|
|
|
There's no implicit conversion from non-ascii str as its encoding is
|
|
|
|
unknown:
|
|
|
|
|
|
|
|
>>> bytestr(chr(0x80)) # doctest: +ELLIPSIS
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
UnicodeEncodeError: ...
|
|
|
|
|
|
|
|
Comparison between bytestr and bytes should work:
|
|
|
|
|
|
|
|
>>> assert bytestr(b'foo') == b'foo'
|
|
|
|
>>> assert b'foo' == bytestr(b'foo')
|
|
|
|
>>> assert b'f' in bytestr(b'foo')
|
|
|
|
>>> assert bytestr(b'f') in b'foo'
|
|
|
|
|
|
|
|
Sliced elements should be bytes, not integer:
|
|
|
|
|
|
|
|
>>> s[1], s[:2]
|
|
|
|
(b'o', b'fo')
|
|
|
|
>>> list(s), list(reversed(s))
|
|
|
|
([b'f', b'o', b'o'], [b'o', b'o', b'f'])
|
|
|
|
|
|
|
|
As bytestr type isn't propagated across operations, you need to cast
|
|
|
|
bytes to bytestr explicitly:
|
|
|
|
|
|
|
|
>>> s = bytestr(b'foo').upper()
|
|
|
|
>>> t = bytestr(s)
|
|
|
|
>>> s[0], t[0]
|
|
|
|
(70, b'F')
|
|
|
|
|
|
|
|
Be careful to not pass a bytestr object to a function which expects
|
|
|
|
bytearray-like behavior.
|
|
|
|
|
|
|
|
>>> t = bytes(t) # cast to bytes
|
|
|
|
>>> assert type(t) is bytes
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
def __new__(cls, s=b""):
|
2017-03-08 16:48:26 +03:00
|
|
|
if isinstance(s, bytestr):
|
|
|
|
return s
|
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 not isinstance(s, (bytes, bytearray)):
|
|
|
|
if not hasattr(s, u"__bytes__"): # hasattr-py3-only
|
|
|
|
s = str(s).encode(u"ascii")
|
|
|
|
return bytes.__new__(cls, s)
|
2017-03-08 16:48:26 +03:00
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
s = bytes.__getitem__(self, key)
|
|
|
|
if not isinstance(s, bytes):
|
|
|
|
s = bytechr(s)
|
|
|
|
return s
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iterbytestr(bytes.__iter__(self))
|
|
|
|
|
2017-03-13 03:04:45 +03:00
|
|
|
def iterbytestr(s):
|
|
|
|
"""Iterate bytes as if it were a str object of Python 2"""
|
2017-03-15 19:32:18 +03:00
|
|
|
return map(bytechr, s)
|
2017-03-13 03:04:45 +03:00
|
|
|
|
2017-04-04 18:34:58 +03:00
|
|
|
def sysbytes(s):
|
|
|
|
"""Convert an internal str (e.g. keyword, __doc__) back to bytes
|
|
|
|
|
|
|
|
This never raises UnicodeEncodeError, but only ASCII characters
|
|
|
|
can be round-trip by sysstr(sysbytes(s)).
|
|
|
|
"""
|
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 s.encode(u"utf-8")
|
2017-04-04 18:34:58 +03:00
|
|
|
|
2016-09-28 16:32:09 +03:00
|
|
|
def sysstr(s):
|
|
|
|
"""Return a keyword str to be passed to Python functions such as
|
|
|
|
getattr() and str.encode()
|
|
|
|
|
|
|
|
This never raises UnicodeDecodeError. Non-ascii characters are
|
|
|
|
considered invalid and mapped to arbitrary but unique code points
|
|
|
|
such that 'sysstr(a) != sysstr(b)' for all 'a != b'.
|
|
|
|
"""
|
|
|
|
if isinstance(s, builtins.str):
|
|
|
|
return s
|
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 s.decode(u"latin-1")
|
2016-09-28 16:32:09 +03:00
|
|
|
|
2017-06-15 22:02:52 +03:00
|
|
|
def strurl(url):
|
|
|
|
"""Converts a bytes url back to str"""
|
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 url.decode(u"ascii")
|
2017-06-15 22:02:52 +03:00
|
|
|
|
2017-06-15 22:06:17 +03:00
|
|
|
def bytesurl(url):
|
|
|
|
"""Converts a str url to bytes by encoding in ascii"""
|
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 url.encode(u"ascii")
|
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 _('')"""
|
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)
|
|
|
|
|
2016-08-14 06:51:21 +03:00
|
|
|
def _wrapattrfunc(f):
|
|
|
|
@functools.wraps(f)
|
|
|
|
def w(object, name, *args):
|
2016-09-28 16:32:09 +03:00
|
|
|
return f(object, sysstr(name), *args)
|
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
|
|
|
|
2016-08-14 06:51:21 +03:00
|
|
|
return w
|
|
|
|
|
2016-08-16 06:35:15 +03:00
|
|
|
# these wrappers are automagically imported by hgloader
|
2016-08-14 06:51:21 +03:00
|
|
|
delattr = _wrapattrfunc(builtins.delattr)
|
|
|
|
getattr = _wrapattrfunc(builtins.getattr)
|
|
|
|
hasattr = _wrapattrfunc(builtins.hasattr)
|
|
|
|
setattr = _wrapattrfunc(builtins.setattr)
|
2016-08-16 06:35:15 +03:00
|
|
|
xrange = builtins.range
|
2017-04-07 21:05:51 +03:00
|
|
|
unicode = str
|
2016-08-14 06:51:21 +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
|
|
|
def open(name, mode="r", buffering=-1):
|
2017-03-03 10:34:32 +03:00
|
|
|
return builtins.open(name, sysstr(mode), buffering)
|
|
|
|
|
2017-11-23 19:09:00 +03:00
|
|
|
def _getoptbwrapper(orig, args, shortlist, namelist):
|
2017-06-16 00:18:17 +03:00
|
|
|
"""
|
|
|
|
Takes bytes arguments, converts them to unicode, pass them to
|
|
|
|
getopt.getopt(), convert the returned values back to bytes and then
|
|
|
|
return them for Python 3 compatibility as getopt.getopt() don't accepts
|
|
|
|
bytes 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
|
|
|
args = [a.decode("latin-1") for a in args]
|
|
|
|
shortlist = shortlist.decode("latin-1")
|
|
|
|
namelist = [a.decode("latin-1") for a in namelist]
|
2017-11-23 19:09:00 +03:00
|
|
|
opts, args = orig(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
|
|
|
opts = [(a[0].encode("latin-1"), a[1].encode("latin-1")) for a in opts]
|
|
|
|
args = [a.encode("latin-1") for a in args]
|
2016-12-06 04:06:36 +03:00
|
|
|
return opts, args
|
|
|
|
|
2016-12-07 19:23:03 +03:00
|
|
|
def strkwargs(dic):
|
2017-06-16 00:18:17 +03:00
|
|
|
"""
|
|
|
|
Converts the keys of a python dictonary to str i.e. unicodes so that
|
|
|
|
they can be passed as keyword arguments as dictonaries with bytes keys
|
|
|
|
can't be passed as keyword arguments to functions 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
|
|
|
dic = dict((k.decode("latin-1"), v) for k, v in dic.iteritems())
|
2016-12-07 19:23:03 +03:00
|
|
|
return dic
|
|
|
|
|
|
|
|
def byteskwargs(dic):
|
2017-06-16 00:18:17 +03:00
|
|
|
"""
|
|
|
|
Converts keys of python dictonaries to bytes as they were converted to
|
|
|
|
str to pass that dictonary as a keyword argument 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
|
|
|
dic = dict((k.encode("latin-1"), v) for k, v in dic.iteritems())
|
2016-12-07 19:23:03 +03:00
|
|
|
return dic
|
|
|
|
|
2016-12-25 00:36:55 +03:00
|
|
|
# TODO: handle shlex.shlex().
|
|
|
|
def shlexsplit(s):
|
2017-06-16 00:18:17 +03:00
|
|
|
"""
|
|
|
|
Takes bytes argument, convert it to str i.e. unicodes, pass that into
|
|
|
|
shlex.split(), convert the returned value to bytes and return that for
|
|
|
|
Python 3 compatibility as shelx.split() don't accept bytes 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
|
|
|
ret = shlex.split(s.decode("latin-1"))
|
|
|
|
return [a.encode("latin-1") for a in ret]
|
|
|
|
|
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
|
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):
|
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
|
|
|
|
|
|
|
|
isjython = sysplatform.startswith("java")
|
2017-10-12 03:27:21 +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
|
|
|
isdarwin = sysplatform == "darwin"
|
|
|
|
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
|