author | Denis Laxalde <denis.laxalde@logilab.fr> |
Thu, 24 Oct 2013 09:20:45 +0200 | |
branch | stable |
changeset 9314 | 178791fde195 |
parent 8930 | 6a02be304486 |
child 9147 | 01124cfd4b1f |
permissions | -rw-r--r-- |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5868
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4425
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5443
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""Twisted request handler for CubicWeb""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
22 |
||
23 |
from cubicweb.web.request import CubicWebRequestBase |
|
24 |
||
25 |
||
26 |
class CubicWebTwistedRequestAdapter(CubicWebRequestBase): |
|
8309
48ef505aa9f9
[request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7879
diff
changeset
|
27 |
def __init__(self, req, vreg, https): |
0 | 28 |
self._twreq = req |
8314
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8309
diff
changeset
|
29 |
super(CubicWebTwistedRequestAdapter, self).__init__( |
cfd6ab461849
[Web-Request] Use rich header (closes #2204164)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8309
diff
changeset
|
30 |
vreg, https, req.args, headers=req.received_headers) |
5155
1dea6e0fdfc1
Switched from TwistedWeb2 to TwistedWeb
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4425
diff
changeset
|
31 |
for key, (name, stream) in req.files.iteritems(): |
1dea6e0fdfc1
Switched from TwistedWeb2 to TwistedWeb
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4425
diff
changeset
|
32 |
if name is None: |
1dea6e0fdfc1
Switched from TwistedWeb2 to TwistedWeb
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4425
diff
changeset
|
33 |
self.form[key] = (name, stream) |
1dea6e0fdfc1
Switched from TwistedWeb2 to TwistedWeb
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4425
diff
changeset
|
34 |
else: |
1dea6e0fdfc1
Switched from TwistedWeb2 to TwistedWeb
Adrien Chauve <adrien.chauve@logilab.fr>
parents:
4425
diff
changeset
|
35 |
self.form[key] = (unicode(name, self.encoding), stream) |
8752
e19f4bba89cd
Add CubicWebRequestBase.content (closes #2742453)
Julien Cristau <julien.cristau@logilab.fr>
parents:
8316
diff
changeset
|
36 |
self.content = self._twreq.content # stream |
0 | 37 |
|
38 |
def http_method(self): |
|
39 |
"""returns 'POST', 'GET', 'HEAD', etc.""" |
|
40 |
return self._twreq.method |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
41 |
|
0 | 42 |
def relative_path(self, includeparams=True): |
5443
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
43 |
"""return the normalized path of the request (ie at least relative to |
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
44 |
the instance's root, but some other normalization may be needed so that |
f299ee54d7e0
[webconfig] cleanup base_url management
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
45 |
the returned path may be used to compare to generated urls |
0 | 46 |
|
47 |
:param includeparams: |
|
48 |
boolean indicating if GET form parameters should be kept in the path |
|
49 |
""" |
|
50 |
path = self._twreq.uri[1:] # remove the root '/' |
|
51 |
if not includeparams: |
|
52 |
path = path.split('?', 1)[0] |
|
53 |
return path |