[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - Request.py:1.7.2.2

Karl Anderson cvs-admin at zope.org
Fri Nov 7 14:07:08 EST 2003


Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv32762

Modified Files:
      Tag: kra-misc-branch
	Request.py 
Log Message:
HTTPRequest.addField(): fixed off-by-one error

_mime_encode(): fleshed out, still raises NotImplementedError for file type,
so it currently won't be reached


=== Packages/FunctionalTests/FunctionalTests/Request.py 1.7.2.1 => 1.7.2.2 ===
--- Packages/FunctionalTests/FunctionalTests/Request.py:1.7.2.1	Mon Nov  3 19:15:42 2003
+++ Packages/FunctionalTests/FunctionalTests/Request.py	Fri Nov  7 14:07:07 2003
@@ -369,7 +369,7 @@
         """ See IHTTPRequest.
         """
         field = _buildField( field_desc )
-        if field[2] == 'file':
+        if field[1] == 'file':
             self._has_file_field = 1
         self._fields.append( field )
 
@@ -583,7 +583,26 @@
     """ Build a 'multipart/form-data' representation of the
         (name,type,value) items in fields.
     """
-    raise NotImplementedError
+    import MimeWriter
+    import StringIO
+    import rfc822
+    # MimeWriter has subtle differences from the spec, will ususally be OK
+    # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306    
+    fp = StringIO.StringIO()
+    writer = MimeWriter.MimeWriter( fp )
+    writer.startmultipartbody( 'form-data' )
+    for field in fields:
+        if field[1] == 'file':
+            raise NotImplementedError
+        subwriter = writer.nextpart()
+        subwriter.addheader( 'content-disposition'
+                           , 'form-data; name="%s"' % field[0] )
+        f = subwriter.startbody( 'text/plain' )
+        f.write( field[2] )
+    writer.lastpart()
+    fp.seek(0)
+    mess = rfc822.Message( fp )
+    return mess['content-type'] + mess.fp.read()
 
 def _buildSleepRequest( cp, section ):
 




More information about the Zope-CVS mailing list