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="<a>&lt;&gt;&amp;"</a>" />', ) inner = self.assertFlattensImmediately(innerTag, b'<a><>&"</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)
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" />')
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" />')
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)
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, ), ))
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="<a href=' ""&lt;&gt;&amp;&quot;">" '</a>" />', ) # As in checkTagAttributeSerialization, belt-and-suspenders: self.assertXMLEqual(XML(flattened).attrib["src"], '<a href="<>&""></a>')
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="<a href=' '"&lt;&gt;&amp;&quot;">' '</a>" />') # As in checkTagAttributeSerialization, belt-and-suspenders: self.assertXMLEqual( XML(flattened).attrib['src'], '<a href="<>&""></a>')
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="<>&"" />')
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="<>&"" />')
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="<>&"" />', )
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="<a>&lt;&gt;&amp;"</a>" />' ) inner = self.assertFlattensImmediately(innerTag, '<a><>&"</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)
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" />')
def test_serializeSelfClosingTags(self): """ The serialized form of a self-closing tag is C{'<tagName />'}. """ return self.assertFlattensTo(tags.img(), b"<img />")
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" />')
def test_serializeSelfClosingTags(self): """ The serialized form of a self-closing tag is C{'<tagName />'}. """ return self.assertFlattensTo(tags.img(), '<img />')
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" />')
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)
def test_serializeSelfClosingTags(self) -> None: """ The serialized form of a self-closing tag is C{'<tagName />'}. """ self.assertFlattensImmediately(tags.img(), b"<img />")