# HG changeset patch # User Marcin Kuzminski # Date 1317395510 -10800 # Node ID a2efbfe84067ecdbc260f860923749ffe90567c4 # Parent a828b83dfa4bcce2facea94da685db5b377fd290 fixes safe_unicode raise UnicodeDecodeError without any parameters diff -r a828b83dfa4b -r a2efbfe84067 rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py Fri Sep 30 18:07:03 2011 +0300 +++ b/rhodecode/lib/__init__.py Fri Sep 30 18:11:50 2011 +0300 @@ -168,24 +168,27 @@ :rtype: unicode :returns: unicode object """ - if isinstance(str_, unicode): return str_ try: + return unicode(str_) + except UnicodeDecodeError: + pass + + try: return unicode(str_, from_encoding) except UnicodeDecodeError: pass - - try: + + try: import chardet encoding = chardet.detect(str_)['encoding'] if encoding is None: - raise UnicodeDecodeError() - + raise Exception() return str_.decode(encoding) - except (ImportError, UnicodeDecodeError): - return unicode(str_, from_encoding, 'replace') + except (ImportError, UnicodeDecodeError, Exception): + return unicode(str_, from_encoding, 'replace') def safe_str(unicode_, to_encoding='utf8'): """