本文整理匯總了Python中tempfile._mkstemp_inner方法的典型用法代碼示例。如果您正苦於以下問題:Python tempfile._mkstemp_inner方法的具體用法?Python tempfile._mkstemp_inner怎麽用?Python tempfile._mkstemp_inner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tempfile
的用法示例。
在下文中一共展示了tempfile._mkstemp_inner方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_basic_with_bytes_names
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_basic_with_bytes_names(self):
# _mkstemp_inner can create files when given name parts all
# specified as bytes.
dir_b = tempfile.gettempdirb()
self.do_create(dir=dir_b, suf=b"").write(b"blat")
self.do_create(dir=dir_b, pre=b"a").write(b"blat")
self.do_create(dir=dir_b, suf=b"b").write(b"blat")
self.do_create(dir=dir_b, pre=b"a", suf=b"b").write(b"blat")
self.do_create(dir=dir_b, pre=b"aa", suf=b".txt").write(b"blat")
# Can't mix str & binary types in the args.
with self.assertRaises(TypeError):
self.do_create(dir="", suf=b"").write(b"blat")
with self.assertRaises(TypeError):
self.do_create(dir=dir_b, pre="").write(b"blat")
with self.assertRaises(TypeError):
self.do_create(dir=dir_b, pre=b"", suf="").write(b"blat")
示例2: __init__
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def __init__(self, dir, pre, suf, bin):
if bin: flags = self._bflags
else: flags = self._tflags
(self.fd, self.name) = tempfile._mkstemp_inner(dir, pre, suf, flags)
示例3: do_create
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def do_create(self, dir=None, pre="", suf="", bin=1):
if dir is None:
dir = tempfile.gettempdir()
try:
file = self.mkstemped(dir, pre, suf, bin)
except:
self.failOnException("_mkstemp_inner")
self.nameCheck(file.name, dir, pre, suf)
return file
示例4: test_basic
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_basic(self):
# _mkstemp_inner can create files
self.do_create().write("blat")
self.do_create(pre="a").write("blat")
self.do_create(suf="b").write("blat")
self.do_create(pre="a", suf="b").write("blat")
self.do_create(pre="aa", suf=".txt").write("blat")
示例5: test_basic_many
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_basic_many(self):
# _mkstemp_inner can create many files (stochastic)
extant = range(TEST_FILES)
for i in extant:
extant[i] = self.do_create(pre="aa")
示例6: test_choose_directory
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_choose_directory(self):
# _mkstemp_inner can create files in a user-selected directory
dir = tempfile.mkdtemp()
try:
self.do_create(dir=dir).write("blat")
finally:
os.rmdir(dir)
示例7: test_noinherit
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_noinherit(self):
# _mkstemp_inner file handles are not inherited by child processes
if support.verbose:
v="v"
else:
v="q"
file = self.do_create()
fd = "%d" % file.fd
try:
me = __file__
except NameError:
me = sys.argv[0]
# We have to exec something, so that FD_CLOEXEC will take
# effect. The core of this test is therefore in
# tf_inherit_check.py, which see.
tester = os.path.join(os.path.dirname(os.path.abspath(me)),
"tf_inherit_check.py")
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
# but an arg with embedded spaces should be decorated with double
# quotes on each end
if sys.platform in ('win32',):
decorated = '"%s"' % sys.executable
tester = '"%s"' % tester
else:
decorated = sys.executable
retval = os.spawnl(os.P_WAIT, sys.executable, decorated, tester, v, fd)
self.assertFalse(retval < 0,
"child process caught fatal signal %d" % -retval)
self.assertFalse(retval > 0, "child process reports failure %d"%retval)
示例8: test_textmode
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_textmode(self):
# _mkstemp_inner can create files in text mode
self.do_create(bin=0).write("blat\n")
# XXX should test that the file really is a text file
示例9: make_temp
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def make_temp(self):
return tempfile._mkstemp_inner(tempfile.gettempdir(),
tempfile.template,
'',
tempfile._bin_openflags)
示例10: test_collision_with_existing_file
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_collision_with_existing_file(self):
# _mkstemp_inner tries another name when a file with
# the chosen name already exists
with _inside_empty_temp_dir(), \
_mock_candidate_names('aaa', 'aaa', 'bbb'):
(fd1, name1) = self.make_temp()
os.close(fd1)
self.assertTrue(name1.endswith('aaa'))
(fd2, name2) = self.make_temp()
os.close(fd2)
self.assertTrue(name2.endswith('bbb'))
示例11: test_collision_with_existing_directory
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_collision_with_existing_directory(self):
# _mkstemp_inner tries another name when a directory with
# the chosen name already exists
with _inside_empty_temp_dir(), \
_mock_candidate_names('aaa', 'aaa', 'bbb'):
dir = tempfile.mkdtemp()
self.assertTrue(dir.endswith('aaa'))
(fd, name) = self.make_temp()
os.close(fd)
self.assertTrue(name.endswith('bbb'))
示例12: test_noinherit
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_noinherit(self):
# _mkstemp_inner file handles are not inherited by child processes
if not has_spawnl:
return # ugh, can't use SkipTest.
if support.verbose:
v="v"
else:
v="q"
file = self.do_create()
fd = "%d" % file.fd
try:
me = __file__
except NameError:
me = sys.argv[0]
# We have to exec something, so that FD_CLOEXEC will take
# effect. The core of this test is therefore in
# tf_inherit_check.py, which see.
tester = os.path.join(os.path.dirname(os.path.abspath(me)),
"tf_inherit_check.py")
# On Windows a spawn* /path/ with embedded spaces shouldn't be quoted,
# but an arg with embedded spaces should be decorated with double
# quotes on each end
if sys.platform in ('win32',):
decorated = '"%s"' % sys.executable
tester = '"%s"' % tester
else:
decorated = sys.executable
retval = os.spawnl(os.P_WAIT, sys.executable, decorated, tester, v, fd)
self.assertFalse(retval < 0,
"child process caught fatal signal %d" % -retval)
self.assertFalse(retval > 0, "child process reports failure %d"%retval)
示例13: test_textmode
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_textmode(self):
# _mkstemp_inner can create files in text mode
if not has_textmode:
return # ugh, can't use SkipTest.
self.do_create(bin=0).write("blat\n")
# XXX should test that the file really is a text file
示例14: default_mkstemp_inner
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def default_mkstemp_inner(self):
return tempfile._mkstemp_inner(tempfile.gettempdir(),
tempfile.template,
'',
tempfile._bin_openflags)
示例15: test_collision_with_existing_file
# 需要導入模塊: import tempfile [as 別名]
# 或者: from tempfile import _mkstemp_inner [as 別名]
def test_collision_with_existing_file(self):
# _mkstemp_inner tries another name when a file with
# the chosen name already exists
with _inside_empty_temp_dir(), \
_mock_candidate_names('aaa', 'aaa', 'bbb'):
(fd1, name1) = self.default_mkstemp_inner()
os.close(fd1)
self.assertTrue(name1.endswith('aaa'))
(fd2, name2) = self.default_mkstemp_inner()
os.close(fd2)
self.assertTrue(name2.endswith('bbb'))