示例#1
0
 def get_query(self):
     """
         Gets the request query string. Returns an ODict object.
     """
     _, _, _, _, query, _ = urlparse.urlparse(self.get_url())
     if query:
         return ODict(utils.urldecode(query))
     return ODict([])
示例#2
0
 def get_form_urlencoded(self):
     """
         Retrieves the URL-encoded form data, returning an ODict object.
         Returns an empty ODict if there is no data or the content-type
         indicates non-form data.
     """
     if self.content and self.headers.in_any("content-type", HDR_FORM_URLENCODED, True):
         return ODict(utils.urldecode(self.content))
     return ODict([])
示例#3
0
 def urlencoded_form(self):
     """
     The URL-encoded form data as an :py:class:`ODict` object.
     None if there is no data or the content-type indicates non-form data.
     """
     is_valid_content_type = "application/x-www-form-urlencoded" in self.headers.get("content-type", "").lower()
     if self.content and is_valid_content_type:
         return ODict(utils.urldecode(self.content))
     return None
示例#4
0
 def __call__(self, hdrs, content, limit):
     lines = utils.urldecode(content)
     if lines:
         body = common.format_keyvals(
             [(k + ":", v) for (k, v) in lines],
             key = "header",
             val = "text"
         )
         return "URLEncoded form", body
示例#5
0
 def query(self):
     """
     The request query string as an :py:class:`ODict` object.
     None, if there is no query.
     """
     _, _, _, _, query, _ = urllib.parse.urlparse(self.url)
     if query:
         return ODict(utils.urldecode(query))
     return None
示例#6
0
 def get_form_urlencoded(self):
     """
         Retrieves the URL-encoded form data, returning an ODict object.
         Returns an empty ODict if there is no data or the content-type
         indicates non-form data.
     """
     if self.body and HDR_FORM_URLENCODED in self.headers.get("content-type", "").lower():
         return odict.ODict(utils.urldecode(self.body))
     return odict.ODict([])
示例#7
0
    def test_get_urlencoded_form(self):
        request = treq(content="foobar")
        assert request.urlencoded_form is None

        request.headers["Content-Type"] = "application/x-www-form-urlencoded"
        assert request.urlencoded_form == ODict(utils.urldecode(request.content))
示例#8
0
    def test_get_form_urlencoded(self):
        req = tutils.treq(body="foobar")
        assert req.get_form_urlencoded() == ODict()

        req.headers["Content-Type"] = HDR_FORM_URLENCODED
        assert req.get_form_urlencoded() == ODict(utils.urldecode(req.body))
示例#9
0
def test_urldecode():
    s = "one=two&three=four"
    assert len(utils.urldecode(s)) == 2
示例#10
0
 def __call__(self, data, **metadata):
     d = urldecode(data)
     return "URLEncoded form", format_dict(ODict(d))
    def test_get_form_urlencoded(self):
        req = tutils.treq("foobar")
        assert req.get_form_urlencoded() == odict.ODict()

        req.headers["Content-Type"] = [semantics.HDR_FORM_URLENCODED]
        assert req.get_form_urlencoded() == odict.ODict(utils.urldecode(req.body))