diff rhodecode/lib/__init__.py @ 1494:8e76649f11ad beta

fixes safe_str method - trye directly to encode with given encoding instead of trying to make a string out of the unicode
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 29 Sep 2011 22:55:32 +0300
parents 76b358f81926
children a2efbfe84067
line wrap: on
line diff
--- a/rhodecode/lib/__init__.py	Thu Sep 29 03:38:45 2011 +0300
+++ b/rhodecode/lib/__init__.py	Thu Sep 29 22:55:32 2011 +0300
@@ -177,7 +177,7 @@
     except UnicodeDecodeError:
         pass
     
-    try:
+    try:        
         import chardet
         encoding = chardet.detect(str_)['encoding']
         if encoding is None:
@@ -203,7 +203,7 @@
         return unicode_
 
     try:
-        return str(unicode_)
+        return unicode_.encode(to_encoding)
     except UnicodeEncodeError:
         pass