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
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))
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))
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([])
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
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
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
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([])
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([])
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([])
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))
def test_urldecode(): s = "one=two&three=four" assert len(utils.urldecode(s)) == 2
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))
def __call__(self, data, **metadata): d = urldecode(data) return "URLEncoded form", format_dict(ODict(d))
def _get_query(self): _, _, _, _, query, _ = urllib.parse.urlparse(self.url) return tuple(utils.urldecode(query))
def _get_urlencoded_form(self): is_valid_content_type = "application/x-www-form-urlencoded" in self.headers.get("content-type", "").lower() if is_valid_content_type: return tuple(utils.urldecode(self.content)) return ()
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))