Skip to content
Snippets Groups Projects
Commit e285655c37c5 authored by Connor Sheehan's avatar Connor Sheehan
Browse files

infinitepush: fix `{get,put}_args` formatting on Python 3

Calling `.format()` on a byte-string does not work, thus
causing an exception on Python 3. This commit adds a function
to paper over the difference.

Differential Revision: https://phab.mercurial-scm.org/D8781
parent a52bf967e90a
No related branches found
No related tags found
No related merge requests found
...@@ -106,6 +106,23 @@ ...@@ -106,6 +106,23 @@
return None return None
def format_placeholders_args(args, filename=None, handle=None):
"""Formats `args` with Infinitepush replacements.
Hack to get `str.format()`-ed strings working in a BC way with
bytes.
"""
formatted_args = []
for arg in args:
if filename and arg == b'{filename}':
formatted_args.append(filename)
elif handle and arg == b'{handle}':
formatted_args.append(handle)
else:
formatted_args.append(arg)
return formatted_args
class externalbundlestore(abstractbundlestore): class externalbundlestore(abstractbundlestore):
def __init__(self, put_binary, put_args, get_binary, get_args): def __init__(self, put_binary, put_args, get_binary, get_args):
""" """
...@@ -144,9 +161,9 @@ ...@@ -144,9 +161,9 @@
temp.write(data) temp.write(data)
temp.flush() temp.flush()
temp.seek(0) temp.seek(0)
formatted_args = [ formatted_args = format_placeholders_args(
arg.format(filename=temp.name) for arg in self.put_args self.put_args, filename=temp.name
] )
returncode, stdout, stderr = self._call_binary( returncode, stdout, stderr = self._call_binary(
[self.put_binary] + formatted_args [self.put_binary] + formatted_args
) )
...@@ -166,5 +183,4 @@ ...@@ -166,5 +183,4 @@
def read(self, handle): def read(self, handle):
# Won't work on windows because you can't open file second time without # Won't work on windows because you can't open file second time without
# closing it # closing it
# TODO: rewrite without str.format()
with pycompat.namedtempfile() as temp: with pycompat.namedtempfile() as temp:
...@@ -170,8 +186,7 @@ ...@@ -170,8 +186,7 @@
with pycompat.namedtempfile() as temp: with pycompat.namedtempfile() as temp:
formatted_args = [ formatted_args = format_placeholders_args(
arg.format(filename=temp.name, handle=handle) self.get_args, filename=temp.name, handle=handle
for arg in self.get_args )
]
returncode, stdout, stderr = self._call_binary( returncode, stdout, stderr = self._call_binary(
[self.get_binary] + formatted_args [self.get_binary] + formatted_args
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment