[Zope] Re: problem with input elements and unicode/utf-8

Andreas Jung lists at zopyx.com
Tue Feb 20 12:52:51 EST 2007



--On 20. Februar 2007 17:52:52 +0100 Andreas Jung <lists at zopyx.com> wrote:

>
>
> --On 19. Februar 2007 12:29:34 -0800 Jostein Leira <jleira at yahoo.com>
> wrote:
>
>>
>>   If it contains either of the tal-lines below I get the following error
>> message:
>>      <div tal:content="python:unicode('hei på deg','utf8')" />
>>
>

Please try out the following patch and report back:

Index: ZRPythonExpr.py
===================================================================
--- ZRPythonExpr.py     (revision 72721)
+++ ZRPythonExpr.py     (working copy)
@@ -29,7 +29,11 @@

     def __init__(self, name, expr, engine):
         self.text = text = expr.strip().replace('\n', ' ')
-        code, err, warn, use = compile_restricted_eval(text, str(self))
+        self.unicode = False
+        if isinstance(text, unicode):
+            text = text.encode('utf-8')
+            self.unicode = True
+        code, err, warn, use = compile_restricted_eval(text, 
self.__class__.__name__)
         if err:
             raise engine.getCompilerError()('Python expression error:\n%s' 
%
                                             '\n'.join(err))
@@ -40,7 +44,10 @@
         __traceback_info__ = self.text
         vars = self._bind_used_names(econtext, {})
         vars.update(self._globals)
-        return eval(self._code, vars, {})
+        result = eval(self._code, vars, {})
+        if self.unicode:
+            result = unicode(result, 'utf-8')
+        return result

 class _SecureModuleImporter:
     __allow_access_to_unprotected_subobjects__ = True


-aj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope/attachments/20070220/0495195b/attachment.bin


More information about the Zope mailing list