Fixes a Python 3 compat error when using the external bundle store.
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- stable
- Lint
No Linters Available - Unit
No Unit Test Coverage
Fixes a Python 3 compat error when using the external bundle store.
No Linters Available |
No Unit Test Coverage |
In D8780#131431, @pulkit wrote:Removed unused tempfile import in flight to make test-check-pyflakes.t happy.
Thanks!
Path | Packages | |||
---|---|---|---|---|
M | hgext/infinitepush/store.py (9 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
165c38f391ca | a17454a189d1 | Connor Sheehan | Apr 22 2020, 5:59 PM |
node, | node, | ||||
pycompat, | pycompat, | ||||
) | ) | ||||
from mercurial.utils import ( | from mercurial.utils import ( | ||||
hashutil, | hashutil, | ||||
procutil, | procutil, | ||||
) | ) | ||||
NamedTemporaryFile = tempfile.NamedTemporaryFile | |||||
class BundleWriteException(Exception): | class BundleWriteException(Exception): | ||||
pass | pass | ||||
class BundleReadException(Exception): | class BundleReadException(Exception): | ||||
pass | pass | ||||
returncode = p.returncode | returncode = p.returncode | ||||
return returncode, stdout, stderr | return returncode, stdout, stderr | ||||
def write(self, data): | def write(self, data): | ||||
# 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() and replace NamedTemporaryFile() | # TODO: rewrite without str.format() and replace NamedTemporaryFile() | ||||
# with pycompat.namedtempfile() | # with pycompat.namedtempfile() | ||||
with NamedTemporaryFile() as temp: | with pycompat.namedtempfile() as temp: | ||||
temp.write(data) | temp.write(data) | ||||
temp.flush() | temp.flush() | ||||
temp.seek(0) | temp.seek(0) | ||||
formatted_args = [ | formatted_args = [ | ||||
arg.format(filename=temp.name) for arg in self.put_args | arg.format(filename=temp.name) for arg in self.put_args | ||||
] | ] | ||||
returncode, stdout, stderr = self._call_binary( | returncode, stdout, stderr = self._call_binary( | ||||
[self.put_binary] + formatted_args | [self.put_binary] + formatted_args | ||||
else: | else: | ||||
raise BundleWriteException( | raise BundleWriteException( | ||||
b'Bad output from %s: %s' % (self.put_binary, stdout) | b'Bad output from %s: %s' % (self.put_binary, stdout) | ||||
) | ) | ||||
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() and replace NamedTemporaryFile() | # TODO: rewrite without str.format() | ||||
# with pycompat.namedtempfile() | with pycompat.namedtempfile() as temp: | ||||
with NamedTemporaryFile() as temp: | |||||
formatted_args = [ | formatted_args = [ | ||||
arg.format(filename=temp.name, handle=handle) | arg.format(filename=temp.name, handle=handle) | ||||
for arg in self.get_args | 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 | ||||
) | ) | ||||
if returncode != 0: | if returncode != 0: | ||||
raise BundleReadException( | raise BundleReadException( | ||||
b'Failed to download from external store: %s' % stderr | b'Failed to download from external store: %s' % stderr | ||||
) | ) | ||||
return temp.read() | return temp.read() |