28 import tempfile |
28 import tempfile |
29 |
29 |
30 from StringIO import StringIO |
30 from StringIO import StringIO |
31 from urllib import quote |
31 from urllib import quote |
32 from urlparse import parse_qs |
32 from urlparse import parse_qs |
|
33 from warnings import warn |
33 |
34 |
34 from cubicweb.multipart import copy_file, parse_form_data |
35 from cubicweb.multipart import copy_file, parse_form_data |
35 from cubicweb.web.request import CubicWebRequestBase |
36 from cubicweb.web.request import CubicWebRequestBase |
36 from cubicweb.wsgi import pformat, normalize_header |
37 from cubicweb.wsgi import pformat, normalize_header |
37 |
38 |
150 post = parse_qs(self.environ.get('QUERY_STRING', '')) |
151 post = parse_qs(self.environ.get('QUERY_STRING', '')) |
151 files = None |
152 files = None |
152 if self.method == 'POST': |
153 if self.method == 'POST': |
153 forms, files = parse_form_data(self.environ, strict=True, |
154 forms, files = parse_form_data(self.environ, strict=True, |
154 mem_limit=self.vreg.config['max-post-length']) |
155 mem_limit=self.vreg.config['max-post-length']) |
155 post.update(forms) |
156 post.update(forms.dict) |
156 self.content.seek(0, 0) |
157 self.content.seek(0, 0) |
157 return post, files |
158 return post, files |
|
159 |
|
160 def setup_params(self, params): |
|
161 # This is a copy of CubicWebRequestBase.setup_params, but without |
|
162 # converting unicode strings because it is partially done by |
|
163 # get_posted_data |
|
164 self.form = {} |
|
165 if params is None: |
|
166 return |
|
167 encoding = self.encoding |
|
168 for param, val in params.iteritems(): |
|
169 if isinstance(val, (tuple, list)): |
|
170 val = [ |
|
171 unicode(x, encoding) if isinstance(x, str) else x |
|
172 for x in val] |
|
173 if len(val) == 1: |
|
174 val = val[0] |
|
175 elif isinstance(val, str): |
|
176 val = unicode(val, encoding) |
|
177 if param in self.no_script_form_params and val: |
|
178 val = self.no_script_form_param(param, val) |
|
179 if param == '_cwmsgid': |
|
180 self.set_message_id(val) |
|
181 elif param == '__message': |
|
182 warn('[3.13] __message in request parameter is deprecated (may ' |
|
183 'only be given to .build_url). Seeing this message usualy ' |
|
184 'means your application hold some <form> where you should ' |
|
185 'replace use of __message hidden input by form.set_message, ' |
|
186 'so new _cwmsgid mechanism is properly used', |
|
187 DeprecationWarning) |
|
188 self.set_message(val) |
|
189 else: |
|
190 self.form[param] = val |