aboutsummaryrefslogtreecommitdiff
path: root/lldb/packages/Python/lldbsuite/support
diff options
context:
space:
mode:
authorDave Lee <davelee.com@gmail.com>2022-08-05 13:35:20 -0600
committerDave Lee <davelee.com@gmail.com>2022-08-11 19:06:15 -0700
commit56f9cfe30c4488aade888905bb6280ecb952a613 (patch)
tree99a60b9c61a4344203d3e645308bd4e871a7590a /lldb/packages/Python/lldbsuite/support
parent256ba7738ea8a07372a82cadd29e9c08fdf9145c (diff)
downloadllvm-56f9cfe30c4488aade888905bb6280ecb952a613.zip
llvm-56f9cfe30c4488aade888905bb6280ecb952a613.tar.gz
llvm-56f9cfe30c4488aade888905bb6280ecb952a613.tar.bz2
[lldb] Remove uses of six module (NFC)
With lldb (& llvm) requiring Python 3.6+, use of the `six` module can be removed. Differential Revision: https://reviews.llvm.org/D131304
Diffstat (limited to 'lldb/packages/Python/lldbsuite/support')
-rw-r--r--lldb/packages/Python/lldbsuite/support/encoded_file.py27
-rw-r--r--lldb/packages/Python/lldbsuite/support/seven.py58
2 files changed, 26 insertions, 59 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."""