[CMF-checkins] CVS: Products/CMFDefault - utils.py:1.26.2.1

Yvo Schubbe y.2004_ at wcm-solutions.de
Sun Oct 17 15:35:50 EDT 2004


Update of /cvs-repository/Products/CMFDefault
In directory cvs.zope.org:/tmp/cvs-serv30082/CMFDefault

Modified Files:
      Tag: CMF-1_5-branch
	utils.py 
Log Message:
- added 'toUnicode' function (http://collector.zope.org/CMF/261, part 1)


=== Products/CMFDefault/utils.py 1.26 => 1.26.2.1 ===
--- Products/CMFDefault/utils.py:1.26	Thu Aug 12 11:07:40 2004
+++ Products/CMFDefault/utils.py	Sun Oct 17 15:35:50 2004
@@ -425,3 +425,20 @@
     for key, converter, value in complex_marshal( kw.items() ):
         vars.append( ( key + converter, escape( str(value) ) ) )
     return tuple(vars)
+
+security.declarePublic('toUnicode')
+def toUnicode(value, charset=None):
+    """ Convert value to unicode.
+    """
+    if isinstance(value, str):
+        return charset and unicode(value, charset) or unicode(value)
+    elif isinstance(value, list):
+        return [ toUnicode(val, charset) for val in value ]
+    elif isinstance(value, tuple):
+        return tuple( [ toUnicode(val, charset) for val in value ] )
+    elif isinstance(value, dict):
+        for key, val in value.items():
+            value[key] = toUnicode(val, charset)
+        return value
+    else:
+        return value



More information about the CMF-checkins mailing list