This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: various datetime methods fail in restricted mode
类型: behavior Stage: test needed
Components: Library (Lib) Versions: Python 2.6
process
状态: closed Resolution: out of date
Dependencies: 9079 后续:
分配给: belopolsky 抄送列表: belopolsky, eric.araujo, ldeller, zseil
优先级: low 关键字: patch

Created on 2006-10-17 04:04 by ldeller, last changed 2022-04-11 14:56 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
datetime-import.patch ldeller, 2006-10-17 04:04 patch to Modules/datetimemodule.c review
Messages (4)
msg51262 - (view) Author: lplatypus (ldeller) * 日期: 2006-10-17 04:04
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.
msg51263 - (view) Author: Ziga Seilnacht (zseil) * (Python committer) 日期: 2007-03-06 18:39
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.
msg107412 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) 日期: 2010-06-09 20:06
I would like to remove datetime module dependency on time module altogether.  For example getting timestamp as a float and later break it into sec/usec just to satisfy time module API looks rather inefficient.
msg108604 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) 日期: 2010-06-25 15:12
See issue9079.
历史
日期 用户 动作 参数
2022-04-11 14:56:20admin修改github: 44136
2012-08-23 04:19:35belopolsky修改状态: open -> closed
resolution: out of date
2010-06-25 15:12:40belopolsky修改dependencies: + Make gettimeofday available in time module
消息: + msg108604
2010-06-09 20:06:19belopolsky修改assignee: belopolsky

消息: + msg107412
抄送: + belopolsky
2010-02-16 04:29:15eric.araujo修改抄送: + eric.araujo
2009-03-30 07:20:34ajaksu2修改优先级: normal -> low
type: behavior
stage: test needed
2006-10-17 04:04:01ldeller创建