diff options
Diffstat (limited to 'lldb/packages/Python/lldbsuite')
11 files changed, 68 insertions, 123 deletions
diff --git a/lldb/packages/Python/lldbsuite/support/encoded_file.py b/lldb/packages/Python/lldbsuite/support/encoded_file.py index c233e04..9de63fd 100644 --- a/lldb/packages/Python/lldbsuite/support/encoded_file.py +++ b/lldb/packages/Python/lldbsuite/support/encoded_file.py @@ -10,26 +10,12 @@ to see a description of the supported command line arguments. # Python modules: import io -# Third party modules -import six - - -def _encoded_read(old_read, encoding): - def impl(size): - result = old_read(size) - # If this is Python 2 then we need to convert the resulting `unicode` back - # into a `str` before returning - if six.PY2: - result = result.encode(encoding) - return result - return impl - def _encoded_write(old_write, encoding): def impl(s): - # If we were asked to write a `str` (in Py2) or a `bytes` (in Py3) decode it - # as unicode before attempting to write. - if isinstance(s, six.binary_type): + # If we were asked to write a `bytes` decode it as unicode before + # attempting to write. + if isinstance(s, bytes): s = s.decode(encoding, "replace") # Filter unreadable characters, Python 3 is stricter than python 2 about them. import re @@ -38,9 +24,8 @@ def _encoded_write(old_write, encoding): return impl ''' -Create a Text I/O file object that can be written to with either unicode strings or byte strings -under Python 2 and Python 3, and automatically encodes and decodes as necessary to return the -native string type for the current Python version +Create a Text I/O file object that can be written to with either unicode strings +or byte strings. ''' @@ -60,8 +45,6 @@ def open( errors=errors, newline=newline, closefd=closefd) - new_read = _encoded_read(getattr(wrapped_file, 'read'), encoding) new_write = _encoded_write(getattr(wrapped_file, 'write'), encoding) - setattr(wrapped_file, 'read', new_read) setattr(wrapped_file, 'write', new_write) return wrapped_file diff --git a/lldb/packages/Python/lldbsuite/support/seven.py b/lldb/packages/Python/lldbsuite/support/seven.py index 969b61d..e9ebf17 100644 --- a/lldb/packages/Python/lldbsuite/support/seven.py +++ b/lldb/packages/Python/lldbsuite/support/seven.py @@ -1,47 +1,31 @@ import binascii -import six import shlex - -if six.PY2: - import commands - get_command_output = commands.getoutput - get_command_status_output = commands.getstatusoutput - - cmp_ = cmp -else: - def get_command_status_output(command): - try: - import subprocess - return ( - 0, - subprocess.check_output( - command, - shell=True, - universal_newlines=True).rstrip()) - except subprocess.CalledProcessError as e: - return (e.returncode, e.output) - - def get_command_output(command): - return get_command_status_output(command)[1] - - cmp_ = lambda x, y: (x > y) - (x < y) - -def bitcast_to_string(b): +import subprocess + +def get_command_output(command): + try: + return subprocess.check_output( + command, + shell=True, + universal_newlines=True).rstrip() + except subprocess.CalledProcessError as e: + return e.output + +def bitcast_to_string(b: bytes) -> str: """ - Take a string(PY2) or a bytes(PY3) object and return a string. The returned - string contains the exact same bytes as the input object (latin1 <-> unicode - transformation is an identity operation for the first 256 code points). + Take a bytes object and return a string. The returned string contains the + exact same bytes as the input object. (latin1 <-> unicode transformation is + an identity operation for the first 256 code points). """ - return b if six.PY2 else b.decode("latin1") + return b.decode("latin1") -def bitcast_to_bytes(s): +def bitcast_to_bytes(s: str) -> bytes: """ - Take a string and return a string(PY2) or a bytes(PY3) object. The returned - object contains the exact same bytes as the input string. (latin1 <-> - unicode transformation is an identity operation for the first 256 code - points). + Take a string and return a bytes object. The returned object contains the + exact same bytes as the input string. (latin1 <-> unicode transformation isi + an identity operation for the first 256 code points). """ - return s if six.PY2 else s.encode("latin1") + return s.encode("latin1") def unhexlify(hexstr): """Hex-decode a string. The result is always a string.""" diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index 477f4a7..3e3db09 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -13,7 +13,6 @@ import tempfile import subprocess # Third-party modules -import six import unittest2 # LLDB modules @@ -71,7 +70,6 @@ def _check_expected_version(comparison, expected, actual): LooseVersion(expected_str)) -_re_pattern_type = type(re.compile('')) def _match_decorator_property(expected, actual): if expected is None: return True @@ -82,7 +80,7 @@ def _match_decorator_property(expected, actual): if isinstance(expected, no_match): return not _match_decorator_property(expected.item, actual) - if isinstance(expected, (_re_pattern_type,) + six.string_types): + if isinstance(expected, (re.Pattern, str)): return re.search(expected, actual) is not None if hasattr(expected, "__iter__"): @@ -131,7 +129,7 @@ def expectedFailureIfFn(expected_fn, bugnumber=None): # the first way, the first argument will be the actual function because decorators are # weird like that. So this is basically a check that says "which syntax was the original # function decorated with?" - if six.callable(bugnumber): + if callable(bugnumber): return expectedFailure_impl(bugnumber) else: return expectedFailure_impl @@ -162,7 +160,7 @@ def skipTestIfFn(expected_fn, bugnumber=None): # the first way, the first argument will be the actual function because decorators are # weird like that. So this is basically a check that says "how was the # decorator used" - if six.callable(bugnumber): + if callable(bugnumber): return skipTestIfFn_impl(bugnumber) else: return skipTestIfFn_impl @@ -249,7 +247,7 @@ def _decorateTest(mode, mode_str, reason_str) else: reason_str = "{} unconditionally".format(mode_str) - if bugnumber is not None and not six.callable(bugnumber): + if bugnumber is not None and not callable(bugnumber): reason_str = reason_str + " [" + str(bugnumber) + "]" return reason_str @@ -463,7 +461,7 @@ def expectedFlakey(expected_fn, bugnumber=None): # the first way, the first argument will be the actual function because decorators are # weird like that. So this is basically a check that says "which syntax was the original # function decorated with?" - if six.callable(bugnumber): + if callable(bugnumber): return expectedFailure_impl(bugnumber) else: return expectedFailure_impl diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py index ee59500..fd21263 100644 --- a/lldb/packages/Python/lldbsuite/test/dotest.py +++ b/lldb/packages/Python/lldbsuite/test/dotest.py @@ -36,7 +36,6 @@ import sys import tempfile # Third-party modules -import six import unittest2 # LLDB Modules diff --git a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py index 22a30c5..f298cc5 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbpexpect.py +++ b/lldb/packages/Python/lldbsuite/test/lldbpexpect.py @@ -4,9 +4,6 @@ from __future__ import absolute_import import os import sys -# Third-party modules -import six - # LLDB Modules import lldb from .lldbtest import * @@ -72,7 +69,7 @@ class PExpectTest(TestBase): self.assertNotIn('\n', cmd) # If 'substrs' is a string then this code would just check that every # character of the string is in the output. - assert not isinstance(substrs, six.string_types), \ + assert not isinstance(substrs, str), \ "substrs must be a collection of strings" self.child.sendline(cmd) diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatform.py b/lldb/packages/Python/lldbsuite/test/lldbplatform.py index 18a4fe5..4418942 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatform.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatform.py @@ -5,9 +5,6 @@ from __future__ import absolute_import # System modules import itertools -# Third-party modules -import six - # LLDB modules import lldb @@ -39,10 +36,10 @@ __name_lookup = { def translate(values): - if isinstance(values, six.integer_types): + if isinstance(values, int): # This is a value from the platform enumeration, translate it. return __name_lookup[values] - elif isinstance(values, six.string_types): + elif isinstance(values, str): # This is a raw string, return it. return [values] elif hasattr(values, "__iter__"): diff --git a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py index 719131c..3f95e80 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbplatformutil.py @@ -9,10 +9,7 @@ import re import subprocess import sys import os - -# Third-party modules -import six -from six.moves.urllib import parse as urlparse +from urllib.parse import urlparse # LLDB modules from . import configuration @@ -62,7 +59,7 @@ def android_device_api(): if not hasattr(android_device_api, 'result'): assert configuration.lldb_platform_url is not None device_id = None - parsed_url = urlparse.urlparse(configuration.lldb_platform_url) + parsed_url = urlparse(configuration.lldb_platform_url) host_name = parsed_url.netloc.split(":")[0] if host_name != 'localhost': device_id = host_name diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index d28e0d2..69bb5ac 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -48,9 +48,6 @@ import traceback # Third-party modules import unittest2 -from six import add_metaclass -from six import StringIO as SixStringIO -import six # LLDB modules import lldb @@ -320,7 +317,7 @@ class ValueCheck: child_error = "Checking child with index " + str(i) + ":\n" + error_msg expected_child.check_value(test_base, actual_child, child_error) -class recording(SixStringIO): +class recording(io.StringIO): """ A nice little context manager for recording the debugger interactions into our session object. If trace flag is ON, it also emits the interactions @@ -328,8 +325,8 @@ class recording(SixStringIO): """ def __init__(self, test, trace): - """Create a SixStringIO instance; record the session obj and trace flag.""" - SixStringIO.__init__(self) + """Create a io.StringIO instance; record the session obj and trace flag.""" + io.StringIO.__init__(self) # The test might not have undergone the 'setUp(self)' phase yet, so that # the attribute 'session' might not even exist yet. self.session = getattr(test, "session", None) if test else None @@ -338,7 +335,7 @@ class recording(SixStringIO): def __enter__(self): """ Context management protocol on entry to the body of the with statement. - Just return the SixStringIO object. + Just return the io.StringIO object. """ return self @@ -346,7 +343,7 @@ class recording(SixStringIO): """ Context management protocol on exit from the body of the with statement. If trace is ON, it emits the recordings into stderr. Always add the - recordings to our session object. And close the SixStringIO object, too. + recordings to our session object. And close the io.StringIO object, too. """ if self.trace: print(self.getvalue(), file=sys.stderr) @@ -355,8 +352,7 @@ class recording(SixStringIO): self.close() -@add_metaclass(abc.ABCMeta) -class _BaseProcess(object): +class _BaseProcess(object, metaclass=abc.ABCMeta): @abc.abstractproperty def pid(self): @@ -945,7 +941,7 @@ class Base(unittest2.TestCase): Hooks are executed in a first come first serve manner. """ - if six.callable(hook): + if callable(hook): with recording(self, traceAlways) as sbuf: print( "Adding tearDown hook:", @@ -1691,8 +1687,7 @@ class LLDBTestCaseFactory(type): # methods when a new class is loaded -@add_metaclass(LLDBTestCaseFactory) -class TestBase(Base): +class TestBase(Base, metaclass=LLDBTestCaseFactory): """ This abstract base class is meant to be subclassed. It provides default implementations for setUpClass(), tearDownClass(), setUp(), and tearDown(), @@ -2230,7 +2225,7 @@ FileCheck output: def expect( self, - str, + string, msg=None, patterns=None, startstr=None, @@ -2264,9 +2259,9 @@ FileCheck output: client is expecting the output of the command not to match the golden input. - Finally, the required argument 'str' represents the lldb command to be + Finally, the required argument 'string' represents the lldb command to be sent to the command interpreter. In case the keyword argument 'exe' is - set to False, the 'str' is treated as a string to be matched/not-matched + set to False, the 'string' is treated as a string to be matched/not-matched against the golden input. """ # Catch cases where `expect` has been miscalled. Specifically, prevent @@ -2280,9 +2275,9 @@ FileCheck output: assert False, "expect() missing a matcher argument" # Check `patterns` and `substrs` are not accidentally given as strings. - assert not isinstance(patterns, six.string_types), \ + assert not isinstance(patterns, str), \ "patterns must be a collection of strings" - assert not isinstance(substrs, six.string_types), \ + assert not isinstance(substrs, str), \ "substrs must be a collection of strings" trace = (True if traceAlways else trace) @@ -2292,7 +2287,7 @@ FileCheck output: # Pass the assert message along since it provides more semantic # info. self.runCmd( - str, + string, msg=msg, trace=( True if trace else False), @@ -2305,13 +2300,13 @@ FileCheck output: # If error is True, the API client expects the command to fail! if error: self.assertFalse(self.res.Succeeded(), - "Command '" + str + "' is expected to fail!") + "Command '" + string + "' is expected to fail!") else: - # No execution required, just compare str against the golden input. - if isinstance(str, lldb.SBCommandReturnObject): - output = str.GetOutput() + # No execution required, just compare string against the golden input. + if isinstance(string, lldb.SBCommandReturnObject): + output = string.GetOutput() else: - output = str + output = string with recording(self, trace) as sbuf: print("looking at:", output, file=sbuf) @@ -2322,7 +2317,7 @@ FileCheck output: # To be used as assert fail message and/or trace content log_lines = [ "{}:".format("Ran command" if exe else "Checking string"), - "\"{}\"".format(str), + "\"{}\"".format(string), # Space out command and output "", ] diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py index eba05a4..8bd49c7 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbutil.py +++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py @@ -9,16 +9,13 @@ from __future__ import absolute_import # System modules import errno +import io import os import re import sys import subprocess from typing import Dict -# Third-party modules -from six import StringIO as SixStringIO -import six - # LLDB modules import lldb from . import lldbtest_config @@ -111,7 +108,7 @@ def disassemble(target, function_or_symbol): It returns the disassembly content in a string object. """ - buf = SixStringIO() + buf = io.StringIO() insts = function_or_symbol.GetInstructions(target) for i in insts: print(i, file=buf) @@ -1080,7 +1077,7 @@ def get_stack_frames(thread): def print_stacktrace(thread, string_buffer=False): """Prints a simple stack trace of this thread.""" - output = SixStringIO() if string_buffer else sys.stdout + output = io.StringIO() if string_buffer else sys.stdout target = thread.GetProcess().GetTarget() depth = thread.GetNumFrames() @@ -1142,7 +1139,7 @@ def print_stacktrace(thread, string_buffer=False): def print_stacktraces(process, string_buffer=False): """Prints the stack traces of all the threads.""" - output = SixStringIO() if string_buffer else sys.stdout + output = io.StringIO() if string_buffer else sys.stdout print("Stack traces for " + str(process), file=output) @@ -1258,7 +1255,7 @@ def get_args_as_string(frame, showFuncName=True): def print_registers(frame, string_buffer=False): """Prints all the register sets of the frame.""" - output = SixStringIO() if string_buffer else sys.stdout + output = io.StringIO() if string_buffer else sys.stdout print("Register sets for " + str(frame), file=output) @@ -1344,7 +1341,7 @@ class BasicFormatter(object): def format(self, value, buffer=None, indent=0): if not buffer: - output = SixStringIO() + output = io.StringIO() else: output = buffer # If there is a summary, it suffices. @@ -1374,7 +1371,7 @@ class ChildVisitingFormatter(BasicFormatter): def format(self, value, buffer=None): if not buffer: - output = SixStringIO() + output = io.StringIO() else: output = buffer @@ -1401,7 +1398,7 @@ class RecursiveDecentFormatter(BasicFormatter): def format(self, value, buffer=None): if not buffer: - output = SixStringIO() + output = io.StringIO() else: output = buffer @@ -1511,7 +1508,7 @@ class PrintableRegex(object): def skip_if_callable(test, mycallable, reason): - if six.callable(mycallable): + if callable(mycallable): if mycallable(test): test.skipTest(reason) return True diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index df1fd2c..1653910 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -59,8 +59,7 @@ class GdbRemoteTestCaseFactory(type): return super(GdbRemoteTestCaseFactory, cls).__new__( cls, name, bases, newattrs) -@add_metaclass(GdbRemoteTestCaseFactory) -class GdbRemoteTestCaseBase(Base): +class GdbRemoteTestCaseBase(Base, metaclass=GdbRemoteTestCaseFactory): # Default time out in seconds. The timeout is increased tenfold under Asan. DEFAULT_TIMEOUT = 20 * (10 if ('ASAN_OPTIONS' in os.environ) else 1) diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py index 82e1685..8e615ec 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py @@ -8,7 +8,6 @@ import os import os.path import platform import re -import six import socket import subprocess from lldbsuite.support import seven @@ -803,7 +802,7 @@ def process_is_running(pid, unknown_value=True): If we don't know how to check running process ids on the given OS: return the value provided by the unknown_value arg. """ - if not isinstance(pid, six.integer_types): + if not isinstance(pid, int): raise Exception( "pid must be an integral type (actual type: %s)" % str( type(pid))) @@ -878,7 +877,7 @@ class Server(object): @staticmethod def _checksum(packet): checksum = 0 - for c in six.iterbytes(packet): + for c in iter(packet): checksum += c return checksum % 256 |