[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests -
Request.py:1.7.2.3.2.2 interfaces.py:1.3.2.1.2.4
Karl Anderson
cvs-admin at zope.org
Fri Nov 14 20:03:10 EST 2003
Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv29797/FunctionalTests
Modified Files:
Tag: kra-intersest-branch
Request.py interfaces.py
Log Message:
merged changes from kra-misc-branch
=== Packages/FunctionalTests/FunctionalTests/Request.py 1.7.2.3.2.1 => 1.7.2.3.2.2 ===
--- Packages/FunctionalTests/FunctionalTests/Request.py:1.7.2.3.2.1 Thu Nov 13 16:16:57 2003
+++ Packages/FunctionalTests/FunctionalTests/Request.py Fri Nov 14 20:02:39 2003
@@ -1,13 +1,16 @@
""" Classes: RequestError, HTTPRequest, ZEORequest
Functions: buildRequest
-$Id
+$Id $
"""
import re
import httplib
import urllib
import urlparse
import base64
+import MimeWriter
+import StringIO
+import rfc822
from interfaces import IPluginFunction
from interfaces import IRequest
@@ -184,6 +187,8 @@
self._expected_cookies = ()
self._payload_checker = None
self._hook = None
+ self._contentTypeCache = None
+ self._dataCache = None
def _initURLParts( self, URL ):
@@ -317,12 +322,23 @@
""" See IHTTPRequest.
"""
return self._expected_cookies is not None
+
+ def setMultipart( self ):
+
+ """ See IHTTPRequest.
+ """
+ self._has_file_field = 1
def getContentType( self ):
""" See IHTTPRequest.
"""
- return self._has_file_field and _MULTIPART or _URLENCODED
+ if self._has_file_field:
+ self._setMultipartDataAndType()
+ return self._contentTypeCache
+
+ return _URLENCODED
+
def getData( self ):
@@ -330,7 +346,8 @@
"""
if self._has_file_field:
- return _mime_encode( self._fields )
+ self._setMultipartDataAndType()
+ return self._dataCache
else:
@@ -376,6 +393,9 @@
""" See IHTTPRequest.
"""
+ if self._dataCache:
+ # adding could change boundary which may have been gotten
+ raise RequestError, "cannot add field after getting data or type"
field = _buildField( field_desc )
if field[1] == 'file':
self._has_file_field = 1
@@ -428,6 +448,21 @@
"""
self._hook = PluginFunction( filename, function )
+ # we need to cache because content-type and data must both state
+ # the same boundary
+ def _setMultipartDataAndType( self ):
+ """ See IHTTPRequest.
+ """
+ if not self._has_file_field:
+ raise RuntimeError, \
+ "attempt to cache data and type of non-multipart type request"
+ if not self._contentTypeCache:
+ mess = _mime_encode( self._fields )
+ type = mess['content-type']
+ type = type.replace('\n ', ' ')
+ self._dataCache = mess.fp.read()[1:]
+ self._contentTypeCache = type
+
#
# Request invocation
#
@@ -596,16 +631,13 @@
raise RequestError, 'Invalid field_desc: %s' % field_desc
_URLENCODED = 'application/x-www-form-urlencoded'
-_MULTIPART = 'multipart/form-data'
+#_MULTIPART = 'multipart/form-data'
def _mime_encode( fields ):
""" Build a 'multipart/form-data' representation of the
(name,type,value) items in fields.
"""
- 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()
@@ -621,8 +653,7 @@
f.write( field[2] )
writer.lastpart()
fp.seek(0)
- mess = rfc822.Message( fp )
- return mess['content-type'] + mess.fp.read()
+ return rfc822.Message( fp )
def _buildSleepRequest( cp, section ):
=== Packages/FunctionalTests/FunctionalTests/interfaces.py 1.3.2.1.2.3 => 1.3.2.1.2.4 ===
--- Packages/FunctionalTests/FunctionalTests/interfaces.py:1.3.2.1.2.3 Thu Nov 13 16:18:17 2003
+++ Packages/FunctionalTests/FunctionalTests/interfaces.py Fri Nov 14 20:02:39 2003
@@ -204,6 +204,10 @@
""" Should invocations of this request retain cookies?
"""
+ def setMultipart():
+ """ Set content-type to multipart/form-data.
+ """
+
def getContentType():
""" Return the HTTP 'Content-type' to use for this request.
@@ -274,11 +278,14 @@
""" Create a checker function as a plugin function.
"""
+ def _setMultipartDataAndType():
+ """ Encode and cache the data and content-type.
+ """
+
def setHook( filename, function ):
""" Create a hook function as a plugin function.
"""
-
class IResult( Interface ):
More information about the Zope-CVS
mailing list