Apply Python 3 futurize transform libmodernize.fixes.fix_basestring.

This commit is contained in:
Tim Abbott 2015-11-01 08:14:25 -08:00
parent 328816a329
commit abd939f16d

View file

@ -8,7 +8,9 @@
# License: MIT <http://www.opensource.org/licenses/mit-license.php> # License: MIT <http://www.opensource.org/licenses/mit-license.php>
# #
from __future__ import print_function from __future__ import print_function
from __future__ import absolute_import
import sys import sys
import six
if sys.hexversion < 0x02040000: if sys.hexversion < 0x02040000:
# The limiter is the subprocess module # The limiter is the subprocess module
sys.stderr.write("git-p4: requires Python 2.4 or later.\n") sys.stderr.write("git-p4: requires Python 2.4 or later.\n")
@ -53,7 +55,7 @@ def p4_build_cmd(cmd):
""" """
real_cmd = ["p4"] real_cmd = ["p4"]
if isinstance(cmd, basestring): if isinstance(cmd, six.string_types):
real_cmd = ' '.join(real_cmd) + ' ' + cmd real_cmd = ' '.join(real_cmd) + ' ' + cmd
else: else:
real_cmd += cmd real_cmd += cmd
@ -92,7 +94,7 @@ def write_pipe(c, stdin):
if verbose: if verbose:
sys.stderr.write('Writing pipe: %s\n' % str(c)) sys.stderr.write('Writing pipe: %s\n' % str(c))
expand = isinstance(c, basestring) expand = isinstance(c, six.string_types)
p = subprocess.Popen(c, stdin=subprocess.PIPE, shell=expand) p = subprocess.Popen(c, stdin=subprocess.PIPE, shell=expand)
pipe = p.stdin pipe = p.stdin
val = pipe.write(stdin) val = pipe.write(stdin)
@ -110,7 +112,7 @@ def read_pipe(c, ignore_error=False):
if verbose: if verbose:
sys.stderr.write('Reading pipe: %s\n' % str(c)) sys.stderr.write('Reading pipe: %s\n' % str(c))
expand = isinstance(c, basestring) expand = isinstance(c, six.string_types)
p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand) p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
pipe = p.stdout pipe = p.stdout
val = pipe.read() val = pipe.read()
@ -127,7 +129,7 @@ def read_pipe_lines(c):
if verbose: if verbose:
sys.stderr.write('Reading pipe: %s\n' % str(c)) sys.stderr.write('Reading pipe: %s\n' % str(c))
expand = isinstance(c, basestring) expand = isinstance(c, six.string_types)
p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand) p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
pipe = p.stdout pipe = p.stdout
val = pipe.readlines() val = pipe.readlines()
@ -170,7 +172,7 @@ def p4_has_move_command():
return True return True
def system(cmd): def system(cmd):
expand = isinstance(cmd, basestring) expand = isinstance(cmd, six.string_types)
if verbose: if verbose:
sys.stderr.write("executing %s\n" % str(cmd)) sys.stderr.write("executing %s\n" % str(cmd))
retcode = subprocess.call(cmd, shell=expand) retcode = subprocess.call(cmd, shell=expand)
@ -180,7 +182,7 @@ def system(cmd):
def p4_system(cmd): def p4_system(cmd):
"""Specifically invoke p4 as the system command. """ """Specifically invoke p4 as the system command. """
real_cmd = p4_build_cmd(cmd) real_cmd = p4_build_cmd(cmd)
expand = isinstance(real_cmd, basestring) expand = isinstance(real_cmd, six.string_types)
retcode = subprocess.call(real_cmd, shell=expand) retcode = subprocess.call(real_cmd, shell=expand)
if retcode: if retcode:
raise CalledProcessError(retcode, real_cmd) raise CalledProcessError(retcode, real_cmd)
@ -357,7 +359,7 @@ def getP4OpenedType(file):
# Return the set of all p4 labels # Return the set of all p4 labels
def getP4Labels(depotPaths): def getP4Labels(depotPaths):
labels = set() labels = set()
if isinstance(depotPaths, basestring): if isinstance(depotPaths, six.string_types):
depotPaths = [depotPaths] depotPaths = [depotPaths]
for l in p4CmdList(["labels"] + ["%s..." % p for p in depotPaths]): for l in p4CmdList(["labels"] + ["%s..." % p for p in depotPaths]):
@ -424,7 +426,7 @@ def isModeExecChanged(src_mode, dst_mode):
def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None): def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None):
if isinstance(cmd, basestring): if isinstance(cmd, six.string_types):
cmd = "-G " + cmd cmd = "-G " + cmd
expand = True expand = True
else: else:
@ -441,7 +443,7 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None):
stdin_file = None stdin_file = None
if stdin is not None: if stdin is not None:
stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode) stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode)
if isinstance(stdin, basestring): if isinstance(stdin, six.string_types):
stdin_file.write(stdin) stdin_file.write(stdin)
else: else:
for i in stdin: for i in stdin: