[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - ScenarioGenerator.py:1.5.2.3

Karl Anderson cvs-admin at zope.org
Fri Nov 7 15:40:12 EST 2003


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

Modified Files:
      Tag: kra-misc-branch
	ScenarioGenerator.py 
Log Message:
ScenarioGenerator._handleFormData(): implemented
ScenarioGenerator._handleURLEncoded(): added dummy arg to make signature
match _handleFormData()
ScenarioGenerator.processFile(): call new handler signature


=== Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py 1.5.2.2 => 1.5.2.3 ===
--- Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py:1.5.2.2	Fri Nov  7 15:28:46 2003
+++ Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py	Fri Nov  7 15:40:12 2003
@@ -12,6 +12,8 @@
 import rfc822
 import urllib
 import urlparse
+import multifile
+import StringIO
 
 _SCENARIO_SKELETON = """\
 [Scenario]
@@ -289,7 +291,9 @@
     , 'content-type'    : _handleContentType
     }
 
-    def _handleURLEncoded( self, data ):
+    # dummy is a sloppy way to do variable argument signatures, but there
+    # are only two functions that may be called
+    def _handleURLEncoded( self, data, dummy = None ):
         """
             Emit Field_## values for data, which is encoded using
             'application/x-www-form-urlencoded'.
@@ -304,13 +308,52 @@
                        , FIELD_VALUE=v
                        )
 
-    def _handleFormdata( self, data ):
+    def _handleFormdata( self
+                       , data
+                       , boundary
+                       , FIRST = re.compile( r'^Content-Disposition:'
+                                             r'\s+([^\s]+);\s*'
+                                             r'name="([^\s]+)"\s*$' )
+                       ):
         """
             Emit Field_## values for data, which is encoded using
             'multipart/form-data'.
         """
-        raise NotImplemented    # TODO:  Implement me!
+        boundary = boundary.split( '=' )[1]
+        mf = multifile.MultiFile( StringIO.StringIO( data ) )
+        mf.push( boundary )
+        count = 0
+        while mf.next():
+            count = count + 1
+            firstline = mf.readline()
+            match = FIRST.match( firstline )
+            
+            if not match:
+                self._log( 'Invalid form line: %s' % firstline, 0 )
+                return
+            
+            content, name = match.groups()
+        
+            # XXX we may be trashing whitespace
+            # XXX we aren't mangling multiline input for ConfigFile
+            #value = mf.read().replace('\r\n', '\r\n    ' )
+            value = mf.read()
+            # strip leading, trailing \r\n
+            if value[0] == '\r':
+                value = value[1:]
+            if value[0] == '\n':
+                value = value[1:]
+            if value[-1] == '\n':
+                value = value[:-1]
+            if value[-1] == '\r':
+                value = value[:-1]
 
+            self._print( _FIELD_SKELETON
+                       , FIELD_NUM=count
+                       , FIELD_NAME=name
+                       , FIELD_VALUE=value
+                       )
+        
     CONTENT_HANDLERS =\
     { 'application/x-www-form-urlencoded'   : _handleURLEncoded
     , 'multipart/form-data'                  : _handleFormdata
@@ -442,7 +485,7 @@
                 self._log( "Can't handle content type: %s"
                             % content_type, 0 )
             else:
-                handler( self, payload )
+                handler( self, payload, content_parm)
 
         if outfilename:
             self._log( 'Scanning response file: %s' % outfilename, 1 )




More information about the Zope-CVS mailing list