[Zope] how to decode base64 in DTML?

Jaroslav Lukesh lukesh at seznam.cz
Thu May 4 16:22:25 EDT 2006


> From: Andreas Jung [mailto:lists at zopyx.com]
> > import cStringIO
> > import mimetools
> > import binascii
> > binascii.a2b_base64('YWxla2liYW5nb0B6dWcuY3o=\n')
> >
> > in commandline python works OK.
> >
> 
> Move such code inside a PythonScript..such code does not belong into
> DTML..
> it just bad style.

I was try this PythonScript (parameter: xemail):

import cStringIO
import mimetools
from Products.PythonScripts.Utility import allow_module
allow_module("base64")

xe=xemail + '=\n'
print xe.decode('base64')
return printed

... but it give me import error (bottom of that page).

So I try to write External method. Many rewrites, many tries, here are
working one - note that allow_module does not work:


import binascii
def preved64(xemail):
    xe=xemail + '=\n'
    return binascii.a2b_base64(xe)


Using: <dtml-var "externalmethodname('kjsdjhf_base64_lkskd')">

Great thanks to all!!!

JL.


----------------------------------------

  <P><STRONG>ImportError</STRONG></P>
  
  Sorry, a site error occurred.<p>
<!--
Traceback (innermost last):
  File D:\zope\251\lib\python\ZPublisher\Publish.py, line 150, in
publish_module
  File D:\zope\251\lib\python\ZPublisher\Publish.py, line 114, in publish
  File D:\zope\251\lib\python\Zope\__init__.py, line 159, in
zpublisher_exception_hook
    (Object: zzzkusebni)
  File D:\zope\251\lib\python\ZPublisher\Publish.py, line 98, in publish
  File D:\zope\251\lib\python\ZPublisher\mapply.py, line 88, in mapply
    (Object: skript)
  File D:\zope\251\lib\python\ZPublisher\Publish.py, line 39, in call_object
    (Object: skript)
  File D:\zope\251\lib\python\Shared\DC\Scripts\Bindings.py, line 252, in
__call__
    (Object: skript)
  File D:\zope\251\lib\python\Shared\DC\Scripts\Bindings.py, line 283, in
_bindAndExec
    (Object: skript)
  File D:\zope\251\lib\python\Products\PythonScripts\PythonScript.py, line
302, in _exec
    (Object: skript)
    (Info: ({'script': &lt;PythonScript instance at 02A97E50&gt;, 'context':
&lt;Folder instance at 0295ADA0&gt;, 'container': &lt;Folder instance at
0295ADA0&gt;, 'traverse_subpath': []}, ('YWxla2liYW5nb0B6dWcuY3o',), {},
None))
  File Script (Python), line 19, in skript
  File D:\zope\251\lib\python\AccessControl\ZopeGuards.py, line 151, in
guarded_import
ImportError: import of &quot;Products.PythonScripts.Utility&quot; is
unauthorized



More information about the Zope mailing list