[Zope] how to decode base64 in DTML?
Tino Wildenhain
tino at wildenhain.de
Thu May 4 18:48:59 EDT 2006
Jaroslav Lukesh wrote:
>> 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')">
I'd just use "base64encodedstring".decode("base64")
since this is part of the unicode api (see "rot13"
and such for other excotic "encodings")
Regards
Tino
More information about the Zope
mailing list