[Patches] [ python-Patches-1578643 ] various datetime methods fail in restricted mode
SourceForge.net
noreply at sourceforge.net
Tue Mar 6 19:39:48 CET 2007
Patches item #1578643, was opened at 2006-10-17 06:04
Message generated for change (Comment added) made by zseil
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1578643&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.6
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: lplatypus (ldeller)
Assigned to: Nobody/Anonymous (nobody)
Summary: various datetime methods fail in restricted mode
Initial Comment:
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.
----------------------------------------------------------------------
Comment By: Žiga Seilnacht (zseil)
Date: 2007-03-06 19:39
Message:
Logged In: YES
user_id=1326842
Originator: NO
I don't think that this is a good solution; datetime
is not the only module that does an import in such a
way (even some parts of typeobject.c are doing imports).
Note that some of the functions in time module that
datetime is calling are actually implemented in Python
and are also imported.
Your patch also introduces a memory leak (the time module
is never decrefed) and is missing tests.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1578643&group_id=5470
More information about the Patches
mailing list