Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-16 Thread [EMAIL PROTECTED]

Am 16.11.2006, 21:43 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:


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_FAST0 (dt)
  6 LOAD_CONST   1 ('strftime')
  9 CALL_FUNCTION2
 12 LOAD_CONST   2 ('%d.%m.%Y')
 15 CALL_FUNCTION1
 18 RETURN_VALUE
 19 LOAD_CONST   0 (None)
 22 RETURN_VALUE
I am using Zope 2.8.1 with Python 2.4.1.


Interesting - in my script there is actually no import just a formatting  
statement for something that is subsequently passed to an external method  
to generate a PDF but is the same error I get when using datetime types.  
The interesting thing is that allow_type explicitly says that extension  
types like datetime will not work. I have used "allow_type" in a generic  
"Tools" script so that I can use in scripts or PageTemplates (which is  
where it should be allowed to be used). I will give your script a go and  
see how that works.


Thanks very much for your help and your profound understanding of the  
internals of Zope.


Charlie
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-16 Thread Dieter Maurer
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_FAST0 (dt)
  6 LOAD_CONST   1 ('strftime')
  9 CALL_FUNCTION2
 12 LOAD_CONST   2 ('%d.%m.%Y')
 15 CALL_FUNCTION1
 18 RETURN_VALUE
 19 LOAD_CONST   0 (None)
 22 RETURN_VALUE



I am using Zope 2.8.1 with Python 2.4.1.



-- 
Dieter
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-15 Thread Charlie Clark

Am 15.11.2006, 21:01 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:


  Module None, line 31, in generate
   - 
   - Line 31
  Module AccessControl.ZopeGuards, line 284, in guarded_import
ImportError: import of "__doc__" from "time" is unauthorized. You are  
not

allowed to access '__doc__' in this context

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.


Charlie

--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-15 Thread Dieter Maurer
Charlie Clark wrote at 2006-11-15 20:15 +0100:
> ..
>>> import datetime
>>>
>>> allow_type(datetime.datetime)
>>>
>>> do work but
>>>
>>> calling strftime() on a datetime object throws an import error
>>>
>>> Error Type: ImportError
>>> Error Value: import of "__doc__" from "time" is unauthorized. You are  
>>> not
>>> allowed to access '__doc__' in this context
> ...
>   Module None, line 31, in generate
>- 
>- Line 31
>   Module AccessControl.ZopeGuards, line 284, in guarded_import
>ImportError: import of "__doc__" from "time" is unauthorized. You are not  
>allowed to access '__doc__' in this context

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.



-- 
Dieter
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-15 Thread Charlie Clark

Am 06.11.2006, 23:12 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:


Charlie Clark wrote at 2006-10-24 22:43 +0200:

Am 24.10.2006, 22:26 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:

It does, but you need to use "allowType"...


Thanks for that.

import datetime

allow_type(datetime.datetime)

do work but

calling strftime() on a datetime object throws an import error

Error Type: ImportError
Error Value: import of "__doc__" from "time" is unauthorized. You are  
not

allowed to access '__doc__' in this context

Is this correct?

You know that you must always (!) provide full error information.
This includes a traceback (beside "Error Type" and "Error Value".


Apologies. Just had this come up again. Now with the full traceback:

Traceback (innermost last):
  Module ZPublisher.Publish, line 115, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 41, in call_object
  Module Shared.DC.Scripts.Bindings, line 311, in __call__
  Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 325, in _exec
  Module None, line 6, in process_bank
   - 
   - Line 6
  Module Shared.DC.Scripts.Bindings, line 311, in __call__
  Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 325, in _exec
  Module None, line 26, in set_bank
   - 
   - Line 26
  Module Shared.DC.Scripts.Bindings, line 311, in __call__
  Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 325, in _exec
  Module None, line 7, in premium
   - 
   - Line 7
  Module Shared.DC.Scripts.Bindings, line 311, in __call__
  Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 325, in _exec
  Module None, line 15, in printBill
   - 
   - Line 15
  Module Shared.DC.Scripts.Bindings, line 311, in __call__
  Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 325, in _exec
  Module None, line 31, in generate
   - 
   - Line 31
  Module AccessControl.ZopeGuards, line 284, in guarded_import
ImportError: import of "__doc__" from "time" is unauthorized. You are not  
allowed to access '__doc__' in this context


All I am doing is calling strftime() on a datetime object.

Charlie


--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-11-06 Thread Dieter Maurer
Charlie Clark wrote at 2006-10-24 22:43 +0200:
>Am 24.10.2006, 22:26 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:
>> It does, but you need to use "allowType"...
>
>Thanks for that.
>
>import datetime
>
>allow_type(datetime.datetime)
>
>do work but
>
>calling strftime() on a datetime object throws an import error
>
>Error Type: ImportError
>Error Value: import of "__doc__" from "time" is unauthorized. You are not  
>allowed to access '__doc__' in this context
>
>Is this correct?

You know that you must always (!) provide full error information.
This includes a traceback (beside "Error Type" and "Error Value".



-- 
Dieter
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-24 Thread Charlie Clark

Am 24.10.2006, 22:26 Uhr, schrieb Dieter Maurer <[EMAIL PROTECTED]>:


Charlie Clark wrote at 2006-10-23 16:03 +0200:

...
ah, the problem seems that Python datetime returns extension types and  
not

classes and Zope's security does not work with extension types!

It does, but you need to use "allowType"...


Thanks for that.

import datetime

allow_type(datetime.datetime)

do work but

calling strftime() on a datetime object throws an import error

Error Type: ImportError
Error Value: import of "__doc__" from "time" is unauthorized. You are not  
allowed to access '__doc__' in this context


Is this correct?

This is the same error thrown when using a wrapper class that uses  
getattr(datime_object, method_name) instead of overwriting the methods.


--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-24 Thread Dieter Maurer
Charlie Clark wrote at 2006-10-23 16:03 +0200:
> ...
>ah, the problem seems that Python datetime returns extension types and not  
>classes and Zope's security does not work with extension types!

It does, but you need to use "allowType"...



-- 
Dieter
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-23 Thread Charlie Clark

Am 23.10.2006, 15:13 Uhr, schrieb Charlie Clark <[EMAIL PROTECTED]>:


I  still have the same problem:
 import mx.DateTime, datetime
 d1 = mx.DateTime.DateTime(2006, 10, 22)
print d1
print d1.strftime("%Y.%m.%d")
 d2 = datetime.datetime(2006, 10, 22)
print d2
print d2.strftime("%Y.%m.%d")
 return printed
 strftime() works find with the mx.DateTime object but not with the  
Python datetime object. Is an additional security declaration required?


ah, the problem seems that Python datetime returns extension types and not  
classes and Zope's security does not work with extension types!


Charlie

--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-23 Thread Charlie Clark

Am 23.10.2006, 14:38 Uhr, schrieb Charlie Clark <[EMAIL PROTECTED]>:


Am 23.10.2006, 14:36 Uhr, schrieb Andreas Jung <[EMAIL PROTECTED]>:
  -> lib/python/Products/PythonScripts/README.txt
 Exactly the same mechanism? I'll give it a try.


I  still have the same problem:

import mx.DateTime, datetime

d1 = mx.DateTime.DateTime(2006, 10, 22)
print d1
print d1.strftime("%Y.%m.%d")

d2 = datetime.datetime(2006, 10, 22)
print d2
print d2.strftime("%Y.%m.%d")

return printed

strftime() works find with the mx.DateTime object but not with the Python  
datetime object. Is an additional security declaration required?


Charlie
--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


Re: [ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-23 Thread Charlie Clark

Am 23.10.2006, 14:36 Uhr, schrieb Andreas Jung <[EMAIL PROTECTED]>:



-> lib/python/Products/PythonScripts/README.txt


Exactly the same mechanism? I'll give it a try.

Charlie

--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt


[ZPT] Using alternatives to Zope's DateTime module in PageTemplates

2006-10-23 Thread Charlie Clark

Hi,

this is probably a no brainer but I haven't found a solution to it yet. Is  
there a simple way to enable Python modules for use in PageTemplates as is  
the case with PythonScripts? ie. I would like to be able to replace  
DateTime instances with mxDateTime instances applying formatting  
strftime('%d.%m.%Y') currently throws a security error as neither  
mxDateTime nor even Python's own datetime methods are allowed by default  
in PageTemplates.


Thanks

Charlie

--
Charlie Clark
eGenix.com

Professional Python Services directly from the Source

Python/Zope Consulting and Support ...http://www.egenix.com/
mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/

Try mxODBC.Zope.DA for Windows, Mac OS, Linux, Solaris, FreeBSD for free!
___
ZPT mailing list
ZPT@zope.org
http://mail.zope.org/mailman/listinfo/zpt