Example #1
0
 def viewing_html(self):
     """Return whether the current response contains HTML data."""
     if self._response is None:
         raise BrowserStateError("not viewing any document")
     ct_hdrs = self._response.info().getheaders("content-type")
     url = self._response.geturl()
     return is_html(ct_hdrs, url)
Example #2
0
 def test_is_html(self):
     from ClientCookie._HeadersUtil import is_html
     for allow_xhtml in False, True:
         for cths, ext, expect in [
             (["text/html"], ".html", True),
             (["text/html", "text/plain"], ".html", True),
             # Content-type takes priority over file extension from URL
             (["text/html"], ".txt", True),
             (["text/plain"], ".html", False),
             # use extension if no Content-Type
             ([], ".html", True),
             ([], ".gif", False),
             # don't regard XHTML as HTML (unless user explicitly asks for it),
             # since we don't yet handle XML properly
             ([], ".xhtml", allow_xhtml),
             (["text/xhtml"], ".xhtml", allow_xhtml),
             ]:
             url = "http://example.com/foo"+ext
             self.assertEqual(expect, is_html(cths, url, allow_xhtml))
Example #3
0
 def test_is_html(self):
     from ClientCookie._HeadersUtil import is_html
     for allow_xhtml in False, True:
         for cths, ext, expect in [
             (["text/html"], ".html", True),
             (["text/html", "text/plain"], ".html", True),
                 # Content-type takes priority over file extension from URL
             (["text/html"], ".txt", True),
             (["text/plain"], ".html", False),
                 # use extension if no Content-Type
             ([], ".html", True),
             ([], ".gif", False),
                 # don't regard XHTML as HTML (unless user explicitly asks for it),
                 # since we don't yet handle XML properly
             ([], ".xhtml", allow_xhtml),
             (["text/xhtml"], ".xhtml", allow_xhtml),
         ]:
             url = "http://example.com/foo" + ext
             self.assertEqual(expect, is_html(cths, url, allow_xhtml))