15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """Twisted request handler for CubicWeb""" |
18 """Twisted request handler for CubicWeb""" |
19 |
19 |
20 |
20 from six import text_type |
21 |
|
22 |
21 |
23 from cubicweb.web.request import CubicWebRequestBase |
22 from cubicweb.web.request import CubicWebRequestBase |
24 |
23 |
25 |
24 |
26 class CubicWebTwistedRequestAdapter(CubicWebRequestBase): |
25 class CubicWebTwistedRequestAdapter(CubicWebRequestBase): |
32 super(CubicWebTwistedRequestAdapter, self).__init__( |
31 super(CubicWebTwistedRequestAdapter, self).__init__( |
33 vreg, https, req.args, headers=req.received_headers) |
32 vreg, https, req.args, headers=req.received_headers) |
34 for key, name_stream_list in req.files.items(): |
33 for key, name_stream_list in req.files.items(): |
35 for name, stream in name_stream_list: |
34 for name, stream in name_stream_list: |
36 if name is not None: |
35 if name is not None: |
37 name = unicode(name, self.encoding) |
36 name = text_type(name, self.encoding) |
38 self.form.setdefault(key, []).append((name, stream)) |
37 self.form.setdefault(key, []).append((name, stream)) |
39 # 3.16.4 backward compat |
38 # 3.16.4 backward compat |
40 if len(self.form[key]) == 1: |
39 if len(self.form[key]) == 1: |
41 self.form[key] = self.form[key][0] |
40 self.form[key] = self.form[key][0] |
42 self.content = self._twreq.content # stream |
41 self.content = self._twreq.content # stream |