etwist/request.py
branchstable
changeset 5994 97c55baefa0c
parent 5868 c4380d8cfc25
child 7879 9aae456abab5
equal deleted inserted replaced
5976:00b1b6b906cf 5994:97c55baefa0c
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    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 """
       
    21 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    22 
    21 
    23 from datetime import datetime
    22 from datetime import datetime
    24 
    23 
    25 from twisted.web import http
    24 from twisted.web import http
    53     def http_method(self):
    52     def http_method(self):
    54         """returns 'POST', 'GET', 'HEAD', etc."""
    53         """returns 'POST', 'GET', 'HEAD', etc."""
    55         return self._twreq.method
    54         return self._twreq.method
    56 
    55 
    57     def relative_path(self, includeparams=True):
    56     def relative_path(self, includeparams=True):
    58         """return the normalized path of the request (ie at least relative
    57         """return the normalized path of the request (ie at least relative to
    59         to the instance's root, but some other normalization may be needed
    58         the instance's root, but some other normalization may be needed so that
    60         so that the returned path may be used to compare to generated urls
    59         the returned path may be used to compare to generated urls
    61 
    60 
    62         :param includeparams:
    61         :param includeparams:
    63            boolean indicating if GET form parameters should be kept in the path
    62            boolean indicating if GET form parameters should be kept in the path
    64         """
    63         """
    65         path = self._twreq.uri[1:] # remove the root '/'
    64         path = self._twreq.uri[1:] # remove the root '/'
    66         if not includeparams:
    65         if not includeparams:
    67             path = path.split('?', 1)[0]
    66             path = path.split('?', 1)[0]
    68         return path
    67         return path
    69 
    68 
    70     def get_header(self, header, default=None, raw=True):
    69     def get_header(self, header, default=None, raw=True):
    71         """return the value associated with the given input header,
    70         """return the value associated with the given input header, raise
    72         raise KeyError if the header is not set
    71         KeyError if the header is not set
    73         """
    72         """
    74         if raw:
    73         if raw:
    75             return self._headers_in.getRawHeaders(header, [default])[0]
    74             return self._headers_in.getRawHeaders(header, [default])[0]
    76         return self._headers_in.getHeader(header, default)
    75         return self._headers_in.getHeader(header, default)
    77 
    76