Mercurial > public > src > rhodecode
changeset 1582:a2efbfe84067 beta
fixes safe_unicode raise UnicodeDecodeError without any parameters
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 30 Sep 2011 18:11:50 +0300 |
parents | a828b83dfa4b |
children | b02aa5f2f066 |
files | rhodecode/lib/__init__.py |
diffstat | 1 files changed, 10 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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'): """