Python HTML Entity decode and encode

–– coding: utf-8 –
#decode
import HTMLParser
h = HTMLParser.HTMLParser()
print h.unescape('許功蓋')
許功蓋

#encode
a = u'許功蓋'
a.encode('ascii', 'xmlcharrefreplace')
'許功蓋'