Hi,
As Wrote in
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306

http://pypi.python.org/pypi/MultipartPostHandler/0.1.0 is not updated ,
the author email doesn't not exist ,
how I send a comment update MultipartPostHandler
anyway patch attach
Only in MultipartPostHandler-0.1.0: build
Only in MultipartPostHandler-0.1.0: dist
Common subdirectories: MultipartPostHandler-0.1.0.orig/doc and MultipartPostHandler-0.1.0/doc
Common subdirectories: MultipartPostHandler-0.1.0.orig/MultipartPostHandler.egg-info and MultipartPostHandler-0.1.0/MultipartPostHandler.egg-info
diff -u MultipartPostHandler-0.1.0.orig/MultipartPostHandler.py MultipartPostHandler-0.1.0/MultipartPostHandler.py
--- MultipartPostHandler-0.1.0.orig/MultipartPostHandler.py	2010-06-05 20:35:37.000000000 +0100
+++ MultipartPostHandler-0.1.0/MultipartPostHandler.py	2011-06-04 12:54:31.958597227 +0100
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# From http://peerit.blogspot.com/2007/07/multipartposthandler-doesnt-work-for.html
 
 ####
 # 02/2006 Will Holcomb <wholc...@gmail.com>
@@ -13,6 +14,8 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Lesser General Public License for more details.
 #
+# 7/26/07 Slightly modified by Brian Schneider  
+# in order to support unicode files ( multipart_encode function )
 """
 Usage:
   Enables the use of multipart/form-data for posting forms
@@ -42,6 +45,7 @@
 import urllib2
 import mimetools, mimetypes
 import os, stat
+from cStringIO import StringIO
 
 class Callable:
     def __init__(self, anycallable):
@@ -86,22 +90,23 @@
         if boundary is None:
             boundary = mimetools.choose_boundary()
         if buffer is None:
-            buffer = ''
+            buffer = StringIO()
         for(key, value) in vars:
-            buffer += '--%s\r\n' % boundary
-            buffer += 'Content-Disposition: form-data; name="%s"' % key
-            buffer += '\r\n\r\n' + value + '\r\n'
+            buffer.write('--%s\r\n' % boundary)
+            buffer.write('Content-Disposition: form-data; name="%s"' % key)
+            buffer.write('\r\n\r\n' + value + '\r\n')
         for(key, fd) in files:
             file_size = os.fstat(fd.fileno())[stat.ST_SIZE]
             filename = fd.name.split('/')[-1]
             contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
-            buffer += '--%s\r\n' % boundary
-            buffer += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
-            buffer += 'Content-Type: %s\r\n' % contenttype
+            buffer.write('--%s\r\n' % boundary)
+            buffer.write('Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename))
+            buffer.write('Content-Type: %s\r\n' % contenttype)
             # buffer += 'Content-Length: %s\r\n' % file_size
             fd.seek(0)
-            buffer += '\r\n' + fd.read() + '\r\n'
-        buffer += '--%s--\r\n\r\n' % boundary
+            buffer.write('\r\n' + fd.read() + '\r\n')
+        buffer.write('--' + boundary + '--\r\n\r\n')
+        buffer = buffer.getvalue()
         return boundary, buffer
     multipart_encode = Callable(multipart_encode)
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to