diff rhodecode/lib/vcs/utils/__init__.py @ 2016:6020e3884a58 beta

implements #212 moved default encoding variable into rhodecode-config. It's now possible to change default utf8 to some other encoding. - also added instance-id to config - update ini files
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 22 Feb 2012 04:30:26 +0200
parents 324ac367a4da
children 7e979933ffec
line wrap: on
line diff
--- a/rhodecode/lib/vcs/utils/__init__.py	Wed Feb 22 04:11:29 2012 +0200
+++ b/rhodecode/lib/vcs/utils/__init__.py	Wed Feb 22 04:30:26 2012 +0200
@@ -27,7 +27,7 @@
     return datetime.datetime.fromtimestamp(float(unixts))
 
 
-def safe_unicode(str_, from_encoding='utf8'):
+def safe_unicode(str_, from_encoding=None):
     """
     safe unicode function. Does few trick to turn str_ into unicode
 
@@ -40,7 +40,10 @@
     """
     if isinstance(str_, unicode):
         return str_
-
+    if not from_encoding:
+        import rhodecode
+        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding','utf8')
+        from_encoding = DEFAULT_ENCODING
     try:
         return unicode(str_)
     except UnicodeDecodeError:
@@ -61,7 +64,7 @@
         return unicode(str_, from_encoding, 'replace')
 
 
-def safe_str(unicode_, to_encoding='utf8'):
+def safe_str(unicode_, to_encoding=None):
     """
     safe str function. Does few trick to turn unicode_ into string
 
@@ -75,7 +78,10 @@
 
     if isinstance(unicode_, str):
         return unicode_
-
+    if not to_encoding:
+        import rhodecode
+        DEFAULT_ENCODING = rhodecode.CONFIG.get('default_encoding','utf8')
+        to_encoding = DEFAULT_ENCODING
     try:
         return unicode_.encode(to_encoding)
     except UnicodeEncodeError: