##// END OF EJS Templates
py3: wrap tempfile.NamedTemporaryFile() to return bytes fp.name...
Yuya Nishihara -
r38184:cc9aa887 default
parent child Browse files
Show More
@@ -120,6 +120,8 b' class externalbundlestore(abstractbundle'
120 def write(self, data):
120 def write(self, data):
121 # Won't work on windows because you can't open file second time without
121 # Won't work on windows because you can't open file second time without
122 # closing it
122 # closing it
123 # TODO: rewrite without str.format() and replace NamedTemporaryFile()
124 # with pycompat.namedtempfile()
123 with NamedTemporaryFile() as temp:
125 with NamedTemporaryFile() as temp:
124 temp.write(data)
126 temp.write(data)
125 temp.flush()
127 temp.flush()
@@ -142,6 +144,8 b' class externalbundlestore(abstractbundle'
142 def read(self, handle):
144 def read(self, handle):
143 # Won't work on windows because you can't open file second time without
145 # Won't work on windows because you can't open file second time without
144 # closing it
146 # closing it
147 # TODO: rewrite without str.format() and replace NamedTemporaryFile()
148 # with pycompat.namedtempfile()
145 with NamedTemporaryFile() as temp:
149 with NamedTemporaryFile() as temp:
146 formatted_args = [arg.format(filename=temp.name, handle=handle)
150 formatted_args = [arg.format(filename=temp.name, handle=handle)
147 for arg in self.get_args]
151 for arg in self.get_args]
@@ -21,7 +21,6 b' import stat'
21 import string
21 import string
22 import subprocess
22 import subprocess
23 import sys
23 import sys
24 import tempfile
25 import time
24 import time
26
25
27 from .i18n import _
26 from .i18n import _
@@ -970,7 +969,7 b' def debugfsinfo(ui, path="."):'
970 ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
969 ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
971 casesensitive = '(unknown)'
970 casesensitive = '(unknown)'
972 try:
971 try:
973 with tempfile.NamedTemporaryFile(prefix='.debugfsinfo', dir=path) as f:
972 with pycompat.namedtempfile(prefix='.debugfsinfo', dir=path) as f:
974 casesensitive = util.fscasesensitive(f.name) and 'yes' or 'no'
973 casesensitive = util.fscasesensitive(f.name) and 'yes' or 'no'
975 except OSError:
974 except OSError:
976 pass
975 pass
@@ -249,16 +249,15 b' def checklink(path):'
249 else:
249 else:
250 checkdir = path
250 checkdir = path
251 cachedir = None
251 cachedir = None
252 fscheckdir = pycompat.fsdecode(checkdir)
252 name = tempfile.mktemp(dir=pycompat.fsdecode(checkdir),
253 name = tempfile.mktemp(dir=fscheckdir,
254 prefix=r'checklink-')
253 prefix=r'checklink-')
255 name = pycompat.fsencode(name)
254 name = pycompat.fsencode(name)
256 try:
255 try:
257 fd = None
256 fd = None
258 if cachedir is None:
257 if cachedir is None:
259 fd = tempfile.NamedTemporaryFile(dir=fscheckdir,
258 fd = pycompat.namedtempfile(dir=checkdir,
260 prefix=r'hg-checklink-')
259 prefix='hg-checklink-')
261 target = pycompat.fsencode(os.path.basename(fd.name))
260 target = os.path.basename(fd.name)
262 else:
261 else:
263 # create a fixed file to link to; doesn't matter if it
262 # create a fixed file to link to; doesn't matter if it
264 # already exists.
263 # already exists.
@@ -392,3 +392,11 b" def mkdtemp(suffix=b'', prefix=b'tmp', d"
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)
General Comments 0
You need to be logged in to leave comments. Login now