comparison src/plugins/plugin_xep_0277.py @ 838:8829a6c0b070

plugin XEP_0277: fix encode/decode errors
author souliane <souliane@mailoo.org>
date Wed, 12 Feb 2014 15:24:03 +0100
parents eff944ff3e13
children a8260ee88708
comparison
equal deleted inserted replaced
837:eff944ff3e13 838:8829a6c0b070
216 if type_: 216 if type_:
217 if type_ == 'rich': # convert input from current syntax to XHTML 217 if type_ == 'rich': # convert input from current syntax to XHTML
218 converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML") 218 converted = yield synt.convert(data[attr], synt.getCurrentSyntax(profile), "XHTML")
219 else: # clean the XHTML input 219 else: # clean the XHTML input
220 converted = yield synt.clean_xhtml(data[attr]) 220 converted = yield synt.clean_xhtml(data[attr])
221 elem = elems[key](u'<div xmlns="%s">%s</div>' % (NS_XHTML, converted)) 221 elem = elems[key]((u'<div xmlns="%s">%s</div>' % (NS_XHTML, converted)).encode('utf-8'))
222 elem.attrs['type'] = 'xhtml' 222 elem.attrs['type'] = 'xhtml'
223 if hasattr(_entry, '%s_xhtml' % key): 223 if hasattr(_entry, '%s_xhtml' % key):
224 raise exceptions.DataError(_("Can't have xhtml and rich content at the same time")) 224 raise exceptions.DataError(_("Can't have xhtml and rich content at the same time"))
225 setattr(_entry, '%s_xhtml' % key, elem) 225 setattr(_entry, '%s_xhtml' % key, elem)
226 else: # raw text only needs to be escaped to get HTML-safe sequence 226 else: # raw text only needs to be escaped to get HTML-safe sequence
227 elem = elems[key](escape(data[attr])) 227 elem = elems[key](escape(data[attr]).encode('utf-8'))
228 elem.attrs['type'] = 'text' 228 elem.attrs['type'] = 'text'
229 setattr(_entry, key, elem) 229 setattr(_entry, key, elem)
230 if not getattr(_entry, key).text: 230 if not getattr(_entry, key).text:
231 if hasattr(_entry, '%s_xhtml' % key): 231 if hasattr(_entry, '%s_xhtml' % key):
232 text = yield self.__removeXHTMLMarkups(getattr(_entry, '%s_xhtml' % key).text) 232 text = yield self.__removeXHTMLMarkups(getattr(_entry, '%s_xhtml' % key).text)