Python tempfile._TemporaryFileWrapper() Examples

The following are 7 code examples of tempfile._TemporaryFileWrapper(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tempfile , or try the search function .
Example #1
Source File: util.py    From SATOSA with Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source File: test_export.py    From readux with MIT License 5 votes vote down vote up
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 
Example #3
Source File: test_urllib_response.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #4
Source File: test_urllib_response.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
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) 
Example #5
Source File: test_urllib_response.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #6
Source File: test_config.py    From ward with MIT License 5 votes vote down vote up
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 
Example #7
Source File: test_urllib_response.py    From android_universal with MIT License 5 votes vote down vote up
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)