##// END OF EJS Templates
py3: wrap tempfile.mkstemp() to use bytes path...
Yuya Nishihara -
r38182:aac4be30 default
parent child Browse files
Show More
@@ -5,7 +5,6 b' from __future__ import absolute_import'
5
5
6 import os
6 import os
7 import re
7 import re
8 import tempfile
9 import xml.dom.minidom
8 import xml.dom.minidom
10
9
11 from mercurial.i18n import _
10 from mercurial.i18n import _
@@ -1225,7 +1224,7 b' class svn_sink(converter_sink, commandli'
1225 wdest = self.wjoin(dest)
1224 wdest = self.wjoin(dest)
1226 exists = os.path.lexists(wdest)
1225 exists = os.path.lexists(wdest)
1227 if exists:
1226 if exists:
1228 fd, tempname = tempfile.mkstemp(
1227 fd, tempname = pycompat.mkstemp(
1229 prefix='hg-copy-', dir=os.path.dirname(wdest))
1228 prefix='hg-copy-', dir=os.path.dirname(wdest))
1230 os.close(fd)
1229 os.close(fd)
1231 os.unlink(tempname)
1230 os.unlink(tempname)
@@ -1313,7 +1312,7 b' class svn_sink(converter_sink, commandli'
1313 self.xargs(self.setexec, 'propset', 'svn:executable', '*')
1312 self.xargs(self.setexec, 'propset', 'svn:executable', '*')
1314 self.setexec = []
1313 self.setexec = []
1315
1314
1316 fd, messagefile = tempfile.mkstemp(prefix='hg-convert-')
1315 fd, messagefile = pycompat.mkstemp(prefix='hg-convert-')
1317 fp = os.fdopen(fd, r'wb')
1316 fp = os.fdopen(fd, r'wb')
1318 fp.write(util.tonativeeol(commit.desc))
1317 fp.write(util.tonativeeol(commit.desc))
1319 fp.close()
1318 fp.close()
@@ -9,7 +9,6 b' from __future__ import absolute_import'
9
9
10 import binascii
10 import binascii
11 import os
11 import os
12 import tempfile
13
12
14 from mercurial.i18n import _
13 from mercurial.i18n import _
15 from mercurial import (
14 from mercurial import (
@@ -61,11 +60,11 b' class gpg(object):'
61 sigfile = datafile = None
60 sigfile = datafile = None
62 try:
61 try:
63 # create temporary files
62 # create temporary files
64 fd, sigfile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".sig")
63 fd, sigfile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".sig")
65 fp = os.fdopen(fd, r'wb')
64 fp = os.fdopen(fd, r'wb')
66 fp.write(sig)
65 fp.write(sig)
67 fp.close()
66 fp.close()
68 fd, datafile = tempfile.mkstemp(prefix="hg-gpg-", suffix=".txt")
67 fd, datafile = pycompat.mkstemp(prefix="hg-gpg-", suffix=".txt")
69 fp = os.fdopen(fd, r'wb')
68 fp = os.fdopen(fd, r'wb')
70 fp.write(data)
69 fp.write(data)
71 fp.close()
70 fp.close()
@@ -94,7 +94,6 b' import random'
94 import re
94 import re
95 import socket
95 import socket
96 import subprocess
96 import subprocess
97 import tempfile
98 import time
97 import time
99
98
100 from mercurial.node import (
99 from mercurial.node import (
@@ -912,7 +911,7 b' def storetobundlestore(orig, repo, op, u'
912
911
913 # storing the bundle in the bundlestore
912 # storing the bundle in the bundlestore
914 buf = util.chunkbuffer(bundler.getchunks())
913 buf = util.chunkbuffer(bundler.getchunks())
915 fd, bundlefile = tempfile.mkstemp()
914 fd, bundlefile = pycompat.mkstemp()
916 try:
915 try:
917 try:
916 try:
918 fp = os.fdopen(fd, r'wb')
917 fp = os.fdopen(fd, r'wb')
@@ -998,7 +997,7 b' def processparts(orig, repo, op, unbundl'
998 # If commits were sent, store them
997 # If commits were sent, store them
999 if cgparams:
998 if cgparams:
1000 buf = util.chunkbuffer(bundler.getchunks())
999 buf = util.chunkbuffer(bundler.getchunks())
1001 fd, bundlefile = tempfile.mkstemp()
1000 fd, bundlefile = pycompat.mkstemp()
1002 try:
1001 try:
1003 try:
1002 try:
1004 fp = os.fdopen(fd, r'wb')
1003 fp = os.fdopen(fd, r'wb')
@@ -1023,8 +1022,7 b' def storebundle(op, params, bundlefile):'
1023
1022
1024 bundle = None
1023 bundle = None
1025 try: # guards bundle
1024 try: # guards bundle
1026 bundlepath = "bundle:%s+%s" % (op.repo.root,
1025 bundlepath = "bundle:%s+%s" % (op.repo.root, bundlefile)
1027 pycompat.fsencode(bundlefile))
1028 bundle = hg.repository(op.repo.ui, bundlepath)
1026 bundle = hg.repository(op.repo.ui, bundlepath)
1029
1027
1030 bookmark = params.get('bookmark')
1028 bookmark = params.get('bookmark')
@@ -1111,7 +1109,7 b' def bundle2scratchbranch(op, part):'
1111 bundler.addpart(cgpart)
1109 bundler.addpart(cgpart)
1112 buf = util.chunkbuffer(bundler.getchunks())
1110 buf = util.chunkbuffer(bundler.getchunks())
1113
1111
1114 fd, bundlefile = tempfile.mkstemp()
1112 fd, bundlefile = pycompat.mkstemp()
1115 try:
1113 try:
1116 try:
1114 try:
1117 fp = os.fdopen(fd, r'wb')
1115 fp = os.fdopen(fd, r'wb')
@@ -6,13 +6,13 b''
6 from __future__ import absolute_import
6 from __future__ import absolute_import
7
7
8 import os
8 import os
9 import tempfile
10
9
11 from mercurial.node import hex
10 from mercurial.node import hex
12
11
13 from mercurial import (
12 from mercurial import (
14 error,
13 error,
15 extensions,
14 extensions,
15 pycompat,
16 )
16 )
17
17
18 def isremotebooksenabled(ui):
18 def isremotebooksenabled(ui):
@@ -30,7 +30,7 b' def downloadbundle(repo, unknownbinhead)'
30
30
31 def _makebundlefromraw(data):
31 def _makebundlefromraw(data):
32 fp = None
32 fp = None
33 fd, bundlefile = tempfile.mkstemp()
33 fd, bundlefile = pycompat.mkstemp()
34 try: # guards bundlefile
34 try: # guards bundlefile
35 try: # guards fp
35 try: # guards fp
36 fp = os.fdopen(fd, 'wb')
36 fp = os.fdopen(fd, 'wb')
@@ -16,7 +16,7 b' map from a changeset hash to its hash in'
16 from __future__ import absolute_import
16 from __future__ import absolute_import
17
17
18 import os
18 import os
19 import tempfile
19
20 from mercurial.i18n import _
20 from mercurial.i18n import _
21 from mercurial import (
21 from mercurial import (
22 bundlerepo,
22 bundlerepo,
@@ -215,7 +215,7 b' class transplanter(object):'
215 if skipmerge:
215 if skipmerge:
216 patchfile = None
216 patchfile = None
217 else:
217 else:
218 fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
218 fd, patchfile = pycompat.mkstemp(prefix='hg-transplant-')
219 fp = os.fdopen(fd, r'wb')
219 fp = os.fdopen(fd, r'wb')
220 gen = patch.diff(source, parent, node, opts=diffopts)
220 gen = patch.diff(source, parent, node, opts=diffopts)
221 for chunk in gen:
221 for chunk in gen:
@@ -263,7 +263,7 b' class transplanter(object):'
263
263
264 self.ui.status(_('filtering %s\n') % patchfile)
264 self.ui.status(_('filtering %s\n') % patchfile)
265 user, date, msg = (changelog[1], changelog[2], changelog[4])
265 user, date, msg = (changelog[1], changelog[2], changelog[4])
266 fd, headerfile = tempfile.mkstemp(prefix='hg-transplant-')
266 fd, headerfile = pycompat.mkstemp(prefix='hg-transplant-')
267 fp = os.fdopen(fd, r'wb')
267 fp = os.fdopen(fd, r'wb')
268 fp.write("# HG changeset patch\n")
268 fp.write("# HG changeset patch\n")
269 fp.write("# User %s\n" % user)
269 fp.write("# User %s\n" % user)
@@ -9,7 +9,6 b' from __future__ import absolute_import'
9
9
10 import os
10 import os
11 import struct
11 import struct
12 import tempfile
13 import weakref
12 import weakref
14
13
15 from .i18n import _
14 from .i18n import _
@@ -80,7 +79,7 b' def writechunks(ui, chunks, filename, vf'
80 # small (4k is common on Linux).
79 # small (4k is common on Linux).
81 fh = open(filename, "wb", 131072)
80 fh = open(filename, "wb", 131072)
82 else:
81 else:
83 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
82 fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
84 fh = os.fdopen(fd, r"wb")
83 fh = os.fdopen(fd, r"wb")
85 cleanup = filename
84 cleanup = filename
86 for c in chunks:
85 for c in chunks:
@@ -10,7 +10,6 b' from __future__ import absolute_import'
10 import errno
10 import errno
11 import os
11 import os
12 import re
12 import re
13 import tempfile
14
13
15 from .i18n import _
14 from .i18n import _
16 from .node import (
15 from .node import (
@@ -329,7 +328,7 b' def dorecord(ui, repo, commitfunc, cmdsu'
329 try:
328 try:
330 # backup continues
329 # backup continues
331 for f in tobackup:
330 for f in tobackup:
332 fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
331 fd, tmpname = pycompat.mkstemp(prefix=f.replace('/', '_') + '.',
333 dir=backupdir)
332 dir=backupdir)
334 os.close(fd)
333 os.close(fd)
335 ui.debug('backup %r as %r\n' % (f, tmpname))
334 ui.debug('backup %r as %r\n' % (f, tmpname))
@@ -1142,7 +1142,7 b' def debuginstall(ui, **opts):'
1142 opts = pycompat.byteskwargs(opts)
1142 opts = pycompat.byteskwargs(opts)
1143
1143
1144 def writetemp(contents):
1144 def writetemp(contents):
1145 (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
1145 (fd, name) = pycompat.mkstemp(prefix="hg-debuginstall-")
1146 f = os.fdopen(fd, r"wb")
1146 f = os.fdopen(fd, r"wb")
1147 f.write(contents)
1147 f.write(contents)
1148 f.close()
1148 f.close()
@@ -724,7 +724,7 b' def _maketempfiles(repo, fco, fca, local'
724 name += ext
724 name += ext
725 f = open(name, r"wb")
725 f = open(name, r"wb")
726 else:
726 else:
727 fd, name = tempfile.mkstemp(prefix=pre + '.', suffix=ext)
727 fd, name = pycompat.mkstemp(prefix=pre + '.', suffix=ext)
728 f = os.fdopen(fd, r"wb")
728 f = os.fdopen(fd, r"wb")
729 return f, name
729 return f, name
730
730
@@ -13,7 +13,6 b' import io'
13 import os
13 import os
14 import socket
14 import socket
15 import struct
15 import struct
16 import tempfile
17 import weakref
16 import weakref
18
17
19 from .i18n import _
18 from .i18n import _
@@ -519,7 +518,7 b' class httppeer(wireprotov1peer.wirepeer)'
519 filename = None
518 filename = None
520 try:
519 try:
521 # dump bundle to disk
520 # dump bundle to disk
522 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
521 fd, filename = pycompat.mkstemp(prefix="hg-bundle-", suffix=".hg")
523 fh = os.fdopen(fd, r"wb")
522 fh = os.fdopen(fd, r"wb")
524 d = fp.read(4096)
523 d = fp.read(4096)
525 while d:
524 while d:
@@ -211,7 +211,7 b' def extract(ui, fileobj):'
211 Any item can be missing from the dictionary. If filename is missing,
211 Any item can be missing from the dictionary. If filename is missing,
212 fileobj did not contain a patch. Caller must unlink filename when done.'''
212 fileobj did not contain a patch. Caller must unlink filename when done.'''
213
213
214 fd, tmpname = tempfile.mkstemp(prefix='hg-patch-')
214 fd, tmpname = pycompat.mkstemp(prefix='hg-patch-')
215 tmpfp = os.fdopen(fd, r'wb')
215 tmpfp = os.fdopen(fd, r'wb')
216 try:
216 try:
217 yield _extract(ui, fileobj, tmpname, tmpfp)
217 yield _extract(ui, fileobj, tmpname, tmpfp)
@@ -1109,7 +1109,7 b' file will be generated: you can use that'
1109 all lines of the hunk are removed, then the edit is aborted and
1109 all lines of the hunk are removed, then the edit is aborted and
1110 the hunk is left unchanged.
1110 the hunk is left unchanged.
1111 """)
1111 """)
1112 (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-",
1112 (patchfd, patchfn) = pycompat.mkstemp(prefix="hg-editor-",
1113 suffix=".diff")
1113 suffix=".diff")
1114 ncpatchfp = None
1114 ncpatchfp = None
1115 try:
1115 try:
@@ -216,7 +216,7 b' def checkexec(path):'
216 # check directly in path and don't leave checkisexec behind
216 # check directly in path and don't leave checkisexec behind
217 checkdir = path
217 checkdir = path
218 checkisexec = None
218 checkisexec = None
219 fh, fn = tempfile.mkstemp(dir=checkdir, prefix='hg-checkexec-')
219 fh, fn = pycompat.mkstemp(dir=checkdir, prefix='hg-checkexec-')
220 try:
220 try:
221 os.close(fh)
221 os.close(fh)
222 m = os.stat(fn).st_mode
222 m = os.stat(fn).st_mode
@@ -15,6 +15,7 b' import inspect'
15 import os
15 import os
16 import shlex
16 import shlex
17 import sys
17 import sys
18 import tempfile
18
19
19 ispy3 = (sys.version_info[0] >= 3)
20 ispy3 = (sys.version_info[0] >= 3)
20 ispypy = (r'__pypy__' in sys.builtin_module_names)
21 ispypy = (r'__pypy__' in sys.builtin_module_names)
@@ -384,3 +385,7 b' def getoptb(args, shortlist, namelist):'
384
385
385 def gnugetoptb(args, shortlist, namelist):
386 def gnugetoptb(args, shortlist, namelist):
386 return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
387 return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)
388
389 # text=True is not supported; use util.from/tonativeeol() instead
390 def mkstemp(suffix=b'', prefix=b'tmp', dir=None):
391 return tempfile.mkstemp(suffix, prefix, dir)
@@ -8,7 +8,6 b''
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import os
10 import os
11 import tempfile
12
11
13 from .i18n import _
12 from .i18n import _
14
13
@@ -72,7 +71,7 b' def runservice(opts, parentfn=None, init'
72
71
73 if opts['daemon'] and not opts['daemon_postexec']:
72 if opts['daemon'] and not opts['daemon_postexec']:
74 # Signal child process startup with file removal
73 # Signal child process startup with file removal
75 lockfd, lockpath = tempfile.mkstemp(prefix='hg-service-')
74 lockfd, lockpath = pycompat.mkstemp(prefix='hg-service-')
76 os.close(lockfd)
75 os.close(lockfd)
77 try:
76 try:
78 if not runargs:
77 if not runargs:
@@ -112,7 +112,6 b' import json'
112 import os
112 import os
113 import signal
113 import signal
114 import sys
114 import sys
115 import tempfile
116 import threading
115 import threading
117 import time
116 import time
118
117
@@ -691,7 +690,7 b' def write_to_flame(data, fp, scriptpath='
691 file=fp)
690 file=fp)
692 return
691 return
693
692
694 fd, path = tempfile.mkstemp()
693 fd, path = pycompat.mkstemp()
695
694
696 file = open(path, "w+")
695 file = open(path, "w+")
697
696
@@ -10,7 +10,6 b' from __future__ import absolute_import'
10 import contextlib
10 import contextlib
11 import os
11 import os
12 import struct
12 import struct
13 import tempfile
14 import warnings
13 import warnings
15
14
16 from .i18n import _
15 from .i18n import _
@@ -19,6 +18,7 b' from . import ('
19 cacheutil,
18 cacheutil,
20 error,
19 error,
21 phases,
20 phases,
21 pycompat,
22 store,
22 store,
23 util,
23 util,
24 )
24 )
@@ -469,7 +469,7 b' def maketempcopies():'
469 files = []
469 files = []
470 try:
470 try:
471 def copy(src):
471 def copy(src):
472 fd, dst = tempfile.mkstemp()
472 fd, dst = pycompat.mkstemp()
473 os.close(fd)
473 os.close(fd)
474 files.append(dst)
474 files.append(dst)
475 util.copyfiles(src, dst, hardlink=True)
475 util.copyfiles(src, dst, hardlink=True)
@@ -18,7 +18,6 b' import signal'
18 import socket
18 import socket
19 import subprocess
19 import subprocess
20 import sys
20 import sys
21 import tempfile
22 import traceback
21 import traceback
23
22
24 from .i18n import _
23 from .i18n import _
@@ -1446,7 +1445,7 b' class ui(object):'
1446 rdir = None
1445 rdir = None
1447 if self.configbool('experimental', 'editortmpinhg'):
1446 if self.configbool('experimental', 'editortmpinhg'):
1448 rdir = repopath
1447 rdir = repopath
1449 (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
1448 (fd, name) = pycompat.mkstemp(prefix='hg-' + extra['prefix'] + '-',
1450 suffix=suffix,
1449 suffix=suffix,
1451 dir=rdir)
1450 dir=rdir)
1452 try:
1451 try:
@@ -31,7 +31,6 b' import shutil'
31 import socket
31 import socket
32 import stat
32 import stat
33 import sys
33 import sys
34 import tempfile
35 import time
34 import time
36 import traceback
35 import traceback
37 import warnings
36 import warnings
@@ -1893,7 +1892,7 b' def checknlink(testfile):'
1893 # work around issue2543 (or testfile may get lost on Samba shares)
1892 # work around issue2543 (or testfile may get lost on Samba shares)
1894 f1, f2, fp = None, None, None
1893 f1, f2, fp = None, None, None
1895 try:
1894 try:
1896 fd, f1 = tempfile.mkstemp(prefix='.%s-' % os.path.basename(testfile),
1895 fd, f1 = pycompat.mkstemp(prefix='.%s-' % os.path.basename(testfile),
1897 suffix='1~', dir=os.path.dirname(testfile))
1896 suffix='1~', dir=os.path.dirname(testfile))
1898 os.close(fd)
1897 os.close(fd)
1899 f2 = '%s2~' % f1[:-2]
1898 f2 = '%s2~' % f1[:-2]
@@ -1939,7 +1938,7 b' def mktempcopy(name, emptyok=False, crea'
1939 Returns the name of the temporary file.
1938 Returns the name of the temporary file.
1940 """
1939 """
1941 d, fn = os.path.split(name)
1940 d, fn = os.path.split(name)
1942 fd, temp = tempfile.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
1941 fd, temp = pycompat.mkstemp(prefix='.%s-' % fn, suffix='~', dir=d)
1943 os.close(fd)
1942 os.close(fd)
1944 # Temporary files are created with mode 0600, which is usually not
1943 # Temporary files are created with mode 0600, which is usually not
1945 # what we want. If the original file already exists, just copy
1944 # what we want. If the original file already exists, just copy
@@ -16,7 +16,6 b' import os'
16 import signal
16 import signal
17 import subprocess
17 import subprocess
18 import sys
18 import sys
19 import tempfile
20 import time
19 import time
21
20
22 from ..i18n import _
21 from ..i18n import _
@@ -164,11 +163,11 b' def tempfilter(s, cmd):'
164 the temporary files generated.'''
163 the temporary files generated.'''
165 inname, outname = None, None
164 inname, outname = None, None
166 try:
165 try:
167 infd, inname = tempfile.mkstemp(prefix='hg-filter-in-')
166 infd, inname = pycompat.mkstemp(prefix='hg-filter-in-')
168 fp = os.fdopen(infd, r'wb')
167 fp = os.fdopen(infd, r'wb')
169 fp.write(s)
168 fp.write(s)
170 fp.close()
169 fp.close()
171 outfd, outname = tempfile.mkstemp(prefix='hg-filter-out-')
170 outfd, outname = pycompat.mkstemp(prefix='hg-filter-out-')
172 os.close(outfd)
171 os.close(outfd)
173 cmd = cmd.replace('INFILE', inname)
172 cmd = cmd.replace('INFILE', inname)
174 cmd = cmd.replace('OUTFILE', outname)
173 cmd = cmd.replace('OUTFILE', outname)
@@ -11,7 +11,6 b' import errno'
11 import os
11 import os
12 import shutil
12 import shutil
13 import stat
13 import stat
14 import tempfile
15 import threading
14 import threading
16
15
17 from .i18n import _
16 from .i18n import _
@@ -171,7 +170,7 b' class abstractvfs(object):'
171 return os.mkdir(self.join(path))
170 return os.mkdir(self.join(path))
172
171
173 def mkstemp(self, suffix='', prefix='tmp', dir=None):
172 def mkstemp(self, suffix='', prefix='tmp', dir=None):
174 fd, name = tempfile.mkstemp(suffix=suffix, prefix=prefix,
173 fd, name = pycompat.mkstemp(suffix=suffix, prefix=prefix,
175 dir=self.join(dir))
174 dir=self.join(dir))
176 dname, fname = util.split(name)
175 dname, fname = util.split(name)
177 if dir:
176 if dir:
@@ -8,7 +8,6 b''
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import os
10 import os
11 import tempfile
12
11
13 from .i18n import _
12 from .i18n import _
14 from .node import (
13 from .node import (
@@ -568,7 +567,7 b' def unbundle(repo, proto, heads):'
568 fp.close()
567 fp.close()
569 if tempname:
568 if tempname:
570 os.unlink(tempname)
569 os.unlink(tempname)
571 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-')
570 fd, tempname = pycompat.mkstemp(prefix='hg-unbundle-')
572 repo.ui.debug('redirecting incoming bundle to %s\n' %
571 repo.ui.debug('redirecting incoming bundle to %s\n' %
573 tempname)
572 tempname)
574 fp = os.fdopen(fd, pycompat.sysstr('wb+'))
573 fp = os.fdopen(fd, pycompat.sysstr('wb+'))
General Comments 0
You need to be logged in to leave comments. Login now