Commit Graph

14 Commits

Author SHA1 Message Date
Brant Watson 8ef0ef772b Implement __nonzero__ for SpooledBytesIO, SpooledStringIO
An empty StringIO instance still has a "truthy" value. In
order to user SpooledBytesIO with the ZipFile library, the
object instance needs to be considered truthy. This patch
implements __nonzero__ so that the truthyness does not fall
back on the underlying __len__ implementation.

Added a test that verifies a SpooledBytesIO is compatible
with the ZipFile library.
2016-11-14 15:55:01 -06:00
Brant Watson dfc19867ff Add another test for good measure 2016-10-26 16:17:02 -05:00
Brant Watson 3f6a020c7f Handle odd codepoints in EncodedFile
Use the underlying StreamReader implementaiton for
retrieving data from the flo. When doing so, we pass
a value for the number of bytes to read & the number
of characters to read.
2016-10-26 16:10:44 -05:00
Brant Watson fd77cb81a7 Reduce tell complexity by tracking position
Instead of calculating the position for tell by
sequentially accessing the file, track the position
on read, write, and seek operations.
2016-10-26 14:29:10 -05:00
Brant Watson 0b37b865af Improve test coverage of seek 2016-10-25 15:27:50 -05:00
Brant Watson d724d8c374 Reduce memory usage in seek
- read in chunks to avoid seek memory
  usage spike on large files
- Add more tests
2016-10-25 15:14:53 -05:00
Brant Watson 43b058d52e Improve tell() and seek() implementation
- Improvements to tell codepoint handling for
  SpooledStringIO
- Seek now works on codepoints for SpooledStringIO
2016-10-25 12:30:33 -05:00
Brant Watson 108bcab038 SpooleStringIO tell returns codepoint position
- SpooledStringIO tell implementation gives the
  codepoint position instead of the bytes position
- Added new test for codepoint position
2016-10-24 09:36:20 -05:00
Brant Watson 1dbd615d55 Make len return number of codepoints in SpooledStringIO 2016-10-24 09:13:19 -05:00
Brant Watson 3ebb2fdc71 Don't allow comparing different instance types.
Return False on __eq__ magic method if the instances
being compared are not the same type.
2016-10-24 08:50:45 -05:00
Brant Watson 0f9581cd85 Implment __len__ magic method 2016-10-24 07:19:32 -05:00
Brant Watson 4d95ea1031 Update tests to be python2.6 compatible 2016-10-21 17:03:30 -05:00
Brant Watson 774ce34bd7 Remove six dependenct in ioutils 2016-10-21 16:35:22 -05:00
Brant Watson 580142da3b Add ioutils module
Spooled Temporary Files are file-like objects
that start out mapped to in-memory objects, but
automatically roll over to a temporary file once
they reach a certain (configurable) threshhold.
Unfortunately the built-in SpooledTemporaryFile
class in Python does not implement the exact API
that some common classes like StringIO do.
SpooledTemporaryFile also spools all of it's in-memory
files as cStringIO instances. cStringIO instances cannot
be deep-copied, and they don't work with the zip
library either. This along with the incompatible api makes
it useless for several use-cases.

To combat this but still gain the memory savings and
usefulness of a true spooled file-like-object, two custom
classes have been implemented which have a compatible API.

SpooledBytesIO is a spooled file-like-object that only
accepts bytes. On Python 2.x this means the 'str' type; on
Python 3.x this means the 'bytes' type. Bytes are written
in and retrieved exactly as given, but it will raise TypeErrors
if something other than bytes are written.

SpooledStringIO is a spooled file-like-object that only accepts
unicode values. On Python 2.x this means the 'unicode' type and
on Python 3.x this means the 'str' type. Values are accepted as
unicode and then coerced into utf-8 encoded bytes for storage. On
retrieval, the values are returned as unicode.
2016-10-21 16:13:44 -05:00