本文整理汇总了Python中tempfile._TemporaryFileWrapper方法的典型用法代码示例。如果您正苦于以下问题:Python tempfile._TemporaryFileWrapper方法的具体用法?Python tempfile._TemporaryFileWrapper怎么用?Python tempfile._TemporaryFileWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tempfile
的用法示例。
在下文中一共展示了tempfile._TemporaryFileWrapper方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_cert
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _TemporaryFileWrapper [as 别名]
def generate_cert(self, code=None):
"""
Will generate a certificate and key. If code is used the same certificate and key will
always be returned for the same code.
:type code: str
:rtype: (tempfile._TemporaryFileWrapper, tempfile._TemporaryFileWrapper)
:param: code: A unique code to represent a certificate and key.
:return: A certificate and key temporary file.
"""
if code in self.generate_certs:
return self.generate_certs[code]
cert_str, key_str = generate_cert()
cert_file = tempfile.NamedTemporaryFile()
cert_file.write(cert_str)
cert_file.flush()
key_file = tempfile.NamedTemporaryFile()
key_file.write(key_str)
key_file.flush()
if code is not None:
self.generate_certs[code] = cert_file, key_file
return cert_file, key_file
示例2: test_jekyll_site_export
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _TemporaryFileWrapper [as 别名]
def test_jekyll_site_export(self):
j = JekyllSiteExport(self.volume, 'v2', owners=[self.user.id])
zip = j.get_zip()
tempdir = j.generate_website()
web_zip = j.website_zip()
# j.import_iiif_jekyll(j.manifest, j.jekyll_site_dir)
assert isinstance(zip, tempfile._TemporaryFileWrapper)
assert "%s_annotated_site_" % (str(self.volume.pk)) in zip.name
assert zip.name.endswith('.zip')
assert isinstance(web_zip, tempfile._TemporaryFileWrapper)
assert "%s_annotated_site_" % (str(self.volume.pk)) in web_zip.name
assert web_zip.name.endswith('.zip')
assert 'tmp-rdx-export' in tempdir
assert tempdir.endswith('/export')
tmpdir = tempfile.mkdtemp(prefix='tmp-rdx-export-')
jekyll_zip = zipfile.ZipFile(zip, "r")
jekyll_zip.extractall(tmpdir)
jekyll_dir = os.listdir(tmpdir)[0]
jekyll_path = os.path.join(tmpdir, jekyll_dir)
# verify the iiif export is embedded
iiif_path = os.path.join(jekyll_path, 'iiif_export')
manifest_path = os.path.join(iiif_path, 'manifest.json')
assert os.path.exists(manifest_path)
# verify page count is correct
assert len(os.listdir(os.path.join(jekyll_path, '_volume_pages'))) == 2
# verify ocr annotation count is correct
with open(os.path.join(jekyll_path, '_volume_pages', '0000.html')) as page_file:
contents = page_file.read()
assert contents.count('ocr-line') == 6
# verify user annotation count is correct
assert len(os.listdir(os.path.join(jekyll_path, '_annotations'))) == 1
示例3: test_with
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _TemporaryFileWrapper [as 别名]
def test_with(self):
addbase = urllib.response.addbase(self.fp)
self.assertIsInstance(addbase, tempfile._TemporaryFileWrapper)
def f():
with addbase as spam:
pass
self.assertFalse(self.fp.closed)
f()
self.assertTrue(self.fp.closed)
self.assertRaises(ValueError, f)
示例4: temp_conf
# 需要导入模块: import tempfile [as 别名]
# 或者: from tempfile import _TemporaryFileWrapper [as 别名]
def temp_conf(conf: str) -> tempfile._TemporaryFileWrapper:
with tempfile.NamedTemporaryFile(delete=False) as temp:
temp.write(bytes(conf, encoding="utf-8"))
temp.seek(0)
yield temp