本文整理汇总了Python中tempfile._get_candidate_names方法的典型用法代码示例。如果您正苦于以下问题:Python tempfile._get_candidate_names方法的具体用法?Python tempfile._get_candidate_names怎么用?Python tempfile._get_candidate_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile
的用法示例。
在下文中一共展示了tempfile._get_candidate_names方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_test_cache
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def test_test_cache(mkdir_permissions):
# Test when cache dir exists already
path = mkdir_permissions(read=False, write=False)
assert (False, False) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=False, write=True)
assert (False, True) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=True, write=False)
assert (True, False) == cache.test_cache(dict(cache_line_dir=path))
path = mkdir_permissions(read=True, write=True)
assert (True, True) == cache.test_cache(dict(cache_line_dir=path))
# Test when cache dir doesn't exist
tmp = os.path.join(tempfile.tempdir,
next(tempfile._get_candidate_names()) + '_yatsm')
read_write = cache.test_cache(dict(cache_line_dir=tmp))
os.removedirs(tmp)
assert (True, True) == read_write
示例2: upx_unpack
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def upx_unpack(self, seed=None):
# dump bytez to a temporary file
tmpfilename = os.path.join(
tempfile._get_default_tempdir(), next(tempfile._get_candidate_names()))
with open(tmpfilename, 'wb') as outfile:
outfile.write(self.bytez)
with open(os.devnull, 'w') as DEVNULL:
retcode = subprocess.call(
['upx', tmpfilename, '-d', '-o', tmpfilename + '_unpacked'], stdout=DEVNULL, stderr=DEVNULL)
os.unlink(tmpfilename)
if retcode == 0: # sucessfully unpacked
with open(tmpfilename + '_unpacked', 'rb') as result:
self.bytez = result.read()
os.unlink(tmpfilename + '_unpacked')
return self.bytez
示例3: get_tmpdir
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def get_tmpdir(requested_tmpdir=None, prefix="", create=True):
"""get a temporary directory for an operation. If SREGISTRY_TMPDIR
is set, return that. Otherwise, return the output of tempfile.mkdtemp
Parameters
==========
requested_tmpdir: an optional requested temporary directory, first
priority as is coming from calling function.
prefix: Given a need for a sandbox (or similar), we will need to
create a subfolder *within* the SREGISTRY_TMPDIR.
create: boolean to determine if we should create folder (True)
"""
from sregistry.defaults import SREGISTRY_TMPDIR
# First priority for the base goes to the user requested.
tmpdir = requested_tmpdir or SREGISTRY_TMPDIR
prefix = prefix or "sregistry-tmp"
prefix = "%s.%s" % (prefix, next(tempfile._get_candidate_names()))
tmpdir = os.path.join(tmpdir, prefix)
if not os.path.exists(tmpdir) and create is True:
os.mkdir(tmpdir)
return tmpdir
示例4: test_barracuda_converter
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def test_barracuda_converter():
path_prefix = os.path.dirname(os.path.abspath(__file__))
tmpfile = os.path.join(
tempfile._get_default_tempdir(), next(tempfile._get_candidate_names()) + ".nn"
)
# make sure there are no left-over files
if os.path.isfile(tmpfile):
os.remove(tmpfile)
tf2bc.convert(path_prefix + "/BasicLearning.pb", tmpfile)
# test if file exists after conversion
assert os.path.isfile(tmpfile)
# currently converter produces small output file even if input file is empty
# 100 bytes is high enough to prove that conversion was successful
assert os.path.getsize(tmpfile) > 100
# cleanup
os.remove(tmpfile)
示例5: _get_conversion_outfile
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def _get_conversion_outfile(self):
"""a helper function to return a conversion temporary output file
based on kind of conversion
Parameters
==========
convert_to: a string either docker or singularity, if a different
"""
prefix = "spythonRecipe"
if hasattr(self, "name"):
prefix = self.name
suffix = next(tempfile._get_candidate_names())
return "%s.%s" % (prefix, suffix)
# Printing
示例6: get_element_image
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def get_element_image(self,element=u'//body',filename=None):
""" Get and opencv image object of the element and save it to file
Returns a numpy array and temporarily filename
"""
result_path = Common.get_result_path()
tmp_file = '%s/screen_%s.png' % (Common.get_result_path(),next(tempfile._get_candidate_names()))
self._selenium.capture_page_screenshot(tmp_file)
_element = self._selenium.get_webelement(element)
pos = _element.location
size = _element.size
screen = cv2.imread(tmp_file)
img = screen[int(pos['y']):int(pos['y']+size['height']),int(pos['x']):int(pos['x']+size['width'])]
if filename:
cv2.imwrite('%s/%s' % (result_path,filename),img)
BuiltIn().log('Save image of element to file `%s`' % filename)
return img,tmp_file
示例7: test_rmdir
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def test_rmdir(self) -> None:
tmp_filename = next(tempfile._get_candidate_names()) # type: ignore
tmp_file = self.plugin.PATH_BACKEND(
os.path.join(self.mirror_base_path, "test_dir", tmp_filename)
)
tmp_file.write_text("")
self.assertTrue(
self.plugin.PATH_BACKEND(
os.path.join(self.mirror_base_path, "test_dir")
).exists()
)
tmp_file.unlink()
self.assertFalse(
self.plugin.PATH_BACKEND(
os.path.join(self.mirror_base_path, "test_dir")
).exists()
)
示例8: apply_modifications
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def apply_modifications(model, custom_objects=None):
"""Applies modifications to the model layers to create a new Graph. For example, simply changing
`model.layers[idx].activation = new activation` does not change the graph. The entire graph needs to be updated
with modified inbound and outbound tensors because of change in layer building function.
Args:
model: The `keras.models.Model` instance.
Returns:
The modified model with changes applied. Does not mutate the original `model`.
"""
# The strategy is to save the modified model and load it back. This is done because setting the activation
# in a Keras layer doesnt actually change the graph. We have to iterate the entire graph and change the
# layer inbound and outbound nodes with modified tensors. This is doubly complicated in Keras 2.x since
# multiple inbound and outbound nodes are allowed with the Graph API.
model_path = os.path.join(tempfile.gettempdir(), next(tempfile._get_candidate_names()) + '.h5')
try:
model.save(model_path)
return load_model(model_path, custom_objects=custom_objects)
finally:
os.remove(model_path)
示例9: wfuzz_me_test_generator_previous_session
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def wfuzz_me_test_generator_previous_session(prev_session_cli, next_session_cli, expected_list):
def test(self):
temp_name = next(tempfile._get_candidate_names())
defult_tmp_dir = tempfile._get_default_tempdir()
filename = os.path.join(defult_tmp_dir, temp_name)
# first session
with wfuzz.get_session(prev_session_cli) as s:
ret_list = [x.eval(x._description) if x._description else x.description for x in s.fuzz(save=filename)]
# second session wfuzzp as payload
with wfuzz.get_session(next_session_cli.replace("$$PREVFILE$$", filename)) as s:
ret_list = [x.eval(x._description) if x._description else x.description for x in s.fuzz()]
self.assertEqual(sorted(ret_list), sorted(expected_list))
return test
示例10: test_cycle_dge_npz
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def test_cycle_dge_npz():
import tempfile
import os
tempdir = tempfile.mkdtemp(prefix="edgePy_tmp")
file_name = tempdir + os.sep + next(tempfile._get_candidate_names())
dge_list_first = dge_list()
dge_list_first.write_npz_file(filename=file_name)
dge_list_second = DGEList(filename=file_name + ".npz")
assert np.array_equal(dge_list_first.counts, dge_list_second.counts)
assert np.array_equal(dge_list_first.genes, dge_list_second.genes)
assert np.array_equal(dge_list_first.samples, dge_list_second.samples)
assert np.array_equal(dge_list_first.norm_factors, dge_list_second.norm_factors)
assert np.array_equal(dge_list_first.groups_list, dge_list_second.groups_list)
os.remove(file_name + ".npz")
os.rmdir(tempdir)
示例11: mkdtemp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def mkdtemp(dirpath, prefix='', suffix='', mode=0700):
"""Creates a directory in directory *dir* using *prefix* and *suffix* to
name it:
(dir)/<prefix><random_string><postfix>
Returns absolute path of directory.
"""
dirpath = os.path.abspath(dirpath)
names = _get_candidate_names()
mode = int(mode)
if not fcheck.mode_check(mode):
raise ValueError("wrong mode: %r" % oct(mode))
for _ in xrange(TMP_MAX):
name = names.next()
fpath = os.path.abspath(os.path.join(dirpath, '%s%s%s'
% (prefix, name, suffix)))
try:
os.mkdir(fpath, mode)
return fpath
except OSError, ex:
if ex.errno == errno.EEXIST:
# try again
continue
raise
示例12: get_temporary_name
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def get_temporary_name(prefix=None, ext=None):
"""get a temporary name, can be used for a directory or file. This does so
without creating the file, and adds an optional prefix
Parameters
==========
prefix: if defined, add the prefix after deid
ext: if defined, return the file extension appended. Do not specify "."
"""
deid_prefix = "deid-"
if prefix:
deid_prefix = "deid-%s-" % prefix
tmpname = os.path.join(
tempfile.gettempdir(),
"%s%s" % (deid_prefix, next(tempfile._get_candidate_names())),
)
if ext:
tmpname = "%s.%s" % (tmpname, ext)
return tmpname
################################################################################
## FILE OPERATIONS #############################################################
################################################################################
示例13: plt_t0_b64
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def plt_t0_b64(plt: matplotlib.pyplot, figsize=None, dpi=None):
""" Matplotlib to base64 url """
path = Path(tempfile.mkdtemp()) / Path(
next(tempfile._get_candidate_names()) + '.png')
figsize = figsize if figsize else (1, 1)
dpi = dpi if dpi else DEFAULT_DPI
# Remove paddings
plt.tight_layout()
plt.savefig(str(path), format='png', figsize=figsize,
dpi=dpi)
with open(str(path), "rb") as f:
img_base64 = base64.b64encode(f.read()).decode("utf-8", "ignore")
b64 = f'data:image/png;base64,{img_base64}'
path.unlink()
return b64
示例14: setUp
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def setUp(self):
super().setUp()
self.recovery_path = os.path.join('/tmp', next(tempfile._get_candidate_names()))
示例15: temp_filename
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _get_candidate_names [as 别名]
def temp_filename(directory, suffix):
temp_name = next(tempfile._get_candidate_names())
filename = os.path.join(directory, temp_name + suffix)
return filename
# test for an operator exists