Commits

Nicolas Grilly committed 6a3c394

Class Request is now responsible for copying request.body.params into request.params

Comments (0)

Files changed (2)

cherrypy/_cpreqbody.py

     maxbytes = None
     """Raise ``MaxSizeExceeded`` if more bytes than this are read from the socket."""
     
-    def __init__(self, fp, headers, params=None, request_params=None):
+    def __init__(self, fp, headers, params=None):
         Entity.__init__(self, fp, headers, params)
         
         # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1
         
         # Temporary fix while deprecating passing .parts as .params.
         self.processors['multipart'] = _old_process_multipart
-        
-        if request_params is None:
-            request_params = {}
-        self.request_params = request_params
     
     def process(self):
         """Process the request entity based on its Content-Type."""
                               self.maxbytes, bufsize=self.bufsize,
                               has_trailers='Trailer' in h)
         super(RequestBody, self).process()
-        
-        # Body params should also be a part of the request_params
-        # add them in here.
-        request_params = self.request_params
-        for key, value in self.params.items():
-            # Python 2 only: keyword arguments must be byte strings (type 'str').
-            if sys.version_info < (3, 0):
-                if isinstance(key, unicode):
-                    key = key.encode('ISO-8859-1')
-            
-            if key in request_params:
-                if not isinstance(request_params[key], list):
-                    request_params[key] = [request_params[key]]
-                request_params[key].append(value)
-            else:
-                request_params[key] = value

cherrypy/_cprequest.py

                     self.stage = 'get_resource'
                     self.get_resource(path_info)
                     
-                    self.body = _cpreqbody.RequestBody(
-                        self.rfile, self.headers, request_params=self.params)
+                    self.body = _cpreqbody.RequestBody(self.rfile, self.headers)
                     
                     self.namespaces(self.config)
                     
                     self.stage = 'before_request_body'
                     self.hooks.run('before_request_body')
                     if self.process_request_body:
-                        self.body.process()
+                        self.process_body()
                     
                     # Run the handler
                     self.stage = 'before_handler'
                     p[key.encode(self.query_string_encoding)] = value
         self.params.update(p)
     
+    def process_body(self):
+        """Process request body and update request.params accordingly."""
+        self.body.process()
+        params = self.params
+        for key, value in self.body.params.items():
+            # Python 2 only: keyword arguments must be byte strings (type 'str').
+            if sys.version_info < (3, 0):
+                if isinstance(key, unicode):
+                    key = key.encode('ISO-8859-1')
+
+            if key in params:
+                if not isinstance(params[key], list):
+                    params[key] = [params[key]]
+                params[key].append(value)
+            else:
+                params[key] = value
+
     def process_headers(self):
         """Parse HTTP header data into Python structures. (Core)"""
         # Process the headers into self.headers