elem = HTMLElement(HTMLElement.TEXT)
elem._parent = self._cursor
+
+ # text encode check and convert.
+ # if charset is given, convert text to unicode type.
if self.charset:
- elem._text = unicode(data, self.charset).encode("utf-8")
+ try:
+ elem._text = unicode(data, self.charset)
+ except TypeError:
+ # self.charset is utf-8.
+ elem._text = data
else:
+ # treat as unicode input
elem._text = data
self._cursor.append(elem)