Commit a0fff9f2 authored by Robert Bradshaw's avatar Robert Bradshaw

Some Python 2.3 cleanup.

parent 5ace507f
from glob import glob from glob import glob
import re, os, sys import re, os, sys
from cython import set
from distutils.extension import Extension from distutils.extension import Extension
...@@ -8,7 +7,6 @@ from distutils.extension import Extension ...@@ -8,7 +7,6 @@ from distutils.extension import Extension
from Cython import Utils from Cython import Utils
from Cython.Compiler.Main import Context, CompilationOptions, default_options from Cython.Compiler.Main import Context, CompilationOptions, default_options
# Unfortunately, Python 2.3 doesn't support decorators.
def cached_method(f): def cached_method(f):
cache_name = '__%s_cache' % f.__name__ cache_name = '__%s_cache' % f.__name__
def wrapper(self, *args): def wrapper(self, *args):
...@@ -254,12 +252,11 @@ class DependencyTree(object): ...@@ -254,12 +252,11 @@ class DependencyTree(object):
self.context = context self.context = context
self._transitive_cache = {} self._transitive_cache = {}
#@cached_method @cached_method
def parse_dependencies(self, source_filename): def parse_dependencies(self, source_filename):
return parse_dependencies(source_filename) return parse_dependencies(source_filename)
parse_dependencies = cached_method(parse_dependencies)
@cached_method
#@cached_method
def cimports_and_externs(self, filename): def cimports_and_externs(self, filename):
cimports, includes, externs = self.parse_dependencies(filename)[:3] cimports, includes, externs = self.parse_dependencies(filename)[:3]
cimports = set(cimports) cimports = set(cimports)
...@@ -275,25 +272,22 @@ class DependencyTree(object): ...@@ -275,25 +272,22 @@ class DependencyTree(object):
else: else:
print("Unable to locate '%s' referenced from '%s'" % (filename, include)) print("Unable to locate '%s' referenced from '%s'" % (filename, include))
return tuple(cimports), tuple(externs) return tuple(cimports), tuple(externs)
cimports_and_externs = cached_method(cimports_and_externs)
def cimports(self, filename): def cimports(self, filename):
return self.cimports_and_externs(filename)[0] return self.cimports_and_externs(filename)[0]
#@cached_method @cached_method
def package(self, filename): def package(self, filename):
dir = os.path.dirname(filename) dir = os.path.dirname(filename)
if os.path.exists(os.path.join(dir, '__init__.py')): if os.path.exists(os.path.join(dir, '__init__.py')):
return self.package(dir) + (os.path.basename(dir),) return self.package(dir) + (os.path.basename(dir),)
else: else:
return () return ()
package = cached_method(package)
#@cached_method @cached_method
def fully_qualifeid_name(self, filename): def fully_qualifeid_name(self, filename):
module = os.path.splitext(os.path.basename(filename))[0] module = os.path.splitext(os.path.basename(filename))[0]
return '.'.join(self.package(filename) + (module,)) return '.'.join(self.package(filename) + (module,))
fully_qualifeid_name = cached_method(fully_qualifeid_name)
def find_pxd(self, module, filename=None): def find_pxd(self, module, filename=None):
if module[0] == '.': if module[0] == '.':
...@@ -306,7 +300,7 @@ class DependencyTree(object): ...@@ -306,7 +300,7 @@ class DependencyTree(object):
return self.context.find_pxd_file(module, None) return self.context.find_pxd_file(module, None)
find_pxd = cached_method(find_pxd) find_pxd = cached_method(find_pxd)
#@cached_method @cached_method
def cimported_files(self, filename): def cimported_files(self, filename):
if filename[-4:] == '.pyx' and os.path.exists(filename[:-4] + '.pxd'): if filename[-4:] == '.pyx' and os.path.exists(filename[:-4] + '.pxd'):
self_pxd = [filename[:-4] + '.pxd'] self_pxd = [filename[:-4] + '.pxd']
...@@ -319,7 +313,6 @@ class DependencyTree(object): ...@@ -319,7 +313,6 @@ class DependencyTree(object):
print("\n\t".join(a)) print("\n\t".join(a))
print("\n\t".join(b)) print("\n\t".join(b))
return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)])) return tuple(self_pxd + filter(None, [self.find_pxd(m, filename) for m in self.cimports(filename)]))
cimported_files = cached_method(cimported_files)
def immediate_dependencies(self, filename): def immediate_dependencies(self, filename):
all = list(self.cimported_files(filename)) all = list(self.cimported_files(filename))
...@@ -327,10 +320,9 @@ class DependencyTree(object): ...@@ -327,10 +320,9 @@ class DependencyTree(object):
all.append(os.path.normpath(os.path.join(os.path.dirname(filename), extern))) all.append(os.path.normpath(os.path.join(os.path.dirname(filename), extern)))
return tuple(all) return tuple(all)
#@cached_method @cached_method
def timestamp(self, filename): def timestamp(self, filename):
return os.path.getmtime(filename) return os.path.getmtime(filename)
timestamp = cached_method(timestamp)
def extract_timestamp(self, filename): def extract_timestamp(self, filename):
# TODO: .h files from extern blocks # TODO: .h files from extern blocks
......
import tempfile import tempfile
import sys, os, re, inspect import sys, os, re, inspect
from cython import set
try: try:
import hashlib import hashlib
......
...@@ -10,11 +10,6 @@ import PyrexTypes ...@@ -10,11 +10,6 @@ import PyrexTypes
import Naming import Naming
import Symtab import Symtab
try:
set
except NameError:
from sets import Set as set
import textwrap import textwrap
def dedent(text, reindent=0): def dedent(text, reindent=0):
......
...@@ -118,13 +118,13 @@ class FunctionState(object): ...@@ -118,13 +118,13 @@ class FunctionState(object):
# exc_vars (string * 3) exception variables for reraise, or None # exc_vars (string * 3) exception variables for reraise, or None
# Not used for now, perhaps later # Not used for now, perhaps later
def __init__(self, owner, names_taken=cython.set()): def __init__(self, owner, names_taken=set()):
self.names_taken = names_taken self.names_taken = names_taken
self.owner = owner self.owner = owner
self.error_label = None self.error_label = None
self.label_counter = 0 self.label_counter = 0
self.labels_used = cython.set() self.labels_used = set()
self.return_label = self.new_label() self.return_label = self.new_label()
self.new_error_label() self.new_error_label()
self.continue_label = None self.continue_label = None
...@@ -309,7 +309,7 @@ class FunctionState(object): ...@@ -309,7 +309,7 @@ class FunctionState(object):
""" """
Useful to find out which temps were used in a code block Useful to find out which temps were used in a code block
""" """
self.collect_temps_stack.append(cython.set()) self.collect_temps_stack.append(set())
def stop_collecting_temps(self): def stop_collecting_temps(self):
return self.collect_temps_stack.pop() return self.collect_temps_stack.pop()
...@@ -504,7 +504,7 @@ class GlobalState(object): ...@@ -504,7 +504,7 @@ class GlobalState(object):
self.filename_table = {} self.filename_table = {}
self.filename_list = [] self.filename_list = []
self.input_file_contents = {} self.input_file_contents = {}
self.utility_codes = cython.set() self.utility_codes = set()
self.declared_cnames = {} self.declared_cnames = {}
self.in_utility_code_generation = False self.in_utility_code_generation = False
self.emit_linenums = emit_linenums self.emit_linenums = emit_linenums
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
# #
import cython import cython
from cython import set
cython.declare(error=object, warning=object, warn_once=object, InternalError=object, cython.declare(error=object, warning=object, warn_once=object, InternalError=object,
CompileError=object, UtilityCode=object, StringEncoding=object, operator=object, CompileError=object, UtilityCode=object, StringEncoding=object, operator=object,
Naming=object, Nodes=object, PyrexTypes=object, py_object_type=object, Naming=object, Nodes=object, PyrexTypes=object, py_object_type=object,
......
...@@ -13,8 +13,6 @@ from PyrexTypes import py_object_type, unspecified_type ...@@ -13,8 +13,6 @@ from PyrexTypes import py_object_type, unspecified_type
from Visitor import TreeVisitor, CythonTransform from Visitor import TreeVisitor, CythonTransform
from Errors import error, warning, CompileError, InternalError from Errors import error, warning, CompileError, InternalError
from cython import set
class TypedExprNode(ExprNodes.ExprNode): class TypedExprNode(ExprNodes.ExprNode):
# Used for declaring assignments of a specified type whithout a known entry. # Used for declaring assignments of a specified type whithout a known entry.
def __init__(self, type): def __init__(self, type):
...@@ -215,7 +213,7 @@ class ControlFlow(object): ...@@ -215,7 +213,7 @@ class ControlFlow(object):
offset = 0 offset = 0
for entry in self.entries: for entry in self.entries:
assmts = AssignmentList() assmts = AssignmentList()
assmts.bit = 1L << offset assmts.bit = 1 << offset
assmts.mask = assmts.bit assmts.mask = assmts.bit
self.assmts[entry] = assmts self.assmts[entry] = assmts
offset += 1 offset += 1
...@@ -223,7 +221,7 @@ class ControlFlow(object): ...@@ -223,7 +221,7 @@ class ControlFlow(object):
for block in self.blocks: for block in self.blocks:
for stat in block.stats: for stat in block.stats:
if isinstance(stat, NameAssignment): if isinstance(stat, NameAssignment):
stat.bit = 1L << offset stat.bit = 1 << offset
assmts = self.assmts[stat.entry] assmts = self.assmts[stat.entry]
assmts.stats.append(stat) assmts.stats.append(stat)
assmts.mask |= stat.bit assmts.mask |= stat.bit
...@@ -561,7 +559,7 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -561,7 +559,7 @@ class CreateControlFlowGraph(CythonTransform):
self.gv_ctx = GVContext() self.gv_ctx = GVContext()
# Set of NameNode reductions # Set of NameNode reductions
self.reductions = cython.set() self.reductions = set()
self.env_stack = [] self.env_stack = []
self.env = node.scope self.env = node.scope
...@@ -857,7 +855,7 @@ class CreateControlFlowGraph(CythonTransform): ...@@ -857,7 +855,7 @@ class CreateControlFlowGraph(CythonTransform):
# if node.target is None or not a NameNode, an error will have # if node.target is None or not a NameNode, an error will have
# been previously issued # been previously issued
if hasattr(node.target, 'entry'): if hasattr(node.target, 'entry'):
self.reductions = cython.set(reductions) self.reductions = set(reductions)
for private_node in node.assigned_nodes: for private_node in node.assigned_nodes:
private_node.entry.error_on_uninitialized = True private_node.entry.error_on_uninitialized = True
......
...@@ -7,12 +7,6 @@ if sys.version_info[:2] < (2, 3): ...@@ -7,12 +7,6 @@ if sys.version_info[:2] < (2, 3):
sys.stderr.write("Sorry, Cython requires Python 2.3 or later\n") sys.stderr.write("Sorry, Cython requires Python 2.3 or later\n")
sys.exit(1) sys.exit(1)
try:
set
except NameError:
# Python 2.3
from sets import Set as set
import itertools import itertools
import Code import Code
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
# #
import cython import cython
from cython import set
cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=object, cython.declare(Naming=object, Options=object, PyrexTypes=object, TypeSlots=object,
error=object, warning=object, py_object_type=object, UtilityCode=object, error=object, warning=object, py_object_type=object, UtilityCode=object,
EncodedString=object) EncodedString=object)
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
# Pyrex - Parse tree nodes # Pyrex - Parse tree nodes
# #
import cython import cython
from cython import set
cython.declare(sys=object, os=object, time=object, copy=object, cython.declare(sys=object, os=object, time=object, copy=object,
Builtin=object, error=object, warning=object, Naming=object, PyrexTypes=object, Builtin=object, error=object, warning=object, Naming=object, PyrexTypes=object,
py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object, \ py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object, \
......
import cython import cython
from cython import set
cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object, cython.declare(UtilityCode=object, EncodedString=object, BytesLiteral=object,
Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object, Nodes=object, ExprNodes=object, PyrexTypes=object, Builtin=object,
UtilNodes=object, Naming=object) UtilNodes=object, Naming=object)
......
...@@ -339,7 +339,7 @@ def eliminate_rhs_duplicates(expr_list_list, ref_node_sequence): ...@@ -339,7 +339,7 @@ def eliminate_rhs_duplicates(expr_list_list, ref_node_sequence):
and appends them to ref_node_sequence. The input list is modified and appends them to ref_node_sequence. The input list is modified
in-place. in-place.
""" """
seen_nodes = cython.set() seen_nodes = set()
ref_nodes = {} ref_nodes = {}
def find_duplicates(node): def find_duplicates(node):
if node.is_literal or node.is_name: if node.is_literal or node.is_name:
...@@ -610,11 +610,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -610,11 +610,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
'operator.comma' : ExprNodes.c_binop_constructor(','), 'operator.comma' : ExprNodes.c_binop_constructor(','),
} }
special_methods = cython.set(['declare', 'union', 'struct', 'typedef', 'sizeof', special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof',
'cast', 'pointer', 'compiled', 'NULL', 'parallel']) 'cast', 'pointer', 'compiled', 'NULL', 'parallel'])
special_methods.update(unop_method_nodes.keys()) special_methods.update(unop_method_nodes.keys())
valid_parallel_directives = cython.set([ valid_parallel_directives = set([
"parallel", "parallel",
"prange", "prange",
"threadid", "threadid",
...@@ -626,7 +626,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations): ...@@ -626,7 +626,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self.compilation_directive_defaults = {} self.compilation_directive_defaults = {}
for key, value in compilation_directive_defaults.items(): for key, value in compilation_directive_defaults.items():
self.compilation_directive_defaults[unicode(key)] = copy.deepcopy(value) self.compilation_directive_defaults[unicode(key)] = copy.deepcopy(value)
self.cython_module_names = cython.set() self.cython_module_names = set()
self.directive_names = {} self.directive_names = {}
self.parallel_directives = {} self.parallel_directives = {}
...@@ -1380,7 +1380,7 @@ if VALUE is not None: ...@@ -1380,7 +1380,7 @@ if VALUE is not None:
return node return node
def visit_ModuleNode(self, node): def visit_ModuleNode(self, node):
self.seen_vars_stack.append(cython.set()) self.seen_vars_stack.append(set())
node.analyse_declarations(self.env_stack[-1]) node.analyse_declarations(self.env_stack[-1])
self.visitchildren(node) self.visitchildren(node)
self.seen_vars_stack.pop() self.seen_vars_stack.pop()
...@@ -1412,7 +1412,7 @@ if VALUE is not None: ...@@ -1412,7 +1412,7 @@ if VALUE is not None:
return node return node
def visit_FuncDefNode(self, node): def visit_FuncDefNode(self, node):
self.seen_vars_stack.append(cython.set()) self.seen_vars_stack.append(set())
lenv = node.local_scope lenv = node.local_scope
node.declare_arguments(lenv) node.declare_arguments(lenv)
for var, type_node in node.directive_locals.items(): for var, type_node in node.directive_locals.items():
...@@ -1446,7 +1446,7 @@ if VALUE is not None: ...@@ -1446,7 +1446,7 @@ if VALUE is not None:
node.analyse_declarations(env) node.analyse_declarations(env)
# the node may or may not have a local scope # the node may or may not have a local scope
if node.has_local_scope: if node.has_local_scope:
self.seen_vars_stack.append(cython.set(self.seen_vars_stack[-1])) self.seen_vars_stack.append(set(self.seen_vars_stack[-1]))
self.env_stack.append(node.expr_scope) self.env_stack.append(node.expr_scope)
node.analyse_scoped_declarations(node.expr_scope) node.analyse_scoped_declarations(node.expr_scope)
self.visitchildren(node) self.visitchildren(node)
...@@ -2345,7 +2345,7 @@ class DebugTransform(CythonTransform): ...@@ -2345,7 +2345,7 @@ class DebugTransform(CythonTransform):
def __init__(self, context, options, result): def __init__(self, context, options, result):
super(DebugTransform, self).__init__(context) super(DebugTransform, self).__init__(context)
self.visited = cython.set() self.visited = set()
# our treebuilder and debug output writer # our treebuilder and debug output writer
# (see Cython.Debugger.debug_output.CythonDebugWriter) # (see Cython.Debugger.debug_output.CythonDebugWriter)
self.tb = self.context.gdb_debug_outputwriter self.tb = self.context.gdb_debug_outputwriter
......
...@@ -875,7 +875,7 @@ def p_comp_for(s, body): ...@@ -875,7 +875,7 @@ def p_comp_for(s, body):
pos = s.position() pos = s.position()
s.next() s.next()
kw = p_for_bounds(s, allow_testlist=False) kw = p_for_bounds(s, allow_testlist=False)
kw.update(dict(else_clause = None, body = p_comp_iter(s, body))) kw.update(else_clause = None, body = p_comp_iter(s, body))
return Nodes.ForStatNode(pos, **kw) return Nodes.ForStatNode(pos, **kw)
def p_comp_if(s, body): def p_comp_if(s, body):
...@@ -1404,7 +1404,7 @@ def p_for_statement(s): ...@@ -1404,7 +1404,7 @@ def p_for_statement(s):
kw = p_for_bounds(s, allow_testlist=True) kw = p_for_bounds(s, allow_testlist=True)
body = p_suite(s) body = p_suite(s)
else_clause = p_else_clause(s) else_clause = p_else_clause(s)
kw.update(dict(body = body, else_clause = else_clause)) kw.update(body = body, else_clause = else_clause)
return Nodes.ForStatNode(pos, **kw) return Nodes.ForStatNode(pos, **kw)
def p_for_bounds(s, allow_testlist=True): def p_for_bounds(s, allow_testlist=True):
...@@ -2187,7 +2187,7 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag): ...@@ -2187,7 +2187,7 @@ def p_c_func_declarator(s, pos, ctx, base, cmethod_flag):
exception_value = exc_val, exception_check = exc_check, exception_value = exc_val, exception_check = exc_check,
nogil = nogil or ctx.nogil or with_gil, with_gil = with_gil) nogil = nogil or ctx.nogil or with_gil, with_gil = with_gil)
supported_overloaded_operators = cython.set([ supported_overloaded_operators = set([
'+', '-', '*', '/', '%', '+', '-', '*', '/', '%',
'++', '--', '~', '|', '&', '^', '<<', '>>', ',', '++', '--', '~', '|', '&', '^', '<<', '>>', ',',
'==', '!=', '>=', '>', '<=', '<', '==', '!=', '>=', '>', '<=', '<',
......
...@@ -282,10 +282,10 @@ class PyrexScanner(Scanner): ...@@ -282,10 +282,10 @@ class PyrexScanner(Scanner):
self.source_encoding = source_encoding self.source_encoding = source_encoding
if filename.is_python_file(): if filename.is_python_file():
self.in_python_file = True self.in_python_file = True
self.keywords = cython.set(py_reserved_words) self.keywords = set(py_reserved_words)
else: else:
self.in_python_file = False self.in_python_file = False
self.keywords = cython.set(pyx_reserved_words) self.keywords = set(pyx_reserved_words)
self.trace = trace_scanner self.trace = trace_scanner
self.indentation_stack = [0] self.indentation_stack = [0]
self.indentation_char = None self.indentation_char = None
......
...@@ -15,11 +15,6 @@ from TypeSlots import \ ...@@ -15,11 +15,6 @@ from TypeSlots import \
get_special_method_signature, get_property_accessor_signature get_special_method_signature, get_property_accessor_signature
import Code import Code
import __builtin__ as builtins import __builtin__ as builtins
try:
set
except NameError:
from sets import Set as set
import copy
possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match
......
...@@ -7,12 +7,6 @@ from Cython import Utils ...@@ -7,12 +7,6 @@ from Cython import Utils
from PyrexTypes import py_object_type, unspecified_type from PyrexTypes import py_object_type, unspecified_type
from Visitor import CythonTransform from Visitor import CythonTransform
try:
set
except NameError:
# Python 2.3
from sets import Set as set
class TypedExprNode(ExprNodes.ExprNode): class TypedExprNode(ExprNodes.ExprNode):
# Used for declaring assignments of a specified type whithout a known entry. # Used for declaring assignments of a specified type whithout a known entry.
......
...@@ -239,17 +239,6 @@ py_float = float ...@@ -239,17 +239,6 @@ py_float = float
py_complex = complex py_complex = complex
try:
# Python 3
from builtins import set, frozenset
except ImportError:
try:
# Python 2.4+
from __builtin__ import set, frozenset
except ImportError:
# Py 2.3
from sets import Set as set, ImmutableSet as frozenset
# Predefined types # Predefined types
int_types = ['char', 'short', 'Py_UNICODE', 'int', 'long', 'longlong', 'Py_ssize_t', 'size_t'] int_types = ['char', 'short', 'Py_UNICODE', 'int', 'long', 'longlong', 'Py_ssize_t', 'size_t']
......
...@@ -11,9 +11,11 @@ import time ...@@ -11,9 +11,11 @@ import time
import unittest import unittest
import doctest import doctest
import operator import operator
import subprocess
import tempfile import tempfile
import warnings
import traceback import traceback
import warnings
try: try:
from StringIO import StringIO from StringIO import StringIO
except ImportError: except ImportError:
...@@ -116,24 +118,13 @@ def get_openmp_compiler_flags(language): ...@@ -116,24 +118,13 @@ def get_openmp_compiler_flags(language):
matcher = re.compile(r"gcc version (\d+\.\d+)").search matcher = re.compile(r"gcc version (\d+\.\d+)").search
try: try:
import subprocess p = subprocess.Popen([cc, "-v"], stderr=subprocess.PIPE)
except ImportError: except EnvironmentError:
try: # Be compatible with Python 3
in_, out_err = os.popen4([cc, "-v"]) warnings.warn("Unable to find the %s compiler: %s: %s" %
except EnvironmentError: (language, os.strerror(sys.exc_info()[1].errno), cc))
warnings.warn("Unable to find the %s compiler: %s: %s" % return None
(language, os.strerror(sys.exc_info()[1].errno), cc)) _, output = p.communicate()
return None
output = out_err.read()
else:
try:
p = subprocess.Popen([cc, "-v"], stderr=subprocess.PIPE)
except EnvironmentError:
# Be compatible with Python 3
warnings.warn("Unable to find the %s compiler: %s: %s" %
(language, os.strerror(sys.exc_info()[1].errno), cc))
return None
_, output = p.communicate()
output = output.decode(locale.getpreferredencoding() or 'ASCII', 'replace') output = output.decode(locale.getpreferredencoding() or 'ASCII', 'replace')
...@@ -1036,20 +1027,16 @@ class EndToEndTest(unittest.TestCase): ...@@ -1036,20 +1027,16 @@ class EndToEndTest(unittest.TestCase):
old_path = os.environ.get('PYTHONPATH') old_path = os.environ.get('PYTHONPATH')
os.environ['PYTHONPATH'] = self.cython_syspath + os.pathsep + os.path.join(self.cython_syspath, (old_path or '')) os.environ['PYTHONPATH'] = self.cython_syspath + os.pathsep + os.path.join(self.cython_syspath, (old_path or ''))
for command in commands.split('\n'): for command in commands.split('\n'):
if sys.version_info[:2] >= (2,4): p = subprocess.Popen(commands,
import subprocess stderr=subprocess.PIPE,
p = subprocess.Popen(commands, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, shell=True)
stdout=subprocess.PIPE, out, err = p.communicate()
shell=True) res = p.returncode
out, err = p.communicate() if res != 0:
res = p.returncode print(command)
if res != 0: print(out)
print(command) print(err)
print(out)
print(err)
else:
res = os.system(command)
self.assertEqual(0, res, "non-zero exit status") self.assertEqual(0, res, "non-zero exit status")
finally: finally:
if old_path: if old_path:
...@@ -1238,12 +1225,7 @@ def check_thread_termination(ignore_seen=True): ...@@ -1238,12 +1225,7 @@ def check_thread_termination(ignore_seen=True):
def subprocess_output(cmd): def subprocess_output(cmd):
try: try:
try: return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
import subprocess
except:
return os.popen4(cmd)[1].read()
else:
return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).communicate()[0]
except OSError: except OSError:
return '' return ''
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment