当前位置: 首页>>代码示例>>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;未经允许,请勿转载。