本文整理匯總了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