當前位置: 首頁>>代碼示例>>Python>>正文


Python tempfile._TemporaryFileWrapper方法代碼示例

本文整理匯總了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 
開發者ID:IdentityPython,項目名稱:SATOSA,代碼行數:26,代碼來源:util.py

示例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 
開發者ID:ecds,項目名稱:readux,代碼行數:33,代碼來源:test_export.py

示例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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:14,代碼來源:test_urllib_response.py

示例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 
開發者ID:darrenburns,項目名稱:ward,代碼行數:7,代碼來源:test_config.py


注:本文中的tempfile._TemporaryFileWrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。