Message51262
The following methods fail in restricted execution
mode, because they try to import the time module:
datetime.datetime.strftime
datetime.datetime.strptime
datetime.datetime.timetuple
datetime.datetime.utctimetuple
datetime.time.time
datetime.date.timetuple
Example of the problem:
>>> import datetime
>>> script = 'print dt; print dt.strftime("x")'
>>> exec script in {'dt':datetime.datetime(2006,1,1)}
2006-01-01 00:00:00
x
>>> exec script in
{'dt':datetime.datetime(2006,1,1),'__builtins__':{}}
2006-01-01 00:00:00
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<string>", line 1, in ?
KeyError: '__import__'
The attached adjusts the datetime module so that the
time module is imported in the initialisation of the
datetime module. This allows these methods to be used
in restricted execution mode.
If the time module is not available, then the datetime
module will not be importable either after this patch.
Previously the datetime module would be importable but
the methods listed above would raise exceptions. If
this situation is worth considering then I can adjust
the patch accordingly. |
|
Date |
User |
Action |
Args |
2007-08-23 15:55:06 | admin | link | issue1578643 messages |
2007-08-23 15:55:06 | admin | create | |
|