Commit 71d3b857 by rfkelly0

Provide working alternative if SpooledTemporaryFile is not available.

parent 4e173179
...@@ -36,11 +36,15 @@ from fs import SEEK_SET, SEEK_CUR, SEEK_END ...@@ -36,11 +36,15 @@ from fs import SEEK_SET, SEEK_CUR, SEEK_END
try: try:
from tempfile import SpooledTemporaryFile from tempfile import SpooledTemporaryFile
def _MakeSpooledTempFile(*args, **kwds):
return SpooledTemporaryFile(*args, **kwds)
except ImportError: except ImportError:
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
class SpooledTemporaryFile(NamedTemporaryFile): class SpooledTemporaryFile(object):
def __init__(self,max_size=0,*args,**kwds): """Fake SpooledTemporaryFile, for faking out isinstance() checks."""
NamedTemporaryFile.__init__(self,*args,**kwds) pass
def _MakeSpooledTempFile(max_size=0, *args, **kwds):
return NamedTemporaryFile(*args,**kwds)
class RemoteFileBuffer(object): class RemoteFileBuffer(object):
...@@ -77,7 +81,7 @@ class RemoteFileBuffer(object): ...@@ -77,7 +81,7 @@ class RemoteFileBuffer(object):
optional argument 'rfile' is provided, it must be a read()-able optional argument 'rfile' is provided, it must be a read()-able
object or a string containing the initial file contents. object or a string containing the initial file contents.
""" """
self.file = SpooledTemporaryFile(max_size=self.max_size_in_memory) self.file = _MakeSpooledTempFile(max_size=self.max_size_in_memory)
self.fs = fs self.fs = fs
self.path = path self.path = path
self.mode = mode self.mode = mode
...@@ -273,7 +277,10 @@ class RemoteFileBuffer(object): ...@@ -273,7 +277,10 @@ class RemoteFileBuffer(object):
else: else:
self.file._file.truncate(size) self.file._file.truncate(size)
else: else:
self.file.truncate(size) if size is None:
self.file.truncate()
else:
self.file.truncate(size)
self._changed = True self._changed = True
if not self._eof and self._readlen < size: if not self._eof and self._readlen < size:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment