def characters(self, data): if data: if isinstance(data, unicode): data = data.encode(self.encoding) self.out.write(escape(None, data))
def startElement(self, tag, attrs): self.out.write('<') self.out.write(tag) if attrs: for name, value in attrs.iteritems(): if isinstance(value, unicode): value = value.encode(self.encoding) self.out.write(' ') self.out.write(name) self.out.write('="') self.out.write(escape(None, value)) self.out.write('"') self.out.write('>')