Mercurial > hg
changeset 45727:d4c4391aa7f2
pycompat: add an entry for unnamedtmpfile
I am going to use unnamed temporary files to pass arbitrarily large input data
to worker creating bundles. To do so, I need a unified API that work on py2 and
py3.
Differential Revision: https://phab.mercurial-scm.org/D9211
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 14 Oct 2020 17:51:56 +0200 |
parents | d1072cba8aff |
children | 232c88dd89e3 |
files | mercurial/pycompat.py |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/pycompat.py Wed Oct 14 21:47:14 2020 +0200 +++ b/mercurial/pycompat.py Wed Oct 14 17:51:56 2020 +0200 @@ -506,6 +506,17 @@ return tempfile.mkstemp(suffix, prefix, dir) +# TemporaryFile does not support an "encoding=" argument on python2. +# This wrapper file are always open in byte mode. +def unnamedtempfile(mode=None, *args, **kwargs): + if mode is None: + mode = b'w+b' + else: + mode = sysstr(mode) + assert 'b' in mode + return tempfile.TemporaryFile(mode, *args, **kwargs) + + # NamedTemporaryFile does not support an "encoding=" argument on python2. # This wrapper file are always open in byte mode. def namedtempfile(