Use six to portably handle module renames in Python 2 and 3

llvm-svn: 250915
This commit is contained in:
Zachary Turner 2015-10-21 17:48:52 +00:00
parent c96d0dd431
commit 814236d694
16 changed files with 68 additions and 46 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -34,6 +34,8 @@ echo core.%p | sudo tee /proc/sys/kernel/core_pattern
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_queue, result_queue, inferior_pid_events):
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_queue, workers, inferior_pid_events,
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, test_work_items):
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.

View File

@ -14,10 +14,12 @@ This module provides asyncore channels used within the LLDB test
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.

View File

@ -1,7 +1,6 @@
"""
Test that argdumper is a viable launching strategy.
"""
import commands
import lldb
import os
import time

View File

@ -1,7 +1,6 @@
"""
Test some lldb command abbreviations.
"""
import commands
import lldb
import os
import time

View File

@ -1,7 +1,6 @@
"""
Test that argdumper is a viable launching strategy.
"""
import commands
import lldb
import os
import time

View File

@ -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

View File

@ -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)

View File

@ -6,11 +6,14 @@ They can also be useful for general purpose lldb scripting.
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_symbol):
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_buffer = False):
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, showFuncName=True):
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(BasicFormatter):
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(BasicFormatter):
self.cindent = indent_child
def format(self, value, buffer=None):
if not buffer:
output = StringIO.StringIO()
output = SixStringIO()
else:
output = buffer

View File

@ -3,6 +3,8 @@ Use lldb Python SBFrame API to get the argument values of the call stacks.
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.

View File

@ -8,8 +8,9 @@ Provides classes used by the test results reporting infrastructure
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."""

View File

@ -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()))

View File

@ -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

View File

@ -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