bug fix: removed \r in textversion's content because of a comment position bug in pre_edit. Added a save function to TextVersionManager to do so. Also removed cleaning \r before computing diffs because it should not be necessary anymore.
import chardet
def to_unicode(input):
if type(input) == str:
res = None
for encoding in [chardet.detect(input)['encoding'], 'utf8', 'latin1']:
try:
res = unicode(input, encoding)
break;
except UnicodeDecodeError:
pass
if not res:
raise Exception('UnicodeDecodeError: could not decode')
return res
return input