[Zope3-dev] datetime module

Guido van Rossum guido@python.org
Thu, 07 Nov 2002 08:36:37 -0500


> I'm trying to use datetime module in a Zope3 project.  There are at least
> two problems with that module:
> 
> - date/time objects cannot be pickled, betcause datetime.basetime
>   defines an empty __slots__ but doesn't define __getstate__.  For all
>   __slots__ using objects Python provides a default 'bozo' __getstate__
>   which throws a TypeError ("a class that defines __slots__ without
>   defining __getstate__ cannot be pickled").
> 
>   Adding a simple
> 
>     def __getstate__(self):
>         return self.__dict__
> 
>   to datetime.basetime solves this problem.  Is this the right fix?
>   Should I commit it to Zope3 CVS?

I think it's better to tip out the __slots__; I see no need for it.
(But do run the datetime test suite before committing.)

In any case, the datetime type will eventually (before Python 2.3 is
released) be converted to a C object, and then it will be pickled
differently -- so beware that a database containing a datetime object
will not persist very well.  That's true of all of Zope 3, though.

> - date/time objects are inaccessible from untrusted code (e.g. you
>   cannot do a somedateobject.isoformat() from a page template).
>   Should there be appropriate security declarations somewhere in the
>   configure.zcml forest, or should these date/time objects be kept
>   unwrapped like objects of Python builtin types?

I think so.  Jim?

--Guido van Rossum (home page: http://www.python.org/~guido/)