[Zodb-checkins] CVS: Zope3/lib/python/ZODB - BaseStorage.py:1.15.10.2 DB.py:1.34.4.2 TimeStamp.c:1.8.4.2 fsrecover.py:1.2.4.1
Jeremy Hylton
jeremy@zope.com
Sat, 1 Dec 2001 23:25:24 -0500
Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv7055
Modified Files:
Tag: Zope-3x-branch
BaseStorage.py DB.py TimeStamp.c fsrecover.py
Log Message:
Refactor ZODB TimeStamp implementation.
Most of the changes are cosmetic. The TimeStamp type uses some of the
new idioms of Python 2.2:
- methods use METH_O and METH_NOARGS instead of METH_VARARGS
- use PyObject_GenericGetAttr
- provide separate C constructor functions
TimeStamp_FromString() and TimeStamp_FromDate()
Use the new constructors in TimeStamp_laterThan(), which fixes a bug
in the previous version of the code. It called the type object
directly, as was the style with ExtensionClass classes. It seems
fairly involved to write a callable type, so I decided not to. (To
make it callable it must support at least the undocumented tp_new).
Non-cosmetic changes:
- Remove repr() and str() methods on TimeStamps. Use raw() method
instead of repr().
- The FromDate() constructor checks the validity of its input.
Other ZODB modules: track API change from `ts` to ts.raw().
=== Zope3/lib/python/ZODB/BaseStorage.py 1.15.10.1 => 1.15.10.2 ===
t=time.time()
t=self._ts=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
- self._serial=`t`
+ self._serial=t.raw()
if base is None: self._oid='\0\0\0\0\0\0\0\0'
else: self._oid=base._oid
@@ -191,7 +191,7 @@
t=time.time()
t=apply(TimeStamp,(time.gmtime(t)[:5]+(t%60,)))
self._ts=t=t.laterThan(self._ts)
- self._serial=`t`
+ self._serial=t.raw()
else:
self._ts=TimeStamp(tid)
self._serial=tid
@@ -285,7 +285,7 @@
if ok: print ('Time stamps out of order %s, %s' % (_ts, t))
ok=0
_ts=t.laterThan(_ts)
- tid=`_ts`
+ tid=_ts.raw()
else:
_ts = t
if not ok:
=== Zope3/lib/python/ZODB/DB.py 1.34.4.1 => 1.34.4.2 ===
self._storage=storage
storage.registerDB(self, None)
- if not hasattr(storage,'tpc_vote'): storage.tpc_vote=lambda *args: None
- try: storage.load('\0\0\0\0\0\0\0\0','')
- except:
+ if not hasattr(storage,'tpc_vote'):
+ storage.tpc_vote=lambda *args: None
+ try:
+ storage.load('\0\0\0\0\0\0\0\0','')
+ except KeyError:
+ # Create the database's root in the storage if it doesn't exist
from Persistence import PersistentMapping
- file=cStringIO.StringIO()
- p=cPickle.Pickler(file,1)
- p.dump((PersistentMapping,None))
- p.dump({'_container': {}})
- t=Transaction()
- t.description='initial database creation'
+ root = PersistentMapping()
+ # Manually create a pickle for the root to put in the storage.
+ # The pickle must be in the special ZODB format.
+ file = cStringIO.StringIO()
+ p = cPickle.Pickler(file, 1)
+ p.dump((root.__class__, None))
+ p.dump(root.__getstate__())
+ t = Transaction()
+ t.description = 'initial database creation'
storage.tpc_begin(t)
storage.store('\0\0\0\0\0\0\0\0', None, file.getvalue(), '', t)
storage.tpc_vote(t)
=== Zope3/lib/python/ZODB/TimeStamp.c 1.8.4.1 => 1.8.4.2 === (671/771 lines abridged)
+
+ Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
- Zope Public License (ZPL) Version 1.0
- -------------------------------------
-
- Copyright (c) Digital Creations. All rights reserved.
-
- This license has been certified as Open Source(tm).
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are
- met:
-
- 1. Redistributions in source code must retain the above copyright
- notice, this list of conditions, and the following disclaimer.
-
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions, and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-
- 3. Digital Creations requests that attribution be given to Zope
- in any manner possible. Zope includes a "Powered by Zope"
- button that is installed by default. While it is not a license
- violation to remove this button, it is requested that the
- attribution remain. A significant investment has been put
- into Zope, and this effort will continue if the Zope community
- continues to grow. This is one way to assure that growth.
-
- 4. All advertising materials and documentation mentioning
- features derived from or use of this software must display
- the following acknowledgement:
-
- "This product includes software developed by Digital Creations
- for use in the Z Object Publishing Environment
- (http://www.zope.org/)."
-
- In the event that the product being advertised includes an
- intact Zope distribution (with copyright and license included)
- then this clause is waived.
-
- 5. Names associated with Zope or Digital Creations must not be used to
- endorse or promote products derived from this software without
- prior written permission from Digital Creations.
-
- 6. Modified redistributions of any form whatsoever must retain
- the following acknowledgment:
-
- "This product includes software developed by Digital Creations
[-=- -=- -=- 671 lines omitted -=- -=- -=-]
- return self;
-}
-
-static struct PyMethodDef Module_Level__methods[] = {
- {"TimeStamp", (PyCFunction)newTimeStamp, METH_VARARGS, ""},
- {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
-};
void
initTimeStamp(void)
{
- PyObject *m, *d, *s;
- char *rev="$Revision$";
-
- if (TimeStamp_init_gmoff() < 0) return;
-
- /* Create the module and add the functions */
- m = Py_InitModule4("TimeStamp", Module_Level__methods,
- TimeStamp_module_documentation,
- (PyObject*)NULL,PYTHON_API_VERSION);
-
- /* Add some symbolic constants to the module */
- d = PyModule_GetDict(m);
-
- TimeStampType.ob_type=&PyType_Type;
-
- PyDict_SetItemString(d,"TimeStampType", OBJECT(&TimeStampType));
+ PyObject *m;
- s = PyString_FromString("TimeStamp.error");
- PyDict_SetItemString(d, "error", s);
- Py_XDECREF(s);
+ if (TimeStamp_init_gmoff() < 0)
+ return;
- s = PyString_FromStringAndSize(rev + 11, strlen(rev + 11) - 2);
- PyDict_SetItemString(d, "__version__", s);
- Py_XDECREF(s);
+ m = Py_InitModule4("TimeStamp", TimeStampModule_functions,
+ TimeStampModule_doc, NULL, PYTHON_API_VERSION);
+ if (m == NULL)
+ return;
- /* Check for errors */
- if (PyErr_Occurred())
- Py_FatalError("can't initialize module TimeStamp");
+ TimeStamp_type.ob_type = &PyType_Type;
+ TimeStamp_type.tp_getattro = PyObject_GenericGetAttr;
}
+
=== Zope3/lib/python/ZODB/fsrecover.py 1.2 => 1.2.4.1 ===
ok=0
_ts=t.laterThan(_ts)
- tid=`_ts`
+ tid=_ts.raw()
else:
_ts = t
if not ok: