[ZPT] Using alternatives to Zope's DateTime module in
PageTemplates
Dieter Maurer
dieter at handshake.de
Thu Nov 16 15:43:41 EST 2006
Charlie Clark wrote at 2006-11-15 21:07 +0100:
> ...
>> What code do you see in line 31 of "psytec/scripts/generate".
>> I expect an "import time" there and would be really surprised
>> when it would contain "someDateTimeObject.strftime(...)".
>> If I am wrong, then the "RestrictedPython" compiler would
>> probably generate wrong code.
>
>Why are you surprised that I am formatting a database result?
>
>result.create_date.strftime('%d.%m.%Y') # line 31
>
>This has been cast by psycopg to a Python datetime object which I have
>added as an allowed type.
I am not surprised that you are formatting a database result.
I am surprised that in the byte code there is an "import time"
(or an import at all).
I tried to reproduce your problem and failed:
bin/zopectl debug
>>> from datetime import datetime
>>> from AccessControl import allow_type
>>> allow_type(datetime)
>>> from Products.PythonScripts.PythonScript import PythonScript
>>> ps=PythonScript('t')
>>> ps.write('''##parameters=dt
... return dt.strftime('%d.%m.%Y')
... ''')
>>> dt=datetime(2006,12,1,20,0,0)
>>> ps.__of__(app)(dt)
'01.12.2006'
And this is the Python Script's code:
>>> f=ps._v_f
>>> from dis import dis
>>> dis(f.func_code)
1 0 LOAD_GLOBAL 0 (_getattr_)
3 LOAD_FAST 0 (dt)
6 LOAD_CONST 1 ('strftime')
9 CALL_FUNCTION 2
12 LOAD_CONST 2 ('%d.%m.%Y')
15 CALL_FUNCTION 1
18 RETURN_VALUE
19 LOAD_CONST 0 (None)
22 RETURN_VALUE
I am using Zope 2.8.1 with Python 2.4.1.
--
Dieter
More information about the ZPT
mailing list