[GeneralDiscussion] applied to unstable: fix LOG macro to pass tests

[email protected] (unstable-repo)
Newsgroups gmane.comp.web.zope.zwiki
Message-ID <20080501194722.CE00F465C48__4255.57300118289$1209671371$gmane$org@mail.joyful.com>
Thu May  1 12:45:24 PDT 2008  Simon Michael <[email protected]>
  * fix LOG macro to pass tests
  toencoded & tounicode are now available as functions, and LOG now encodes to utf8.
diff -rN -u old-ZWiki-unstable/Utils.py new-ZWiki-unstable/Utils.py
--- old-ZWiki-unstable/Utils.py	2008-05-01 12:47:22.000000000 -0700
+++ new-ZWiki-unstable/Utils.py	2008-05-01 12:47:22.000000000 -0700
@@ -577,15 +577,25 @@
         """Safely convert a unicode string to an encoded ordinary string.
         The wiki's default encoding is used, unless overridden.
         """
-        if isunicode(s): return s.encode(enc or self.encoding())
-        else:            return s
+        return toencoded(s,enc or self.encoding())
 
     def tounicode(self,s,enc=None):
         """Safely convert an encoded ordinary string to a unicode string.
         The wiki's default encoding is used, unless overridden.
         """
-        if isunicode(s): return s
-        else:            return s.decode(enc or self.encoding())
+        return tounicode(s,enc or self.encoding())
+
+def toencoded(s,enc='utf8'):
+    """Safely convert a unicode string to an encoded ordinary string.
+    UTF8 is used by default."""
+    if isunicode(s): return s.encode(enc)
+    else:            return s
+
+def tounicode(s,enc='utf8'):
+    """Safely convert an encoded ordinary string to a unicode string.
+    UTF8 is used by default."""
+    if isunicode(s): return s
+    else:            return s.decode(enc)
 
 
 InitializeClass(PageUtils)
@@ -595,7 +605,7 @@
 
 #logging
 def STDERR(*args):  sys.stderr.write(' '.join(map(str,args)) + '\n')
-def LOG(severity,*args): zLOG.LOG('ZWiki',severity,' '.join(map(str,*args)))
+def LOG(severity,*args): zLOG.LOG('ZWiki',severity,' '.join(map(toencoded,*args)))
 def TRACE(*args):   LOG(zLOG.TRACE,  args)
 def DEBUG(*args):   LOG(zLOG.DEBUG,  args)
 def BLATHER(*args): LOG(zLOG.BLATHER,args)

--
forwarded from http://zwiki.org/GeneralDiscussion#[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.