updated for unicode support, handle file-like objects#71
updated for unicode support, handle file-like objects#71shaneshifflett wants to merge 5 commits into
Conversation
…stance). Upload also uses an object instead of a file path
…oking for file attributes instead of descending from File and also using StringIO as a buffer instead of plain string (no unicode ascii issues no mo)
|
Great. Giving it a look now. I might not handle it via Github's pull interface, but I'm on it. |
|
Hey looks like you pulled in several changes. I was wondering, did you On Wed, Jun 15, 2011 at 3:35 PM, palewire <
Shane Shifflett |
|
Not on the right computer to check everything again for you, but I'm pretty sure the file object and unicode fixes should be out on pip now with version 0.151. I tweaked a couple small things, but it's mostly your work. Tried to get you props in the changelog in the docs. If I screwed something up, let me know. |
|
Thanks so much I really appreciate your help! I think your changes look Still having an occasional issue with the pdf file object in the upload Required parametersOn Fri, Jun 17, 2011 at 9:21 AM, palewire <
Shane Shifflett |
|
Okay, maybe that check works better an isinstance instead of hasattr, though then we might have the subclassing problems you talked about when we get something descending from "file" or "stringio." If we figure out an example that crashes, I bet we can solve it. |
I'm working on a django app for document cloud documents and your python wrapper for the doccloud api was a great starting point. We host many of our PDF's and documents on Amazon S3 via django-storages. First thing I noticed was using file paths wouldn't work. I worked with palewire to provide the option to pass in file objects or file paths. As I kept working, MultipartPostHandler started to throw some encoding exceptions. The encode function's buffer was a plain ascii string that worked as long as the file was opened using the python's open function (default encoding=ascii). Upon retrieval, our files are stored in memory as a StringIO object (wrapped in an S3BotoStorageFile). StringIO objects are unicode and thus the the encode function blew up as it tried to append the contents of a unicode file to an ascii header. I changed the encode to method to use a StringIO object as the buffer and things worked fine. I don't think it will matter if the file-like objects use some other class to store the contents of a file because the issue had everything to do with the encoding. I also updated some other checks to look for the read attr instead of testing to see if the file object inherited from python's File class. And, I added a function to calculate the size of a file without using fstat.
Let me know if you see any issues!