Fix byte vs string error in Python 3.7

This commit is contained in:
Roland Rossgotterer
2019-02-05 10:12:34 +01:00
committed by Mat Sutcliffe
parent fb46947252
commit f63d6cc392
2 changed files with 4 additions and 10 deletions

View File

@@ -38,7 +38,7 @@ def get_environment_from_batch_command(env_cmd, initial=None):
# Construct the command that will alter the environment.
env_cmd = subprocess.list2cmdline(env_cmd)
# Create a tag so we can tell in the output when the proc is done.
tag = 'END OF BATCH COMMAND'
tag = b'END OF BATCH COMMAND'
# Construct a cmd.exe command to do accomplish this.
cmd = 'cmd.exe /s /c "{env_cmd} && echo "{tag}" && set"'.format(**vars())
# Launch the process.
@@ -48,7 +48,7 @@ def get_environment_from_batch_command(env_cmd, initial=None):
# Consume whatever output occurs until the tag is reached.
consume(itertools.takewhile(lambda l: tag not in l, lines))
# Define a way to handle each KEY=VALUE line.
handle_line = lambda l: l.rstrip().split('=', 1)
handle_line = lambda l: l.decode('utf-8').rstrip().split('=', 1)
# Parse key/values into pairs.
pairs = map(handle_line, lines)
# Make sure the pairs are valid.

View File

@@ -312,12 +312,6 @@ class Dumper:
# FILE index filename
(x, index, filename) = line.rstrip().split(None, 2)
filename = os.path.normpath(self.fix_filename_case(filename))
# We want original file paths for the source server.
sourcepath = filename
# gather up files with hg for indexing
if filename.startswith("hg"):
(ver, checkout, source_file, revision) = filename.split(":", 3)
source_file_stream += sourcepath + "*" + source_file + '*' + revision + "\r\n"
f.write("FILE %s %s\n" % (index, filename))
elif line.startswith("INFO CODE_ID "):
# INFO CODE_ID code_id code_file
@@ -379,8 +373,8 @@ class DumperWin32(Dumper):
result = file_name
ctypes.windll.kernel32.SetErrorMode(ctypes.c_uint(1))
if not isinstance(file_name, unicode):
file_name = unicode(file_name, sys.getfilesystemencoding())
if not isinstance(file_name, str):
file_name = file_name.decode(sys.getfilesystemencoding())
handle = ctypes.windll.kernel32.CreateFileW(file_name,
# GENERIC_READ
0x80000000,