def __str__(self): attributes = "".join([expand(" %s='%s'",(k,iri_to_uri(v))) for k,v \ in self.attributes.items() if v != None ]) if self.type == 'selfclose': return expand("<%s%s/>", (self.name, attributes)) else: return expand("<%s%s>%s</%s>", (self.name, attributes, self.innerHTML(), self.name))
def __str__(self): postfix = '' ## Some tags are never allowed to be outputted if self.name not in self.allowable_tags: if self.name in self.forbidden_tag: return '' #print "Rejected tag %s" % self.name return self.innerHTML() if self.name == 'head': self.children = [self.header,] + self.children elif self.name =='body': self.children = [self.body_extra, ] + self.children ## Frames without src are filtered because IE Whinges: if self.name == 'iframe' and 'src' not in self.attributes: return '' attributes = "".join([" %s='%s'" % (k,v) for k,v \ in self.attributes.items() if k in \ self.allowable_attributes]) if 'style' in self.attributes: attributes += ' style=%r' % self.css_filter(self.attributes['style'] or '') if 'http-equiv' in self.attributes: if self.attributes['http-equiv'].lower() == "content-type": ## PF _always_ outputs in utf8 attributes += ' http-equiv = "Content-Type" content="text/html; charset=UTF-8"' if 'src' in self.attributes: attributes += ' src=%s' % self.resolve_reference(self.attributes['src']) try: if 'href' in self.attributes: if self.name == 'link': attributes += " href=%s" % self.resolve_reference(self.attributes['href'], 'text/css') else: attributes += DB.expand(' href="javascript: alert(%r)"', iri_to_uri(DB.expand("%s",self.attributes['href'])[:100])) postfix = self.mark_link(self.attributes['href']) except: pass ## CSS needs to be filtered extra well if self.name == 'style': return expand("<style %s>%s</style>" , (attributes, self.css_filter(self.innerHTML()))) if self.type == 'selfclose': return expand("<%s%s/>%s" , (self.name, attributes, postfix)) else: return expand("<%s%s>%s</%s>%s", (self.name, attributes, self.innerHTML(), self.name,postfix))
def to_unicode(self, code): child_result = '' for c in self.children: if type(c)==str: child_result += c.encode(code) else: child_result += c.to_unicode(code) attributes = "".join([expand(" %s='%s'",(k,iri_to_uri(v))) for k,v \ in self.attributes.items() if v != None ]) if self.type == 'selfclose': result = expand("<%s%s/>", (self.name, attributes)) else: result = expand("<%s%s>%s</%s>", (self.name.encode("utf8"), attributes, child_result, self.name)) result = result.encode("latin1") return result
def __str__(self): postfix = '' ## Some tags are never allowed to be outputted if self.name not in self.allowable_tags: if self.name in self.forbidden_tag: return '' #print "Rejected tag %s" % self.name return self.innerHTML() if self.name == 'head': self.children = [ self.header, ] + self.children elif self.name == 'body': self.children = [ self.body_extra, ] + self.children ## Frames without src are filtered because IE Whinges: if self.name == 'iframe' and 'src' not in self.attributes: return '' attributes = "".join([" %s='%s'" % (k,v) for k,v \ in self.attributes.items() if k in \ self.allowable_attributes]) if 'style' in self.attributes: attributes += ' style=%r' % self.css_filter( self.attributes['style'] or '') if 'http-equiv' in self.attributes: if self.attributes['http-equiv'].lower() == "content-type": ## PF _always_ outputs in utf8 attributes += ' http-equiv = "Content-Type" content="text/html; charset=UTF-8"' if 'src' in self.attributes: attributes += ' src=%s' % self.resolve_reference( self.attributes['src']) try: if 'href' in self.attributes: if self.name == 'link': attributes += " href=%s" % self.resolve_reference( self.attributes['href'], 'text/css') else: attributes += DB.expand( ' href="javascript: alert(%r)"', iri_to_uri( DB.expand("%s", self.attributes['href'])[:100])) postfix = self.mark_link(self.attributes['href']) except: pass ## CSS needs to be filtered extra well if self.name == 'style': return expand("<style %s>%s</style>", (attributes, self.css_filter(self.innerHTML()))) if self.type == 'selfclose': return expand("<%s%s/>%s", (self.name, attributes, postfix)) else: return expand( "<%s%s>%s</%s>%s", (self.name, attributes, self.innerHTML(), self.name, postfix))