[Lldb-commits] [lldb] r250915 - Use six to portably handle module renames in Python 2 and 3
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 21 10:48:52 PDT 2015
Author: zturner
Date: Wed Oct 21 12:48:52 2015
New Revision: 250915
URL: http://llvm.org/viewvc/llvm-project?rev=250915&view=rev
Log:
Use six to portably handle module renames in Python 2 and 3
Modified:
lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
lldb/trunk/test/api/multiple-debuggers/TestMultipleDebuggers.py
lldb/trunk/test/api/multithreaded/TestMultithreaded.py
lldb/trunk/test/dosep.py
lldb/trunk/test/dotest_channels.py
lldb/trunk/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py
lldb/trunk/test/functionalities/paths/TestPaths.py
lldb/trunk/test/functionalities/rerun/TestRerun.py
lldb/trunk/test/functionalities/stop-hook/TestStopHookCmd.py
lldb/trunk/test/lldbtest.py
lldb/trunk/test/lldbutil.py
lldb/trunk/test/python_api/frame/TestFrames.py
lldb/trunk/test/test_results.py
lldb/trunk/test/tools/lldb-server/lldbgdbserverutils.py
lldb/trunk/test/tools/lldb-server/socket_packet_pump.py
lldb/trunk/test/unittest2/result.py
Modified: lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py (original)
+++ lldb/trunk/test/api/check_public_api_headers/TestPublicAPIHeaders.py Wed Oct 21 12:48:52 2015
@@ -3,7 +3,9 @@
There should be nothing unwanted there and a simpe main.cpp which includes SB*.h
should compile and link with the LLDB framework."""
-import os, re, StringIO
+import lldb_shared
+
+import os, re
import unittest2
from lldbtest import *
import lldbutil
Modified: lldb/trunk/test/api/multiple-debuggers/TestMultipleDebuggers.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/multiple-debuggers/TestMultipleDebuggers.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/api/multiple-debuggers/TestMultipleDebuggers.py (original)
+++ lldb/trunk/test/api/multiple-debuggers/TestMultipleDebuggers.py Wed Oct 21 12:48:52 2015
@@ -1,6 +1,8 @@
"""Test the lldb public C++ api when doing multiple debug sessions simultaneously."""
-import os, re, StringIO
+import lldb_shared
+
+import os, re
import unittest2
from lldbtest import *
import lldbutil
Modified: lldb/trunk/test/api/multithreaded/TestMultithreaded.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/api/multithreaded/TestMultithreaded.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/api/multithreaded/TestMultithreaded.py (original)
+++ lldb/trunk/test/api/multithreaded/TestMultithreaded.py Wed Oct 21 12:48:52 2015
@@ -1,6 +1,8 @@
"""Test the lldb public C++ api breakpoint callbacks."""
-import os, re, StringIO
+import lldb_shared
+
+import os, re
import unittest2
from lldbtest import *
import lldbutil
Modified: lldb/trunk/test/dosep.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dosep.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/dosep.py (original)
+++ lldb/trunk/test/dosep.py Wed Oct 21 12:48:52 2015
@@ -34,6 +34,8 @@ echo core.%p | sudo tee /proc/sys/kernel
from __future__ import print_function
+import lldb_shared
+
# system packages and modules
import asyncore
import distutils.version
@@ -42,12 +44,13 @@ import multiprocessing
import multiprocessing.pool
import os
import platform
-import Queue
import re
import signal
import sys
import threading
+from six.moves import queue
+
# Add our local test_runner/lib dir to the python path.
sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib"))
@@ -336,7 +339,7 @@ def process_dir_worker_multiprocessing(
result = process_dir(job[0], job[1], job[2], job[3],
inferior_pid_events)
result_queue.put(result)
- except Queue.Empty:
+ except queue.Empty:
# Fine, we're done.
pass
@@ -359,7 +362,7 @@ def process_dir_worker_threading(job_que
result = process_dir(job[0], job[1], job[2], job[3],
inferior_pid_events)
result_queue.put(result)
- except Queue.Empty:
+ except queue.Empty:
# Fine, we're done.
pass
@@ -641,7 +644,7 @@ def handle_ctrl_c(ctrl_c_count, job_queu
try:
# Just drain it to stop more work from being started.
job_queue.get_nowait()
- except Queue.Empty:
+ except queue.Empty:
pass
with output_lock:
print("Stopped more work from being started.")
@@ -834,16 +837,16 @@ def threading_test_runner(num_threads, t
initialize_global_vars_threading(num_threads, test_work_items)
# Create jobs.
- job_queue = Queue.Queue()
+ job_queue = queue.Queue()
for test_work_item in test_work_items:
job_queue.put(test_work_item)
- result_queue = Queue.Queue()
+ result_queue = queue.Queue()
# Create queues for started child pids. Terminating
# the threading threads does not terminate the
# child processes they spawn.
- inferior_pid_events = Queue.Queue()
+ inferior_pid_events = queue.Queue()
# Create workers. We don't use multiprocessing.pool.ThreadedPool
# due to challenges with handling ^C keyboard interrupts.
Modified: lldb/trunk/test/dotest_channels.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/dotest_channels.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/dotest_channels.py (original)
+++ lldb/trunk/test/dotest_channels.py Wed Oct 21 12:48:52 2015
@@ -14,10 +14,12 @@ This module provides asyncore channels u
framework.
"""
+import lldb_shared
+
import asyncore
-import cPickle
import socket
+from six.moves import cPickle
class UnpicklingForwardingReaderChannel(asyncore.dispatcher):
"""Provides an unpickling, forwarding asyncore dispatch channel reader.
Modified: lldb/trunk/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py (original)
+++ lldb/trunk/test/functionalities/launch_with_shellexpand/TestLaunchWithShellExpand.py Wed Oct 21 12:48:52 2015
@@ -1,7 +1,6 @@
"""
Test that argdumper is a viable launching strategy.
"""
-import commands
import lldb
import os
import time
Modified: lldb/trunk/test/functionalities/paths/TestPaths.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/paths/TestPaths.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/paths/TestPaths.py (original)
+++ lldb/trunk/test/functionalities/paths/TestPaths.py Wed Oct 21 12:48:52 2015
@@ -1,7 +1,6 @@
"""
Test some lldb command abbreviations.
"""
-import commands
import lldb
import os
import time
Modified: lldb/trunk/test/functionalities/rerun/TestRerun.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/rerun/TestRerun.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/rerun/TestRerun.py (original)
+++ lldb/trunk/test/functionalities/rerun/TestRerun.py Wed Oct 21 12:48:52 2015
@@ -1,7 +1,6 @@
"""
Test that argdumper is a viable launching strategy.
"""
-import commands
import lldb
import os
import time
Modified: lldb/trunk/test/functionalities/stop-hook/TestStopHookCmd.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/stop-hook/TestStopHookCmd.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/stop-hook/TestStopHookCmd.py (original)
+++ lldb/trunk/test/functionalities/stop-hook/TestStopHookCmd.py Wed Oct 21 12:48:52 2015
@@ -2,9 +2,10 @@
Test lldb target stop-hook command.
"""
+import lldb_shared
+
import os
import unittest2
-import StringIO
import lldb
from lldbtest import *
import lldbutil
Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Wed Oct 21 12:48:52 2015
@@ -43,7 +43,6 @@ import os.path
import re
import signal
from subprocess import *
-import StringIO
import time
import types
import unittest2
@@ -52,11 +51,8 @@ import lldbtest_config
import lldbutil
from six import add_metaclass
-
-if sys.version_info.major < 3:
- import urlparse
-else:
- import urllib.parse as urlparse
+from six import StringIO as SixStringIO
+from six.moves.urllib import parse as urlparse
# dosep.py starts lots and lots of dotest instances
# This option helps you find if two (or more) dotest instances are using the same
@@ -224,15 +220,15 @@ def which(program):
return exe_file
return None
-class recording(StringIO.StringIO):
+class recording(SixStringIO):
"""
A nice little context manager for recording the debugger interactions into
our session object. If trace flag is ON, it also emits the interactions
into the stderr.
"""
def __init__(self, test, trace):
- """Create a StringIO instance; record the session obj and trace flag."""
- StringIO.StringIO.__init__(self)
+ """Create a SixStringIO instance; record the session obj and trace flag."""
+ SixStringIO.__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
@@ -241,7 +237,7 @@ class recording(StringIO.StringIO):
def __enter__(self):
"""
Context management protocol on entry to the body of the with statement.
- Just return the StringIO object.
+ Just return the SixStringIO object.
"""
return self
@@ -249,7 +245,7 @@ class recording(StringIO.StringIO):
"""
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 StringIO object, too.
+ recordings to our session object. And close the SixStringIO object, too.
"""
if self.trace:
print(self.getvalue(), file=sys.stderr)
Modified: lldb/trunk/test/lldbutil.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbutil.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/lldbutil.py (original)
+++ lldb/trunk/test/lldbutil.py Wed Oct 21 12:48:52 2015
@@ -6,11 +6,14 @@ They can also be useful for general purp
from __future__ import print_function
+import lldb_shared
+
import lldb
import os, sys
-import StringIO
import re
+from six import StringIO as SixStringIO
+
# ===================================================
# Utilities for locating/checking executable programs
# ===================================================
@@ -41,7 +44,7 @@ def disassemble(target, function_or_symb
It returns the disassembly content in a string object.
"""
- buf = StringIO.StringIO()
+ buf = SixStringIO()
insts = function_or_symbol.GetInstructions(target)
for i in insts:
print(i, file=buf)
@@ -670,7 +673,7 @@ def get_stack_frames(thread):
def print_stacktrace(thread, string_buffer = False):
"""Prints a simple stack trace of this thread."""
- output = StringIO.StringIO() if string_buffer else sys.stdout
+ output = SixStringIO() if string_buffer else sys.stdout
target = thread.GetProcess().GetTarget()
depth = thread.GetNumFrames()
@@ -714,7 +717,7 @@ def print_stacktrace(thread, string_buff
def print_stacktraces(process, string_buffer = False):
"""Prints the stack traces of all the threads."""
- output = StringIO.StringIO() if string_buffer else sys.stdout
+ output = SixStringIO() if string_buffer else sys.stdout
print("Stack traces for " + str(process), file=output)
@@ -786,7 +789,7 @@ def get_args_as_string(frame, showFuncNa
def print_registers(frame, string_buffer = False):
"""Prints all the register sets of the frame."""
- output = StringIO.StringIO() if string_buffer else sys.stdout
+ output = SixStringIO() if string_buffer else sys.stdout
print("Register sets for " + str(frame), file=output)
@@ -860,7 +863,7 @@ class BasicFormatter(object):
"""The basic formatter inspects the value object and prints the value."""
def format(self, value, buffer=None, indent=0):
if not buffer:
- output = StringIO.StringIO()
+ output = SixStringIO()
else:
output = buffer
# If there is a summary, it suffices.
@@ -887,7 +890,7 @@ class ChildVisitingFormatter(BasicFormat
self.cindent = indent_child
def format(self, value, buffer=None):
if not buffer:
- output = StringIO.StringIO()
+ output = SixStringIO()
else:
output = buffer
@@ -910,7 +913,7 @@ class RecursiveDecentFormatter(BasicForm
self.cindent = indent_child
def format(self, value, buffer=None):
if not buffer:
- output = StringIO.StringIO()
+ output = SixStringIO()
else:
output = buffer
Modified: lldb/trunk/test/python_api/frame/TestFrames.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/python_api/frame/TestFrames.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/python_api/frame/TestFrames.py (original)
+++ lldb/trunk/test/python_api/frame/TestFrames.py Wed Oct 21 12:48:52 2015
@@ -3,6 +3,8 @@ Use lldb Python SBFrame API to get the a
And other SBFrame API tests.
"""
+import lldb_shared
+
import os, time
import re
import unittest2
@@ -42,8 +44,8 @@ class FrameAPITestCase(TestBase):
# depth of 3 of the 'c' leaf function.
callsOfA = 0
- import StringIO
- session = StringIO.StringIO()
+ from six import StringIO as SixStringIO
+ session = SixStringIO()
while process.GetState() == lldb.eStateStopped:
thread = process.GetThreadAtIndex(0)
# Inspect at most 3 frames.
Modified: lldb/trunk/test/test_results.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/test_results.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/test_results.py (original)
+++ lldb/trunk/test/test_results.py Wed Oct 21 12:48:52 2015
@@ -8,8 +8,9 @@ Provides classes used by the test result
within the LLDB test suite.
"""
+import lldb_shared
+
import argparse
-import cPickle
import inspect
import os
import pprint
@@ -20,6 +21,8 @@ import time
import traceback
import xml.sax.saxutils
+from six.moves import cPickle
+
class EventBuilder(object):
"""Helper class to build test result event dictionaries."""
Modified: lldb/trunk/test/tools/lldb-server/lldbgdbserverutils.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-server/lldbgdbserverutils.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-server/lldbgdbserverutils.py (original)
+++ lldb/trunk/test/tools/lldb-server/lldbgdbserverutils.py Wed Oct 21 12:48:52 2015
@@ -1,16 +1,19 @@
"""Module for supporting unit testing of the lldb-server debug monitor exe.
"""
+import lldb_shared
+
import os
import os.path
import platform
-import Queue
import re
import socket_packet_pump
import subprocess
import time
from lldbtest import *
+from six.moves import queue
+
def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename):
"""Return the debug monitor exe path given the lldb exe path.
@@ -215,14 +218,14 @@ def expect_lldb_gdbserver_replay(
try:
# Grab next entry from the output queue.
content = pump.output_queue().get(True, timeout_seconds)
- except Queue.Empty:
+ except queue.Empty:
if logger:
logger.warning("timeout waiting for stub output (accumulated output:{})".format(pump.get_accumulated_output()))
raise Exception("timed out while waiting for output match (accumulated output: {})".format(pump.get_accumulated_output()))
else:
try:
content = pump.packet_queue().get(True, timeout_seconds)
- except Queue.Empty:
+ except queue.Empty:
if logger:
logger.warning("timeout waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer()))
raise Exception("timed out while waiting for packet match (receive buffer: {})".format(pump.get_receive_buffer()))
Modified: lldb/trunk/test/tools/lldb-server/socket_packet_pump.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/tools/lldb-server/socket_packet_pump.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/tools/lldb-server/socket_packet_pump.py (original)
+++ lldb/trunk/test/tools/lldb-server/socket_packet_pump.py Wed Oct 21 12:48:52 2015
@@ -1,10 +1,14 @@
-import Queue
+
+import lldb_shared
+
import re
import select
import threading
import traceback
import codecs
+from six.moves import queue
+
def _handle_output_packet_string(packet_contents):
if (not packet_contents) or (len(packet_contents) < 1):
return None
@@ -38,8 +42,8 @@ class SocketPacketPump(object):
if not pump_socket:
raise Exception("pump_socket cannot be None")
- self._output_queue = Queue.Queue()
- self._packet_queue = Queue.Queue()
+ self._output_queue = queue.Queue()
+ self._packet_queue = queue.Queue()
self._thread = None
self._stop_thread = False
self._socket = pump_socket
Modified: lldb/trunk/test/unittest2/result.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/unittest2/result.py?rev=250915&r1=250914&r2=250915&view=diff
==============================================================================
--- lldb/trunk/test/unittest2/result.py (original)
+++ lldb/trunk/test/unittest2/result.py Wed Oct 21 12:48:52 2015
@@ -1,10 +1,12 @@
"""Test result object"""
+import lldb_shared
+
import sys
import traceback
import unittest
-from StringIO import StringIO
+from six import StringIO as SixStringIO
from unittest2 import util
from unittest2.compatibility import wraps
@@ -61,8 +63,8 @@ class TestResult(unittest.TestResult):
self._mirrorOutput = False
if self.buffer:
if self._stderr_buffer is None:
- self._stderr_buffer = StringIO()
- self._stdout_buffer = StringIO()
+ self._stderr_buffer = SixStringIO()
+ self._stdout_buffer = SixStringIO()
sys.stdout = self._stdout_buffer
sys.stderr = self._stderr_buffer
More information about the lldb-commits
mailing list