Beispiel #1
0
    def build_filedata(self, content_str, suffix='.txt'):
        tmpfile = NamedTemporaryFile(suffix=suffix)
        tmpfile.write(content_str.encode())
        tmpfile.flush()

        filedata = tmpfile.file
        filedata.seek(0)

        tmpfile.base_name = basename(tmpfile.name)

        return tmpfile
Beispiel #2
0
    def _build_filedata(self, content_str, suffix='.txt'):
        # tmpfile = NamedTemporaryFile(suffix=suffix, delete=False)
        # tmpfile.write(content_str)
        # tmpfile.flush()
        #
        # # We close and reopen in order to have a file with the right name (so we must specify delete=False)
        # tmpfile.close()
        #
        # name = tmpfile.name
        #
        # return open(name, 'rb'), basename(name)
        tmpfile = NamedTemporaryFile(suffix=suffix)
        tmpfile.write(content_str.encode())
        tmpfile.flush()

        filedata = tmpfile.file
        filedata.seek(0)

        tmpfile.base_name = basename(tmpfile.name)

        return tmpfile