Beispiel #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([])
Beispiel #2
0
 def cookies(self):
     """
     The request cookies.
     An empty :py:class:`ODict` object if the cookie monster ate them all.
     """
     ret = ODict()
     for i in self.headers.get_all("Cookie"):
         ret.extend(cookies.parse_cookie_header(i))
     return ret
Beispiel #3
0
 def cookies(self):
     """
     The request cookies.
     An empty :py:class:`ODict` object if the cookie monster ate them all.
     """
     ret = ODict()
     for i in self.headers.get_all("Cookie"):
         ret.extend(cookies.parse_cookie_header(i))
     return ret
Beispiel #4
0
 def test_get_cookies_twocookies(self):
     resp = tresp()
     resp.headers = Headers([[b"Set-Cookie", b"cookiename=cookievalue"],
                             [b"Set-Cookie", b"othercookie=othervalue"]])
     result = resp.cookies
     assert len(result) == 2
     assert "cookiename" in result
     assert result["cookiename"][0] == ["cookievalue", ODict()]
     assert "othercookie" in result
     assert result["othercookie"][0] == ["othervalue", ODict()]
Beispiel #5
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([])
Beispiel #6
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))
Beispiel #7
0
 def __call__(self, data, **metadata):
     try:
         img = Image.open(StringIO(data))
     except IOError:
         return None
     parts = [
         ("Format", str(img.format_description)),
         ("Size", "%s x %s px" % img.size),
         ("Mode", str(img.mode)),
     ]
     for i in sorted(img.info.keys()):
         if i != "exif":
             parts.append(
                 (str(i), str(img.info[i]))
             )
     if hasattr(img, "_getexif"):
         ex = img._getexif()
         if ex:
             for i in sorted(ex.keys()):
                 tag = TAGS.get(i, i)
                 parts.append(
                     (str(tag), str(ex[i]))
                 )
     fmt = format_dict(ODict(parts))
     return "%s image" % img.format, fmt
Beispiel #8
0
 def test_get_cookies_simple(self):
     resp = tresp()
     resp.headers = Headers(set_cookie="cookiename=cookievalue")
     result = resp.cookies
     assert len(result) == 1
     assert "cookiename" in result
     assert result["cookiename"][0] == ["cookievalue", ODict()]
Beispiel #9
0
    def test_get_multipart_form(self):
        request = treq(content="foobar")
        assert request.multipart_form is None

        request.headers["Content-Type"] = "multipart/form-data"
        assert request.multipart_form == ODict(
            utils.multipartdecode(request.headers, request.content))
Beispiel #10
0
 def test_set_path_components(self):
     request = treq(host=b"foo", headers=Headers(host=b"bar"))
     request.path_components = ["foo", "baz"]
     assert request.path == "/foo/baz"
     request.path_components = []
     assert request.path == "/"
     request.query = ODict([])
     assert request.host == b"foo"
     assert request.headers["host"] == b"bar"
Beispiel #11
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
Beispiel #12
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
Beispiel #13
0
 def multipart_form(self):
     """
     The multipart 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 = "multipart/form-data" in self.headers.get("content-type", "").lower()
     if self.content and is_valid_content_type:
         return ODict(utils.multipartdecode(self.headers,self.content))
     return None
Beispiel #14
0
    def test_view_auto(self):
        v = cv.ViewAuto()
        f = v("foo", headers=Headers())
        assert f[0] == "Raw"

        f = v("<html></html>", headers=Headers(content_type="text/html"))
        assert f[0] == "HTML"

        f = v("foo", headers=Headers(content_type="text/flibble"))
        assert f[0] == "Raw"

        f = v("<xml></xml>", headers=Headers(content_type="text/flibble"))
        assert f[0].startswith("XML")

        f = v("", headers=Headers())
        assert f[0] == "No content"

        f = v(
            "",
            headers=Headers(),
            query=ODict([("foo", "bar")]),
        )
        assert f[0] == "Query"
Beispiel #15
0
 def _format(v):
     yield [("highlight", "Form data:\n")]
     for message in format_dict(ODict(v)):
         yield message
Beispiel #16
0
 def __call__(self, data, **metadata):
     d = urldecode(data)
     return "URLEncoded form", format_dict(ODict(d))
Beispiel #17
0
 def test_view_query(self):
     d = ""
     v = cv.ViewQuery()
     f = v(d, query=ODict([("foo", "bar")]))
     assert f[0] == "Query"
     assert [x for x in f[1]] == [[("header", "foo: "), ("text", "bar")]]
Beispiel #18
0
 def get_form_urlencoded(self):  # pragma: nocover
     warnings.warn(
         ".get_form_urlencoded is deprecated, use .urlencoded_form instead.",
         DeprecationWarning)
     return self.urlencoded_form or ODict([])
Beispiel #19
0
 def get_form_multipart(self):  # pragma: nocover
     warnings.warn(
         ".get_form_multipart is deprecated, use .multipart_form instead.",
         DeprecationWarning)
     return self.multipart_form or ODict([])
Beispiel #20
0
 def get_query(self):  # pragma: nocover
     warnings.warn(".get_query is deprecated, use .query instead.",
                   DeprecationWarning)
     return self.query or ODict([])
Beispiel #21
0
 def test_set_query(self):
     request = treq(host=b"foo", headers=Headers(host=b"bar"))
     request.query = ODict([])
     assert request.host == b"foo"
     assert request.headers["host"] == b"bar"
Beispiel #22
0
 def test_set_query(self):
     request = treq()
     request.query = ODict([])
Beispiel #23
0
 def test_odict2dict(self):
     odict = ODict([('k1', 'v1'), ('k2', 'v2'), ('k1', 'v10')])
     d1 = FlowHandler.odict2dict(odict)
     assert d1 == {'k1': ['v1', 'v10'], 'k2': ['v2']}
     d2 = FlowHandler.odict2dict(odict, False)
     assert d2 == {'k1': 'v10', 'k2': 'v2'}
Beispiel #24
0
 def test_set_urlencoded_form(self):
     request = treq()
     request.urlencoded_form = ODict([('foo', 'bar'), ('rab', 'oof')])
     assert request.headers[
         "Content-Type"] == "application/x-www-form-urlencoded"
     assert request.content