def to_xml(self, client_context): xml = "<%s" % self._name for attrib_name in self._attribs: if isinstance(self._attribs[attrib_name], str): attrib_value = self._attribs[attrib_name] else: attrib_value = self._attribs[attrib_name].resolve( client_context) escaped = TextUtils.html_escape(attrib_value) xml += ' %s="%s"' % (attrib_name, escaped) xml += ">" child_xml = self.children_to_xml(client_context) xml += child_xml xml += "</%s>" % self._name return xml
def resolve_to_string(self, client_context): xml = "<%s" % self._name for attrib_name in self._attribs: if isinstance(self._attribs[attrib_name], str): attrib_value = self._attribs[attrib_name] else: attrib_value = self._attribs[attrib_name].resolve( client_context) escaped = TextUtils.html_escape(attrib_value) escaped = escaped.replace(" ", "") xml += ' %s="%s"' % (attrib_name, escaped) xml += ">" xml += self.resolve_children_to_string(client_context) xml += "</%s>" % self._name return xml
def to_xml(self, client_context): return TextUtils.html_escape(self.word)
def test_html_escape(self): self.assertEquals("", TextUtils.html_escape("")) self.assertEquals(" ", TextUtils.html_escape(" ")) self.assertEquals("<>", TextUtils.html_escape("<>")) self.assertEquals("<regex/>", TextUtils.html_escape("<regex/>"))