Пример #1
0
    def checkTagAttributeSerialization(
            self, wrapTag: Callable[[Tag], Flattenable]) -> None:
        """
        Common implementation of L{test_serializedAttributeWithTag} and
        L{test_serializedAttributeWithDeferredTag}.

        @param wrapTag: A 1-argument callable that wraps around the attribute's
            value so other tests can customize it.
        @type wrapTag: callable taking L{Tag} and returning something
            flattenable
        """
        innerTag = tags.a('<>&"')
        outerTag = tags.img(src=wrapTag(innerTag))
        outer = self.assertFlattensImmediately(
            outerTag,
            b'<img src="&lt;a&gt;&amp;lt;&amp;gt;&amp;amp;&quot;&lt;/a&gt;" />',
        )
        inner = self.assertFlattensImmediately(innerTag,
                                               b'<a>&lt;&gt;&amp;"</a>')

        # Since the above quoting is somewhat tricky, validate it by making sure
        # that the main use-case for tag-within-attribute is supported here: if
        # we serialize a tag, it is quoted *such that it can be parsed out again
        # as a tag*.
        self.assertXMLEqual(XML(outer).attrib["src"], inner)
Пример #2
0
 def test_serializedMultipleAttributes(self):
     """
     Multiple attributes are separated by a single space in their serialized
     form.
     """
     tag = tags.img()
     tag.attributes = OrderedAttributes([("src", "foo"), ("name", "bar")])
     self.assertFlattensImmediately(tag, '<img src="foo" name="bar" />')
Пример #3
0
 def test_serializedMultipleAttributes(self):
     """
     Multiple attributes are separated by a single space in their serialized
     form.
     """
     tag = tags.img()
     tag.attributes = OrderedDict([("src", "foo"), ("name", "bar")])
     self.assertFlattensImmediately(tag, b'<img src="foo" name="bar" />')
Пример #4
0
 def main(self, request, tag):
     path = request.URLPath()
     l = []
     for y in range(-5, 5):
         for x in range(-5, 5):
             child = path.child("%s,%s" % (x, y))
             l.append(tags.img(src=str(child), height="64", width="64"))
         l.append(tags.br())
     return tag(*l)
Пример #5
0
 def main(self, request, tag):
     path = request.URLPath()
     l = []
     for y in range(-5, 5):
         for x in range(-5, 5):
             child = path.child("%s,%s" % (x, y))
             l.append(tags.img(src=str(child), height="64", width="64"))
         l.append(tags.br())
     return tag(*l)
Пример #6
0
 def linkTag(self, time, arrowDirection, hidden=False):
     style = LINK_STYLE
     if hidden:
         style += ' visibility: hidden;'
     return tags.a(style=style,
                   href="?time=%s" %
                   (time.asDatetime().strftime('%Y-%m-%d'), ))(tags.img(
                       border="0",
                       src="static/%s-arrow.png" % (arrowDirection, ),
                   ))
Пример #7
0
    def test_serializedAttributeWithTagWithAttribute(self):
        """
        Similar to L{test_serializedAttributeWithTag}, but for the additional
        complexity where the tag which is the attribute value itself has an
        attribute value which contains bytes which require substitution.
        """
        flattened = self.assertFlattensImmediately(
            tags.img(src=tags.a(href='<>&"')),
            '<img src="&lt;a href=' "&quot;&amp;lt;&amp;gt;&amp;amp;&amp;quot;&quot;&gt;" '&lt;/a&gt;" />',
        )

        # As in checkTagAttributeSerialization, belt-and-suspenders:
        self.assertXMLEqual(XML(flattened).attrib["src"], '<a href="&lt;&gt;&amp;&quot;"></a>')
Пример #8
0
    def test_serializedAttributeWithTagWithAttribute(self):
        """
        Similar to L{test_serializedAttributeWithTag}, but for the additional
        complexity where the tag which is the attribute value itself has an
        attribute value which contains bytes which require substitution.
        """
        flattened = self.assertFlattensImmediately(
            tags.img(src=tags.a(href='<>&"')), '<img src="&lt;a href='
            '&quot;&amp;lt;&amp;gt;&amp;amp;&amp;quot;&quot;&gt;'
            '&lt;/a&gt;" />')

        # As in checkTagAttributeSerialization, belt-and-suspenders:
        self.assertXMLEqual(
            XML(flattened).attrib['src'], '<a href="&lt;&gt;&amp;&quot;"></a>')
Пример #9
0
    def checkAttributeSanitization(self, wrapData, wrapTag):
        """
        Common implementation of L{test_serializedAttributeWithSanitization}
        and L{test_serializedDeferredAttributeWithSanitization},
        L{test_serializedAttributeWithTransparentTag}.

        @param wrapData: A 1-argument callable that wraps around the
            attribute's value so other tests can customize it.
        @param wrapData: callable taking L{bytes} and returning something
            flattenable

        @param wrapTag: A 1-argument callable that wraps around the outer tag
            so other tests can customize it.
        @type wrapTag: callable taking L{Tag} and returning L{Tag}.
        """
        self.assertFlattensImmediately(wrapTag(tags.img(src=wrapData('<>&"'))), '<img src="&lt;&gt;&amp;&quot;" />')
Пример #10
0
    def checkAttributeSanitization(self, wrapData, wrapTag):
        """
        Common implementation of L{test_serializedAttributeWithSanitization}
        and L{test_serializedDeferredAttributeWithSanitization},
        L{test_serializedAttributeWithTransparentTag}.

        @param wrapData: A 1-argument callable that wraps around the
            attribute's value so other tests can customize it.
        @param wrapData: callable taking L{bytes} and returning something
            flattenable

        @param wrapTag: A 1-argument callable that wraps around the outer tag
            so other tests can customize it.
        @type wrapTag: callable taking L{Tag} and returning L{Tag}.
        """
        self.assertFlattensImmediately(
            wrapTag(tags.img(src=wrapData("<>&\""))),
            '<img src="&lt;&gt;&amp;&quot;" />')
Пример #11
0
    def checkAttributeSanitization(
        self,
        wrapData: Callable[[str], Flattenable],
        wrapTag: Callable[[Tag], Flattenable],
    ) -> None:
        """
        Common implementation of L{test_serializedAttributeWithSanitization}
        and L{test_serializedDeferredAttributeWithSanitization},
        L{test_serializedAttributeWithTransparentTag}.

        @param wrapData: A 1-argument callable that wraps around the
            attribute's value so other tests can customize it.

        @param wrapTag: A 1-argument callable that wraps around the outer tag
            so other tests can customize it.
        """
        self.assertFlattensImmediately(
            wrapTag(tags.img(src=wrapData('<>&"'))),
            b'<img src="&lt;&gt;&amp;&quot;" />',
        )
Пример #12
0
    def checkTagAttributeSerialization(self, wrapTag):
        """
        Common implementation of L{test_serializedAttributeWithTag} and
        L{test_serializedAttributeWithDeferredTag}.

        @param wrapTag: A 1-argument callable that wraps around the attribute's
            value so other tests can customize it.
        @param wrapTag: callable taking L{Tag} and returning something
            flattenable
        """
        innerTag = tags.a('<>&"')
        outerTag = tags.img(src=wrapTag(innerTag))
        outer = self.assertFlattensImmediately(
            outerTag, '<img src="&lt;a&gt;&amp;lt;&amp;gt;&amp;amp;&quot;&lt;/a&gt;" />'
        )
        inner = self.assertFlattensImmediately(innerTag, '<a>&lt;&gt;&amp;"</a>')

        # Since the above quoting is somewhat tricky, validate it by making sure
        # that the main use-case for tag-within-attribute is supported here: if
        # we serialize a tag, it is quoted *such that it can be parsed out again
        # as a tag*.
        self.assertXMLEqual(XML(outer).attrib["src"], inner)
Пример #13
0
 def test_serializeAttribute(self):
     """
     The serialized form of attribute I{a} with value I{b} is C{'a="b"'}.
     """
     self.assertFlattensImmediately(tags.img(src="foo"), b'<img src="foo" />')
Пример #14
0
 def test_serializeSelfClosingTags(self):
     """
     The serialized form of a self-closing tag is C{'<tagName />'}.
     """
     return self.assertFlattensTo(tags.img(), b"<img />")
Пример #15
0
 def test_serializeAttribute(self):
     """
     The serialized form of attribute I{a} with value I{b} is C{'a="b"'}.
     """
     self.assertFlattensImmediately(tags.img(src='foo'),
                                    '<img src="foo" />')
Пример #16
0
 def test_serializeSelfClosingTags(self):
     """
     The serialized form of a self-closing tag is C{'<tagName />'}.
     """
     return self.assertFlattensTo(tags.img(), '<img />')
Пример #17
0
 def test_serializeSelfClosingTags(self):
     """
     Test that some tags are normally written out as self-closing tags.
     """
     return self.assertFlattensTo(tags.img(src='test'), '<img src="test" />')
Пример #18
0
 def test_serializeSelfClosingTags(self):
     """
     Test that some tags are normally written out as self-closing tags.
     """
     return self.assertFlattensTo(tags.img(src='test'),
                                  '<img src="test" />')
Пример #19
0
 def comment(self, request, tag):
     if self.post.file:
         image = tags.img(src=self.post.file)
         return tag(image, self.post.comment)
     else:
         return tag(self.post.comment)
Пример #20
0
 def test_serializeSelfClosingTags(self) -> None:
     """
     The serialized form of a self-closing tag is C{'<tagName />'}.
     """
     self.assertFlattensImmediately(tags.img(), b"<img />")