Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/pycompat.py @ 38199:cc9aa88792fe
py3: wrap tempfile.NamedTemporaryFile() to return bytes fp.name
Unlike its name, tempfile.NamedTemporaryFile is not a class, so I renamed
the pycompat version to look like a plain function.
Since temp.name uses in the infinitepush extension aren't bytes-safe, this
patch leaves them unmodified. Another weird thing is tempfile.mktemp(),
which does not accept bytes suffix nor prefix. Sigh.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 26 May 2018 12:38:07 +0900 |
parents | 2ce60954b1b7 |
children | 79dd61a4554f |
comparison
equal
deleted
inserted
replaced
38198:2ce60954b1b7 | 38199:cc9aa88792fe |
---|---|
390 return tempfile.mkdtemp(suffix, prefix, dir) | 390 return tempfile.mkdtemp(suffix, prefix, dir) |
391 | 391 |
392 # text=True is not supported; use util.from/tonativeeol() instead | 392 # text=True is not supported; use util.from/tonativeeol() instead |
393 def mkstemp(suffix=b'', prefix=b'tmp', dir=None): | 393 def mkstemp(suffix=b'', prefix=b'tmp', dir=None): |
394 return tempfile.mkstemp(suffix, prefix, dir) | 394 return tempfile.mkstemp(suffix, prefix, dir) |
395 | |
396 # mode must include 'b'ytes as encoding= is not supported | |
397 def namedtempfile(mode=b'w+b', bufsize=-1, suffix=b'', prefix=b'tmp', dir=None, | |
398 delete=True): | |
399 mode = sysstr(mode) | |
400 assert r'b' in mode | |
401 return tempfile.NamedTemporaryFile(mode, bufsize, suffix=suffix, | |
402 prefix=prefix, dir=dir, delete=delete) |