[Zodb-checkins] CVS: Zope/lib/python/Persistence - PersistentList.py:1.4.2.1 PersistentMapping.py:1.21.2.1 _Persistence.c:1.1.4.1 __init__.py:1.4.118.1

Jim Fulton cvs-admin at zope.org
Tue Nov 25 15:18:06 EST 2003


Update of /cvs-repository/Zope/lib/python/Persistence
In directory cvs.zope.org:/tmp/cvs-serv24052/lib/python/Persistence

Modified Files:
      Tag: Zope-2_8-devel-branch
	__init__.py 
Added Files:
      Tag: Zope-2_8-devel-branch
	PersistentList.py PersistentMapping.py _Persistence.c 
Log Message:
merged everything but ZODB and ZEO from zodb33-devel-branch


=== Added File Zope/lib/python/Persistence/PersistentList.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

"""Python implementation of persistent list.

$Id: PersistentList.py,v 1.4.2.1 2003/11/25 20:17:32 jim Exp $"""

__version__='$Revision: 1.4.2.1 $'[11:-2]

import Persistence
import persistent
from persistent.list import PersistentList

if Persistence.Persistent is not persistent.Persistent:
    class PersistentList(Persistence.Persistent, PersistentList):
        """Legacy persistent list class
        
        This class mixes in ExtensionClass Base if it is present.
        
        Unless you actually want ExtensionClass semantics, use
        persistent.list.PersistentList instead.
        """


=== Added File Zope/lib/python/Persistence/PersistentMapping.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################

"""Python implementation of persistent base types

$Id: PersistentMapping.py,v 1.21.2.1 2003/11/25 20:17:32 jim Exp $"""

__version__='$Revision: 1.21.2.1 $'[11:-2]

import Persistence
import persistent
from persistent.mapping import PersistentMapping

if Persistence.Persistent is not persistent.Persistent:
    class PersistentMapping(Persistence.Persistent, PersistentMapping):
        """Legacy persistent mapping class
        
        This class mixes in ExtensionClass Base if it is present.
        
        Unless you actually want ExtensionClass semantics, use
        persistent.mapping.PersistentMapping instead.
        """


=== Added File Zope/lib/python/Persistence/_Persistence.c ===
/*

 Copyright (c) 2003 Zope Corporation and Contributors.
 All Rights Reserved.

 This software is subject to the provisions of the Zope Public License,
 Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 FOR A PARTICULAR PURPOSE.

*/
static char _Persistence_module_documentation[] = 
"Persistent ExtensionClass\n"
"\n"
"$Id: _Persistence.c,v 1.1.4.1 2003/11/25 20:17:32 jim Exp $\n"
;

#include "ExtensionClass.h"
#include "cPersistence.h"


/* convert_name() returns a new reference to a string name
   or sets an exception and returns NULL.
*/

static PyObject *
convert_name(PyObject *name)
{
#ifdef Py_USING_UNICODE
    /* The Unicode to string conversion is done here because the
       existing tp_setattro slots expect a string object as name
       and we wouldn't want to break those. */
    if (PyUnicode_Check(name)) {
	name = PyUnicode_AsEncodedString(name, NULL, NULL);
    }
    else
#endif
    if (!PyString_Check(name)) {
	PyErr_SetString(PyExc_TypeError, "attribute name must be a string");
	return NULL;
    } else
	Py_INCREF(name);
    return name;
}

/* Returns true if the object requires unghostification.

   There are several special attributes that we allow access to without
   requiring that the object be unghostified:
   __class__
   __del__
   __dict__
   __of__
   __setstate__
*/

static int
unghost_getattr(const char *s)
{
    if (*s++ != '_')
	return 1;
    if (*s == 'p') {
	s++;
	if (*s == '_')
	    return 0; /* _p_ */
	else
	    return 1;
    }
    else if (*s == '_') {
	s++;
	switch (*s) {
	case 'c':
	    return strcmp(s, "class__");
	case 'd':
	    s++;
	    if (!strcmp(s, "el__"))
		return 0; /* __del__ */
	    if (!strcmp(s, "ict__"))
		return 0; /* __dict__ */
	    return 1;
	case 'o':
	    return strcmp(s, "of__");
	case 's':
	    return strcmp(s, "setstate__");
	default:
	    return 1;
	}
    }
    return 1;
}

static PyObject *
P_getattr(cPersistentObject *self, PyObject *name)
{
  PyObject *v=NULL;
  char *s;

  name = convert_name(name);
  if (!name)
    return NULL;

  s = PyString_AS_STRING(name);

  if (*s != '_' || unghost_getattr(s)) 
    {
      if (PER_USE(self))
        {
          v = Py_FindAttr((PyObject*)self, name);
          PER_ALLOW_DEACTIVATION(self);
          PER_ACCESSED(self);
        }
    }
  else
    v = Py_FindAttr((PyObject*)self, name);

  Py_DECREF(name);

  return v;
}


static PyTypeObject Ptype = {
	PyObject_HEAD_INIT(NULL)
	/* ob_size           */ 0,
	/* tp_name           */ "Persistence.Persistent",
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        /* tp_getattro       */ (getattrofunc)P_getattr,
        0, 0,
        /* tp_flags          */ Py_TPFLAGS_DEFAULT
				| Py_TPFLAGS_BASETYPE ,
	/* tp_doc            */ "Persistent ExtensionClass",
};

static struct PyMethodDef _Persistence_methods[] = {
	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */
};

#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
#define PyMODINIT_FUNC void
#endif
PyMODINIT_FUNC
init_Persistence(void)
{
  PyObject *m;
        
  if (! ExtensionClassImported)
    return;

  cPersistenceCAPI = PyCObject_Import("persistent.cPersistence", "CAPI");
  if (cPersistenceCAPI == NULL)
    return;

  Ptype.tp_bases = Py_BuildValue("OO", cPersistenceCAPI->pertype, ECBaseType);
  if (Ptype.tp_bases == NULL)
    return;
  Ptype.tp_base = cPersistenceCAPI->pertype;
  
  Ptype.ob_type = ECExtensionClassType;
  if (PyType_Ready(&Ptype) < 0)
    return;
        
  /* Create the module and add the functions */
  m = Py_InitModule3("_Persistence", _Persistence_methods,
                     _Persistence_module_documentation);
  
  if (m == NULL)
    return;
  
  /* Add types: */
  if (PyModule_AddObject(m, "Persistent", (PyObject *)&Ptype) < 0)
    return;
}



=== Zope/lib/python/Persistence/__init__.py 1.4 => 1.4.118.1 ===
--- Zope/lib/python/Persistence/__init__.py:1.4	Wed Aug 14 17:43:18 2002
+++ Zope/lib/python/Persistence/__init__.py	Tue Nov 25 15:17:32 2003
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001, 2002, 2003 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -11,10 +11,38 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
-"""Provide access to Persistent and PersistentMapping
+"""Persistence and ExtensionClass combined
 
-This avoids dependency on the database package name.
-
-While obviously there is nothing in this module, the correct names are
-inserted by the __init__.py in ZODB, jumpstarting the process.
+$Id$
 """
+
+from persistent import PickleCache
+
+try:
+    from _Persistence import Persistent
+except:
+    from warnings import warn
+    warn("""Couldn't import the ExtensionClass-based base class
+
+    There are two possibilities:
+
+    1. You don't care about ExtensionClass. You are importing
+       Persistence because that's what you imported in the past.
+       In this case, you should really use the persistent package
+       instead:
+
+          >>> from persistent import Persistent
+          >>> from persistent.list import PersistentList
+          >>> from persistent.mapping import PersistentMapping
+
+    2. You want your classes to be ExtensionClasses. In this case,
+       you need to install the ExtensionClass package
+       separately. ExtensionClass is no-longer included with ZODB3.
+
+    """)
+
+    from persistent import Persistent
+
+Overridable = Persistent
+
+from PersistentMapping import PersistentMapping




More information about the Zodb-checkins mailing list