# HG changeset patch # User Marcin Kuzminski # Date 2011-09-29 21:55:32 # Node ID 8e76649f11adc07a7f20facfaf0812002ec2dcc0 # Parent 5a3252dd7fd9270a7c2b6e0d62a634e2086e9f71 fixes safe_str method - trye directly to encode with given encoding instead of trying to make a string out of the unicode diff --git a/rhodecode/lib/__init__.py b/rhodecode/lib/__init__.py --- a/rhodecode/lib/__init__.py +++ b/rhodecode/lib/__init__.py @@ -177,7 +177,7 @@ def safe_unicode(str_, from_encoding='ut except UnicodeDecodeError: pass - try: + try: import chardet encoding = chardet.detect(str_)['encoding'] if encoding is None: @@ -203,7 +203,7 @@ def safe_str(unicode_, to_encoding='utf8 return unicode_ try: - return str(unicode_) + return unicode_.encode(to_encoding) except UnicodeEncodeError: pass