Persistence 5.2__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- Persistence/_Persistence.c +193 -0
- Persistence/_Persistence.cp314-win_amd64.pyd +0 -0
- Persistence/__init__.py +62 -0
- Persistence/mapping.py +49 -0
- Persistence/tests/__init__.py +0 -0
- Persistence/tests/test_ec.py +502 -0
- Persistence/tests/test_mapping.py +35 -0
- Persistence/tests/test_persistent.py +246 -0
- persistence-5.2.dist-info/METADATA +200 -0
- persistence-5.2.dist-info/RECORD +13 -0
- persistence-5.2.dist-info/WHEEL +5 -0
- persistence-5.2.dist-info/licenses/LICENSE.txt +44 -0
- persistence-5.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
+
All Rights Reserved.
|
|
5
|
+
|
|
6
|
+
This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
FOR A PARTICULAR PURPOSE.
|
|
12
|
+
|
|
13
|
+
*/
|
|
14
|
+
static char _Persistence_module_documentation[] =
|
|
15
|
+
"Persistent ExtensionClass\n"
|
|
16
|
+
;
|
|
17
|
+
|
|
18
|
+
#include "ExtensionClass/ExtensionClass.h"
|
|
19
|
+
#include "ExtensionClass/_compat.h"
|
|
20
|
+
#include "persistent/cPersistence.h"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/* convert_name() returns a new reference to a string name
|
|
24
|
+
or sets an exception and returns NULL.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
static PyObject *
|
|
28
|
+
convert_name(PyObject *name)
|
|
29
|
+
{
|
|
30
|
+
#ifdef Py_USING_UNICODE
|
|
31
|
+
/* The Unicode to string conversion is done here because the
|
|
32
|
+
existing tp_setattro slots expect a string object as name
|
|
33
|
+
and we wouldn't want to break those. */
|
|
34
|
+
if (PyUnicode_Check(name)) {
|
|
35
|
+
name = PyUnicode_AsEncodedString(name, NULL, NULL);
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
#endif
|
|
39
|
+
if (!NATIVE_CHECK(name)) {
|
|
40
|
+
PyErr_SetString(PyExc_TypeError, "attribute name must be a string");
|
|
41
|
+
return NULL;
|
|
42
|
+
} else
|
|
43
|
+
Py_INCREF(name);
|
|
44
|
+
return name;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Returns true if the object requires unghostification.
|
|
48
|
+
|
|
49
|
+
There are several special attributes that we allow access to without
|
|
50
|
+
requiring that the object be unghostified:
|
|
51
|
+
__class__
|
|
52
|
+
__del__
|
|
53
|
+
__dict__
|
|
54
|
+
__of__
|
|
55
|
+
__setstate__
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
static int
|
|
59
|
+
unghost_getattr(const char *s)
|
|
60
|
+
{
|
|
61
|
+
if (*s++ != '_')
|
|
62
|
+
return 1;
|
|
63
|
+
if (*s == 'p') {
|
|
64
|
+
s++;
|
|
65
|
+
if (*s == '_')
|
|
66
|
+
return 0; /* _p_ */
|
|
67
|
+
else
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
else if (*s == '_') {
|
|
71
|
+
s++;
|
|
72
|
+
switch (*s) {
|
|
73
|
+
case 'c':
|
|
74
|
+
return strcmp(s, "class__");
|
|
75
|
+
case 'd':
|
|
76
|
+
s++;
|
|
77
|
+
if (!strcmp(s, "el__"))
|
|
78
|
+
return 0; /* __del__ */
|
|
79
|
+
if (!strcmp(s, "ict__"))
|
|
80
|
+
return 0; /* __dict__ */
|
|
81
|
+
return 1;
|
|
82
|
+
case 'o':
|
|
83
|
+
return strcmp(s, "of__");
|
|
84
|
+
case 's':
|
|
85
|
+
return strcmp(s, "setstate__");
|
|
86
|
+
default:
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static PyObject *
|
|
94
|
+
P_getattr(cPersistentObject *self, PyObject *name)
|
|
95
|
+
{
|
|
96
|
+
PyObject *v=NULL;
|
|
97
|
+
|
|
98
|
+
char *s;
|
|
99
|
+
|
|
100
|
+
PyObject* as_bytes = convert_name(name);
|
|
101
|
+
if (!as_bytes)
|
|
102
|
+
return NULL;
|
|
103
|
+
|
|
104
|
+
s = PyBytes_AS_STRING(as_bytes);
|
|
105
|
+
|
|
106
|
+
if (s[0] != '_' || unghost_getattr(s))
|
|
107
|
+
{
|
|
108
|
+
if (PER_USE(self))
|
|
109
|
+
{
|
|
110
|
+
v = Py_FindAttr((PyObject*)self, name);
|
|
111
|
+
PER_ALLOW_DEACTIVATION(self);
|
|
112
|
+
PER_ACCESSED(self);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else
|
|
116
|
+
v = Py_FindAttr((PyObject*)self, name);
|
|
117
|
+
|
|
118
|
+
Py_DECREF(as_bytes);
|
|
119
|
+
|
|
120
|
+
return v;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
static PyTypeObject Ptype = {
|
|
125
|
+
PyVarObject_HEAD_INIT(NULL, 0)
|
|
126
|
+
"Persistence.Persistent", /* tp_name */
|
|
127
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
128
|
+
(getattrofunc)P_getattr, /* tp_getattro */
|
|
129
|
+
0, /* tp_setattro */
|
|
130
|
+
0, /* tp_as_buffer */
|
|
131
|
+
Py_TPFLAGS_DEFAULT |
|
|
132
|
+
Py_TPFLAGS_BASETYPE |
|
|
133
|
+
Py_TPFLAGS_HAVE_VERSION_TAG, /* tp_flags */
|
|
134
|
+
"Persistent ExtensionClass", /* tp_doc */
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
static struct PyMethodDef _Persistence_methods[] = {
|
|
138
|
+
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
static struct PyModuleDef moduledef =
|
|
142
|
+
{
|
|
143
|
+
PyModuleDef_HEAD_INIT,
|
|
144
|
+
"_Persistence", /* m_name */
|
|
145
|
+
_Persistence_module_documentation, /* m_doc */
|
|
146
|
+
-1, /* m_size */
|
|
147
|
+
_Persistence_methods, /* m_methods */
|
|
148
|
+
NULL, /* m_reload */
|
|
149
|
+
NULL, /* m_traverse */
|
|
150
|
+
NULL, /* m_clear */
|
|
151
|
+
NULL, /* m_free */
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
static PyObject*
|
|
155
|
+
module_init(void)
|
|
156
|
+
{
|
|
157
|
+
PyObject *m;
|
|
158
|
+
|
|
159
|
+
if (! ExtensionClassImported)
|
|
160
|
+
return NULL;
|
|
161
|
+
|
|
162
|
+
cPersistenceCAPI = PyCapsule_Import("persistent.cPersistence.CAPI", 0);
|
|
163
|
+
if (cPersistenceCAPI == NULL)
|
|
164
|
+
return NULL;
|
|
165
|
+
|
|
166
|
+
Ptype.tp_bases = Py_BuildValue("OO", cPersistenceCAPI->pertype, ECBaseType);
|
|
167
|
+
if (Ptype.tp_bases == NULL)
|
|
168
|
+
return NULL;
|
|
169
|
+
Ptype.tp_base = cPersistenceCAPI->pertype;
|
|
170
|
+
Ptype.tp_basicsize = cPersistenceCAPI->pertype->tp_basicsize;
|
|
171
|
+
|
|
172
|
+
Py_SET_TYPE(&Ptype, ECExtensionClassType);
|
|
173
|
+
|
|
174
|
+
if (PyType_Ready(&Ptype) < 0)
|
|
175
|
+
return NULL;
|
|
176
|
+
|
|
177
|
+
/* Create the module and add the functions */
|
|
178
|
+
m = PyModule_Create(&moduledef);
|
|
179
|
+
|
|
180
|
+
if (m == NULL)
|
|
181
|
+
return NULL;
|
|
182
|
+
|
|
183
|
+
/* Add types: */
|
|
184
|
+
if (PyModule_AddObject(m, "Persistent", (PyObject *)&Ptype) < 0)
|
|
185
|
+
return NULL;
|
|
186
|
+
|
|
187
|
+
return m;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
PyMODINIT_FUNC PyInit__Persistence(void)
|
|
191
|
+
{
|
|
192
|
+
return module_init();
|
|
193
|
+
}
|
|
Binary file
|
Persistence/__init__.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
import os
|
|
15
|
+
import platform
|
|
16
|
+
|
|
17
|
+
import persistent
|
|
18
|
+
from ExtensionClass import Base
|
|
19
|
+
from ExtensionClass import Base_getattro
|
|
20
|
+
from persistent.persistence import _SPECIAL_NAMES
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
IS_PYPY = getattr(platform, 'python_implementation', lambda: None)() == 'PyPy'
|
|
24
|
+
IS_PURE = int(os.environ.get('PURE_PYTHON', '0'))
|
|
25
|
+
|
|
26
|
+
CAPI = not (IS_PYPY or IS_PURE)
|
|
27
|
+
if CAPI: # pragma: no cover
|
|
28
|
+
# Both of our dependencies need to have working C extensions
|
|
29
|
+
import persistent.cPersistence
|
|
30
|
+
from ExtensionClass import _ExtensionClass # NOQA
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class Persistent(persistent.Persistent, Base):
|
|
34
|
+
"""Legacy persistent class
|
|
35
|
+
|
|
36
|
+
This class mixes in :class:`ExtensionClass.Base` if it is present.
|
|
37
|
+
|
|
38
|
+
Unless you actually want ExtensionClass semantics, use
|
|
39
|
+
:class:`persistent.mapping.Persistent` instead.
|
|
40
|
+
"""
|
|
41
|
+
__slots__ = ()
|
|
42
|
+
|
|
43
|
+
def __getattribute__(self, name):
|
|
44
|
+
""" See IPersistent.
|
|
45
|
+
"""
|
|
46
|
+
oga = Base_getattro
|
|
47
|
+
if (not name.startswith('_p_') and
|
|
48
|
+
name not in _SPECIAL_NAMES):
|
|
49
|
+
if oga(self, '_Persistent__flags') is None:
|
|
50
|
+
oga(self, '_p_activate')()
|
|
51
|
+
oga(self, '_p_accessed')()
|
|
52
|
+
return oga(self, name)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if CAPI: # pragma: no cover
|
|
56
|
+
# Override the Python implementation with the C one
|
|
57
|
+
from Persistence._Persistence import Persistent # NOQA
|
|
58
|
+
|
|
59
|
+
Overridable = Persistent
|
|
60
|
+
|
|
61
|
+
# API Import after setting up the base class
|
|
62
|
+
from Persistence.mapping import PersistentMapping # NOQA
|
Persistence/mapping.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2001, 2002 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
|
|
15
|
+
from abc import ABCMeta
|
|
16
|
+
|
|
17
|
+
from ExtensionClass import ExtensionClass
|
|
18
|
+
from persistent.mapping import PersistentMapping as _BasePersistentMapping
|
|
19
|
+
|
|
20
|
+
from Persistence import Persistent
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class _Meta(ExtensionClass, ABCMeta):
|
|
24
|
+
# persistent.mapping is based on collections.UserDict,
|
|
25
|
+
# which has an ABCMeta class. Reconcile this with the
|
|
26
|
+
# ExtensionClass meta class, by ignoring the ABCMeta registration.
|
|
27
|
+
|
|
28
|
+
def __new__(cls, *args, **kw):
|
|
29
|
+
# Ignore ABCMeta.
|
|
30
|
+
return ExtensionClass.__new__(cls, *args, **kw)
|
|
31
|
+
|
|
32
|
+
__instancecheck__ = ExtensionClass.__instancecheck__
|
|
33
|
+
__subclasscheck__ = ExtensionClass.__subclasscheck__
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class PersistentMapping(Persistent, _BasePersistentMapping, metaclass=_Meta):
|
|
37
|
+
"""Legacy persistent mapping class
|
|
38
|
+
|
|
39
|
+
This class mixes in :class:`ExtensionClass.Base` if it is present.
|
|
40
|
+
|
|
41
|
+
Unless you actually want ExtensionClass semantics, use
|
|
42
|
+
:class:`persistent.mapping.PersistentMapping` instead.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __setstate__(self, state):
|
|
46
|
+
if 'data' not in state:
|
|
47
|
+
state['data'] = state['_container']
|
|
48
|
+
del state['_container']
|
|
49
|
+
self.__dict__.update(state)
|
|
File without changes
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
|
|
15
|
+
from doctest import DocTestSuite
|
|
16
|
+
|
|
17
|
+
from Persistence import Persistent
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def print_dict(d):
|
|
21
|
+
d = d.items()
|
|
22
|
+
print('{%s}' % (', '.join(
|
|
23
|
+
[(f'{k!r}: {v!r}') for (k, v) in sorted(d)]
|
|
24
|
+
)))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_basic():
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
>>> from ExtensionClass import Base
|
|
31
|
+
|
|
32
|
+
- Support for a class initialiser:
|
|
33
|
+
|
|
34
|
+
>>> class C(Persistent):
|
|
35
|
+
... def __class_init__(self):
|
|
36
|
+
... print('class init called')
|
|
37
|
+
... print(self.__name__)
|
|
38
|
+
... def bar(self):
|
|
39
|
+
... return 'bar called'
|
|
40
|
+
class init called
|
|
41
|
+
C
|
|
42
|
+
>>> c = C()
|
|
43
|
+
>>> int(c.__class__ is C)
|
|
44
|
+
1
|
|
45
|
+
>>> int(c.__class__ is type(c))
|
|
46
|
+
1
|
|
47
|
+
|
|
48
|
+
- Provide an inheritedAttribute method for looking up attributes in
|
|
49
|
+
base classes:
|
|
50
|
+
|
|
51
|
+
>>> class C2(C):
|
|
52
|
+
... def bar(*a):
|
|
53
|
+
... return C2.inheritedAttribute('bar')(*a), 42
|
|
54
|
+
class init called
|
|
55
|
+
C2
|
|
56
|
+
>>> o = C2()
|
|
57
|
+
>>> o.bar()
|
|
58
|
+
('bar called', 42)
|
|
59
|
+
|
|
60
|
+
This is for compatability with old code. New code should use super
|
|
61
|
+
instead.
|
|
62
|
+
|
|
63
|
+
The base class, Base, exists mainly to support the __of__ protocol.
|
|
64
|
+
The __of__ protocol is similar to __get__ except that __of__ is called
|
|
65
|
+
when an implementor is retrieved from an instance as well as from a
|
|
66
|
+
class:
|
|
67
|
+
|
|
68
|
+
>>> class O(Base):
|
|
69
|
+
... def __of__(*a):
|
|
70
|
+
... return a
|
|
71
|
+
|
|
72
|
+
>>> o1 = O()
|
|
73
|
+
>>> o2 = O()
|
|
74
|
+
>>> C.o1 = o1
|
|
75
|
+
>>> c.o2 = o2
|
|
76
|
+
>>> c.o1 == (o1, c)
|
|
77
|
+
1
|
|
78
|
+
>>> C.o1 == o1
|
|
79
|
+
1
|
|
80
|
+
>>> int(c.o2 == (o2, c))
|
|
81
|
+
1
|
|
82
|
+
|
|
83
|
+
We accomplish this by making a class that implements __of__ a
|
|
84
|
+
descriptor and treating all descriptor ExtensionClasses this way. That
|
|
85
|
+
is, if an extension class is a descriptor, it's __get__ method will be
|
|
86
|
+
called even when it is retrieved from an instance.
|
|
87
|
+
|
|
88
|
+
>>> class O(Base):
|
|
89
|
+
... def __get__(*a):
|
|
90
|
+
... return a
|
|
91
|
+
...
|
|
92
|
+
>>> o1 = O()
|
|
93
|
+
>>> o2 = O()
|
|
94
|
+
>>> C.o1 = o1
|
|
95
|
+
>>> c.o2 = o2
|
|
96
|
+
>>> int(c.o1 == (o1, c, type(c)))
|
|
97
|
+
1
|
|
98
|
+
>>> int(C.o1 == (o1, None, type(c)))
|
|
99
|
+
1
|
|
100
|
+
>>> int(c.o2 == (o2, c, type(c)))
|
|
101
|
+
1
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def test_mixing():
|
|
106
|
+
"""Test working with a classic class
|
|
107
|
+
|
|
108
|
+
>>> class Classic:
|
|
109
|
+
... def x(self):
|
|
110
|
+
... return 42
|
|
111
|
+
|
|
112
|
+
>>> class O(Persistent):
|
|
113
|
+
... def __of__(*a):
|
|
114
|
+
... return a
|
|
115
|
+
|
|
116
|
+
>>> class O2(Classic, O):
|
|
117
|
+
... def __of__(*a):
|
|
118
|
+
... return (O2.inheritedAttribute('__of__')(*a),
|
|
119
|
+
... O2.inheritedAttribute('x')(a[0]))
|
|
120
|
+
|
|
121
|
+
>>> class C(Persistent):
|
|
122
|
+
... def __class_init__(self):
|
|
123
|
+
... print('class init called')
|
|
124
|
+
... print(self.__name__)
|
|
125
|
+
... def bar(self):
|
|
126
|
+
... return 'bar called'
|
|
127
|
+
class init called
|
|
128
|
+
C
|
|
129
|
+
|
|
130
|
+
>>> c = C()
|
|
131
|
+
>>> o2 = O2()
|
|
132
|
+
>>> c.o2 = o2
|
|
133
|
+
>>> int(c.o2 == ((o2, c), 42))
|
|
134
|
+
1
|
|
135
|
+
|
|
136
|
+
Test working with a new style
|
|
137
|
+
|
|
138
|
+
>>> class Modern(object):
|
|
139
|
+
... def x(self):
|
|
140
|
+
... return 42
|
|
141
|
+
|
|
142
|
+
>>> class O2(Modern, O):
|
|
143
|
+
... def __of__(*a):
|
|
144
|
+
... return (O2.inheritedAttribute('__of__')(*a),
|
|
145
|
+
... O2.inheritedAttribute('x')(a[0]))
|
|
146
|
+
|
|
147
|
+
>>> o2 = O2()
|
|
148
|
+
>>> c.o2 = o2
|
|
149
|
+
>>> int(c.o2 == ((o2, c), 42))
|
|
150
|
+
1
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_class_creation_under_stress():
|
|
155
|
+
"""
|
|
156
|
+
>>> numbers = []
|
|
157
|
+
>>> for i in range(100):
|
|
158
|
+
... class B(Persistent):
|
|
159
|
+
... numbers.append(i)
|
|
160
|
+
>>> numbers == list(range(100))
|
|
161
|
+
True
|
|
162
|
+
|
|
163
|
+
>>> import gc
|
|
164
|
+
>>> x = gc.collect()
|
|
165
|
+
"""
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def proper_error_on_deleattr():
|
|
169
|
+
"""
|
|
170
|
+
Florent Guillaume wrote:
|
|
171
|
+
|
|
172
|
+
...
|
|
173
|
+
|
|
174
|
+
Excellent.
|
|
175
|
+
Will it also fix this particularity of ExtensionClass:
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
>>> class A(Persistent):
|
|
179
|
+
... def foo(self):
|
|
180
|
+
... self.gee
|
|
181
|
+
... def bar(self):
|
|
182
|
+
... del self.gee
|
|
183
|
+
|
|
184
|
+
>>> a=A()
|
|
185
|
+
>>> a.foo() # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
186
|
+
Traceback (most recent call last):
|
|
187
|
+
...
|
|
188
|
+
AttributeError: 'A' object has no attribute 'gee'
|
|
189
|
+
|
|
190
|
+
>>> a.bar() # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
191
|
+
Traceback (most recent call last):
|
|
192
|
+
...
|
|
193
|
+
AttributeError: 'A' object has no attribute 'gee'
|
|
194
|
+
|
|
195
|
+
I.e., the fact that KeyError is raised whereas a normal class would
|
|
196
|
+
raise AttributeError.
|
|
197
|
+
"""
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def test__basicnew__():
|
|
201
|
+
"""
|
|
202
|
+
>>> x = Simple.__basicnew__()
|
|
203
|
+
>>> x.__dict__
|
|
204
|
+
{}
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def cmpattrs(self, other, *attrs):
|
|
209
|
+
for attr in attrs:
|
|
210
|
+
if attr[:3] in ('_v_', '_p_'):
|
|
211
|
+
continue
|
|
212
|
+
c = getattr(self, attr, None) == getattr(other, attr, None)
|
|
213
|
+
if c:
|
|
214
|
+
return c
|
|
215
|
+
return 0
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
class Simple(Persistent):
|
|
219
|
+
def __init__(self, name, **kw):
|
|
220
|
+
self.__name__ = name
|
|
221
|
+
self.__dict__.update(kw)
|
|
222
|
+
self._v_favorite_color = 'blue'
|
|
223
|
+
self._p_foo = 'bar'
|
|
224
|
+
|
|
225
|
+
def __eq__(self, other):
|
|
226
|
+
return cmpattrs(self, other, '__class__', *(self.__dict__.keys()))
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_basic_pickling():
|
|
230
|
+
"""
|
|
231
|
+
>>> x = Simple('x', aaa=1, bbb='foo')
|
|
232
|
+
|
|
233
|
+
>>> print_dict(x.__getstate__())
|
|
234
|
+
{'__name__': 'x', 'aaa': 1, 'bbb': 'foo'}
|
|
235
|
+
|
|
236
|
+
>>> f, (c,), state = x.__reduce__()
|
|
237
|
+
>>> f.__name__
|
|
238
|
+
'__newobj__'
|
|
239
|
+
>>> f.__module__ in ('copyreg', 'copy_reg')
|
|
240
|
+
True
|
|
241
|
+
>>> c.__name__
|
|
242
|
+
'Simple'
|
|
243
|
+
|
|
244
|
+
>>> print_dict(state)
|
|
245
|
+
{'__name__': 'x', 'aaa': 1, 'bbb': 'foo'}
|
|
246
|
+
|
|
247
|
+
>>> import pickle
|
|
248
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
249
|
+
1
|
|
250
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
251
|
+
1
|
|
252
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
253
|
+
1
|
|
254
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
255
|
+
1
|
|
256
|
+
|
|
257
|
+
>>> x.__setstate__({'z': 1})
|
|
258
|
+
>>> x.__dict__
|
|
259
|
+
{'z': 1}
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
class Custom(Simple):
|
|
264
|
+
|
|
265
|
+
def __new__(cls, x, y):
|
|
266
|
+
r = Persistent.__new__(cls)
|
|
267
|
+
r.x, r.y = x, y
|
|
268
|
+
return r
|
|
269
|
+
|
|
270
|
+
def __init__(self, x, y):
|
|
271
|
+
self.a = 42
|
|
272
|
+
|
|
273
|
+
def __getnewargs__(self):
|
|
274
|
+
return self.x, self.y
|
|
275
|
+
|
|
276
|
+
def __getstate__(self):
|
|
277
|
+
return self.a
|
|
278
|
+
|
|
279
|
+
def __setstate__(self, a):
|
|
280
|
+
self.a = a
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def test_pickling_w_overrides():
|
|
284
|
+
"""
|
|
285
|
+
>>> x = Custom('x', 'y')
|
|
286
|
+
>>> x.a = 99
|
|
287
|
+
|
|
288
|
+
>>> (f, (c, ax, ay), a) = x.__reduce__()
|
|
289
|
+
>>> f.__name__
|
|
290
|
+
'__newobj__'
|
|
291
|
+
>>> f.__module__ in ('copy_reg', 'copyreg')
|
|
292
|
+
True
|
|
293
|
+
>>> c.__name__
|
|
294
|
+
'Custom'
|
|
295
|
+
>>> ax, ay, a
|
|
296
|
+
('x', 'y', 99)
|
|
297
|
+
|
|
298
|
+
>>> import pickle
|
|
299
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
300
|
+
1
|
|
301
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
302
|
+
1
|
|
303
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
304
|
+
1
|
|
305
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
306
|
+
1
|
|
307
|
+
"""
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class Slotted(Persistent):
|
|
311
|
+
__slots__ = 's1', 's2', '_p_splat', '_v_eek'
|
|
312
|
+
|
|
313
|
+
def __init__(self, s1, s2):
|
|
314
|
+
self.s1, self.s2 = s1, s2
|
|
315
|
+
self._v_eek = 1
|
|
316
|
+
self._p_splat = 2
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class SubSlotted(Slotted):
|
|
320
|
+
__slots__ = 's3', 's4'
|
|
321
|
+
|
|
322
|
+
def __init__(self, s1, s2, s3):
|
|
323
|
+
Slotted.__init__(self, s1, s2)
|
|
324
|
+
self.s3 = s3
|
|
325
|
+
|
|
326
|
+
def __eq__(self, other):
|
|
327
|
+
return cmpattrs(self, other, '__class__', 's1', 's2', 's3', 's4')
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
def test_pickling_w_slots_only():
|
|
331
|
+
"""
|
|
332
|
+
>>> x = SubSlotted('x', 'y', 'z')
|
|
333
|
+
|
|
334
|
+
>>> d, s = x.__getstate__()
|
|
335
|
+
>>> d
|
|
336
|
+
>>> print_dict(s)
|
|
337
|
+
{'s1': 'x', 's2': 'y', 's3': 'z'}
|
|
338
|
+
|
|
339
|
+
>>> import pickle
|
|
340
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
341
|
+
1
|
|
342
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
343
|
+
1
|
|
344
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
345
|
+
1
|
|
346
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
347
|
+
1
|
|
348
|
+
|
|
349
|
+
>>> x.s4 = 'spam'
|
|
350
|
+
|
|
351
|
+
>>> d, s = x.__getstate__()
|
|
352
|
+
>>> d
|
|
353
|
+
>>> print_dict(s)
|
|
354
|
+
{'s1': 'x', 's2': 'y', 's3': 'z', 's4': 'spam'}
|
|
355
|
+
|
|
356
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
357
|
+
1
|
|
358
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
359
|
+
1
|
|
360
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
361
|
+
1
|
|
362
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
363
|
+
1
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
class SubSubSlotted(SubSlotted):
|
|
368
|
+
|
|
369
|
+
def __init__(self, s1, s2, s3, **kw):
|
|
370
|
+
SubSlotted.__init__(self, s1, s2, s3)
|
|
371
|
+
self.__dict__.update(kw)
|
|
372
|
+
self._v_favorite_color = 'blue'
|
|
373
|
+
self._p_foo = 'bar'
|
|
374
|
+
|
|
375
|
+
def __eq__(self, other):
|
|
376
|
+
return cmpattrs(self, other,
|
|
377
|
+
'__class__', 's1', 's2', 's3', 's4',
|
|
378
|
+
*(self.__dict__.keys()))
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def test_pickling_w_slots():
|
|
382
|
+
"""
|
|
383
|
+
>>> x = SubSubSlotted('x', 'y', 'z', aaa=1, bbb='foo')
|
|
384
|
+
|
|
385
|
+
>>> d, s = x.__getstate__()
|
|
386
|
+
>>> print_dict(d)
|
|
387
|
+
{'aaa': 1, 'bbb': 'foo'}
|
|
388
|
+
>>> print_dict(s)
|
|
389
|
+
{'s1': 'x', 's2': 'y', 's3': 'z'}
|
|
390
|
+
|
|
391
|
+
>>> import pickle
|
|
392
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
393
|
+
1
|
|
394
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
395
|
+
1
|
|
396
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
397
|
+
1
|
|
398
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
399
|
+
1
|
|
400
|
+
|
|
401
|
+
>>> x.s4 = 'spam'
|
|
402
|
+
|
|
403
|
+
>>> d, s = x.__getstate__()
|
|
404
|
+
>>> print_dict(d)
|
|
405
|
+
{'aaa': 1, 'bbb': 'foo'}
|
|
406
|
+
>>> print_dict(s)
|
|
407
|
+
{'s1': 'x', 's2': 'y', 's3': 'z', 's4': 'spam'}
|
|
408
|
+
|
|
409
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
410
|
+
1
|
|
411
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
412
|
+
1
|
|
413
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
414
|
+
1
|
|
415
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
416
|
+
1
|
|
417
|
+
"""
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def test_pickling_w_slots_w_empty_dict():
|
|
421
|
+
"""
|
|
422
|
+
>>> x = SubSubSlotted('x', 'y', 'z')
|
|
423
|
+
|
|
424
|
+
>>> d, s = x.__getstate__()
|
|
425
|
+
>>> print_dict(d)
|
|
426
|
+
{}
|
|
427
|
+
>>> print_dict(s)
|
|
428
|
+
{'s1': 'x', 's2': 'y', 's3': 'z'}
|
|
429
|
+
|
|
430
|
+
>>> import pickle
|
|
431
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
432
|
+
1
|
|
433
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
434
|
+
1
|
|
435
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
436
|
+
1
|
|
437
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
438
|
+
1
|
|
439
|
+
|
|
440
|
+
>>> x.s4 = 'spam'
|
|
441
|
+
|
|
442
|
+
>>> d, s = x.__getstate__()
|
|
443
|
+
>>> print_dict(d)
|
|
444
|
+
{}
|
|
445
|
+
>>> print_dict(s)
|
|
446
|
+
{'s1': 'x', 's2': 'y', 's3': 'z', 's4': 'spam'}
|
|
447
|
+
|
|
448
|
+
>>> pickle.loads(pickle.dumps(x)) == x
|
|
449
|
+
1
|
|
450
|
+
>>> pickle.loads(pickle.dumps(x, 0)) == x
|
|
451
|
+
1
|
|
452
|
+
>>> pickle.loads(pickle.dumps(x, 1)) == x
|
|
453
|
+
1
|
|
454
|
+
>>> pickle.loads(pickle.dumps(x, 2)) == x
|
|
455
|
+
1
|
|
456
|
+
"""
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
def test_setattr_on_extension_type():
|
|
460
|
+
"""
|
|
461
|
+
>>> for name in 'x', '_x', 'x_', '__x_y__', '___x__', '__x___', '_x_':
|
|
462
|
+
... setattr(Persistent, name, 1)
|
|
463
|
+
... print(getattr(Persistent, name))
|
|
464
|
+
... delattr(Persistent, name)
|
|
465
|
+
... print(getattr(Persistent, name, 0))
|
|
466
|
+
1
|
|
467
|
+
0
|
|
468
|
+
1
|
|
469
|
+
0
|
|
470
|
+
1
|
|
471
|
+
0
|
|
472
|
+
1
|
|
473
|
+
0
|
|
474
|
+
1
|
|
475
|
+
0
|
|
476
|
+
1
|
|
477
|
+
0
|
|
478
|
+
1
|
|
479
|
+
0
|
|
480
|
+
|
|
481
|
+
>>> Persistent.__foo__ = 1 # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
482
|
+
Traceback (most recent call last):
|
|
483
|
+
...
|
|
484
|
+
TypeError: can't set attributes of built-in/extension type """ \
|
|
485
|
+
"""'Persistence.Persistent' if the attribute name begins """ \
|
|
486
|
+
"""and ends with __ and contains only 4 _ characters
|
|
487
|
+
|
|
488
|
+
>>> Persistent.__foo__ # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
489
|
+
Traceback (most recent call last):
|
|
490
|
+
...
|
|
491
|
+
AttributeError: ...
|
|
492
|
+
|
|
493
|
+
>>> try:
|
|
494
|
+
... del Persistent.__foo__
|
|
495
|
+
... except (AttributeError, TypeError): # different on pypy
|
|
496
|
+
... print('error')
|
|
497
|
+
error
|
|
498
|
+
"""
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
def test_suite():
|
|
502
|
+
return DocTestSuite()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PersistentMappingTests(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def _getTargetClass(self):
|
|
7
|
+
from Persistence import PersistentMapping
|
|
8
|
+
return PersistentMapping
|
|
9
|
+
|
|
10
|
+
def _makeOne(self, *args, **kw):
|
|
11
|
+
return self._getTargetClass()(*args, **kw)
|
|
12
|
+
|
|
13
|
+
def test___setstate__(self):
|
|
14
|
+
m = self._makeOne()
|
|
15
|
+
m.__setstate__({'data': {'x': 1, 'y': 2}})
|
|
16
|
+
self.assertEqual(sorted(m.items()), [('x', 1), ('y', 2)])
|
|
17
|
+
|
|
18
|
+
def test___setstate___old_pickles(self):
|
|
19
|
+
m = self._makeOne()
|
|
20
|
+
m.__setstate__({'_container': {'x': 1, 'y': 2}})
|
|
21
|
+
self.assertEqual(sorted(m.items()), [('x', 1), ('y', 2)])
|
|
22
|
+
|
|
23
|
+
def test_subclass(self):
|
|
24
|
+
klass = self._getTargetClass()
|
|
25
|
+
|
|
26
|
+
class Dummy(klass):
|
|
27
|
+
def __init__(self, *args, **kw):
|
|
28
|
+
self._value = []
|
|
29
|
+
klass.__init__(self, *args, **kw)
|
|
30
|
+
|
|
31
|
+
self.assertTrue(issubclass(Dummy, klass))
|
|
32
|
+
|
|
33
|
+
dummy = Dummy()
|
|
34
|
+
self.assertIsInstance(dummy, Dummy)
|
|
35
|
+
self.assertIsInstance(dummy, klass)
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
#############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2003 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
|
|
8
|
+
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
|
|
9
|
+
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
10
|
+
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
|
|
11
|
+
# FOR A PARTICULAR PURPOSE.
|
|
12
|
+
#
|
|
13
|
+
##############################################################################
|
|
14
|
+
|
|
15
|
+
import pickle
|
|
16
|
+
import time
|
|
17
|
+
import unittest
|
|
18
|
+
from struct import pack
|
|
19
|
+
|
|
20
|
+
from persistent import PickleCache
|
|
21
|
+
from persistent.TimeStamp import TimeStamp
|
|
22
|
+
|
|
23
|
+
from Persistence import CAPI
|
|
24
|
+
from Persistence import IS_PURE
|
|
25
|
+
from Persistence import IS_PYPY
|
|
26
|
+
from Persistence import Persistent
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def p64(v):
|
|
30
|
+
"""Pack an integer or long into a 8-byte string"""
|
|
31
|
+
return pack(">Q", v)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class Jar:
|
|
35
|
+
"""Testing stub for _p_jar attribute."""
|
|
36
|
+
|
|
37
|
+
def __init__(self):
|
|
38
|
+
self.cache = PickleCache(self)
|
|
39
|
+
self.oid = 1
|
|
40
|
+
self.registered = {}
|
|
41
|
+
|
|
42
|
+
def add(self, obj):
|
|
43
|
+
obj._p_oid = p64(self.oid)
|
|
44
|
+
self.oid += 1
|
|
45
|
+
obj._p_jar = self
|
|
46
|
+
self.cache[obj._p_oid] = obj
|
|
47
|
+
|
|
48
|
+
def close(self):
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
# the following methods must be implemented to be a jar
|
|
52
|
+
|
|
53
|
+
def setklassstate(self):
|
|
54
|
+
# I don't know what this method does, but the pickle cache
|
|
55
|
+
# constructor calls it.
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
def register(self, obj):
|
|
59
|
+
self.registered[obj] = 1
|
|
60
|
+
|
|
61
|
+
def setstate(self, obj):
|
|
62
|
+
# Trivial setstate() implementation that just re-initializes
|
|
63
|
+
# the object. This isn't what setstate() is supposed to do,
|
|
64
|
+
# but it suffices for the tests.
|
|
65
|
+
obj.__class__.__init__(obj)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class P(Persistent):
|
|
69
|
+
pass
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class H1(Persistent):
|
|
73
|
+
def __init__(self):
|
|
74
|
+
self.n = 0
|
|
75
|
+
|
|
76
|
+
def __getattr__(self, attr):
|
|
77
|
+
self.n += 1
|
|
78
|
+
return self.n
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class H2(Persistent):
|
|
82
|
+
def __init__(self):
|
|
83
|
+
self.n = 0
|
|
84
|
+
|
|
85
|
+
def __getattribute__(self, attr):
|
|
86
|
+
supergetattr = super().__getattribute__
|
|
87
|
+
try:
|
|
88
|
+
return supergetattr(attr)
|
|
89
|
+
except AttributeError:
|
|
90
|
+
n = supergetattr("n")
|
|
91
|
+
self.n = n + 1
|
|
92
|
+
return n + 1
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
class PersistenceTest(unittest.TestCase):
|
|
96
|
+
def setUp(self):
|
|
97
|
+
self.jar = Jar()
|
|
98
|
+
|
|
99
|
+
def tearDown(self):
|
|
100
|
+
self.jar.close()
|
|
101
|
+
|
|
102
|
+
def test_oid_jar_attrs(self):
|
|
103
|
+
obj = P()
|
|
104
|
+
self.assertEqual(obj._p_oid, None)
|
|
105
|
+
obj._p_oid = 12
|
|
106
|
+
self.assertEqual(obj._p_oid, 12)
|
|
107
|
+
del obj._p_oid
|
|
108
|
+
|
|
109
|
+
self.jar.add(obj)
|
|
110
|
+
|
|
111
|
+
# Can't change oid of cache object.
|
|
112
|
+
with self.assertRaises(ValueError):
|
|
113
|
+
del obj._p_oid
|
|
114
|
+
|
|
115
|
+
with self.assertRaises(ValueError):
|
|
116
|
+
obj._p_oid = 12
|
|
117
|
+
|
|
118
|
+
with self.assertRaises(ValueError):
|
|
119
|
+
del obj._p_jar
|
|
120
|
+
|
|
121
|
+
with self.assertRaises(ValueError):
|
|
122
|
+
obj._p_jar = 12
|
|
123
|
+
|
|
124
|
+
def testChanged(self):
|
|
125
|
+
obj = P()
|
|
126
|
+
self.jar.add(obj)
|
|
127
|
+
|
|
128
|
+
# The value returned for _p_changed can be one of:
|
|
129
|
+
# 0 -- it is not changed
|
|
130
|
+
# 1 -- it is changed
|
|
131
|
+
# None -- it is a ghost
|
|
132
|
+
|
|
133
|
+
obj.x = 1
|
|
134
|
+
self.assertEqual(obj._p_changed, 1)
|
|
135
|
+
self.assertIn(obj, self.jar.registered)
|
|
136
|
+
|
|
137
|
+
obj._p_changed = 0
|
|
138
|
+
self.assertEqual(obj._p_changed, 0)
|
|
139
|
+
self.jar.registered.clear()
|
|
140
|
+
|
|
141
|
+
obj._p_changed = 1
|
|
142
|
+
self.assertEqual(obj._p_changed, 1)
|
|
143
|
+
self.assertIn(obj, self.jar.registered)
|
|
144
|
+
|
|
145
|
+
# setting obj._p_changed to None ghostifies if the
|
|
146
|
+
# object is in the up-to-date state, but not otherwise.
|
|
147
|
+
obj._p_changed = None
|
|
148
|
+
self.assertEqual(obj._p_changed, 1)
|
|
149
|
+
obj._p_changed = 0
|
|
150
|
+
# Now it's a ghost.
|
|
151
|
+
obj._p_changed = None
|
|
152
|
+
self.assertEqual(obj._p_changed, None)
|
|
153
|
+
|
|
154
|
+
obj = P()
|
|
155
|
+
self.jar.add(obj)
|
|
156
|
+
obj._p_changed = 1
|
|
157
|
+
# You can transition directly from modified to ghost if
|
|
158
|
+
# you delete the _p_changed attribute.
|
|
159
|
+
del obj._p_changed
|
|
160
|
+
self.assertEqual(obj._p_changed, None)
|
|
161
|
+
|
|
162
|
+
def testSerial(self):
|
|
163
|
+
noserial = b"\000" * 8
|
|
164
|
+
obj = P()
|
|
165
|
+
self.assertEqual(obj._p_serial, noserial)
|
|
166
|
+
|
|
167
|
+
def set(val):
|
|
168
|
+
obj._p_serial = val
|
|
169
|
+
|
|
170
|
+
self.assertRaises(ValueError, set, 1)
|
|
171
|
+
self.assertRaises(ValueError, set, "0123")
|
|
172
|
+
self.assertRaises(ValueError, set, "012345678")
|
|
173
|
+
self.assertRaises(ValueError, set, "01234567")
|
|
174
|
+
|
|
175
|
+
obj._p_serial = b"01234567"
|
|
176
|
+
del obj._p_serial
|
|
177
|
+
self.assertEqual(obj._p_serial, noserial)
|
|
178
|
+
|
|
179
|
+
def testMTime(self):
|
|
180
|
+
obj = P()
|
|
181
|
+
self.assertEqual(obj._p_mtime, None)
|
|
182
|
+
|
|
183
|
+
t = int(time.time())
|
|
184
|
+
ts = TimeStamp(*time.gmtime(t)[:6])
|
|
185
|
+
obj._p_serial = ts.raw()
|
|
186
|
+
self.assertEqual(obj._p_mtime, t)
|
|
187
|
+
self.assertIsInstance(obj._p_mtime, float)
|
|
188
|
+
|
|
189
|
+
def testPicklable(self):
|
|
190
|
+
obj = P()
|
|
191
|
+
obj.attr = "test"
|
|
192
|
+
s = pickle.dumps(obj)
|
|
193
|
+
obj2 = pickle.loads(s)
|
|
194
|
+
self.assertEqual(obj.attr, obj2.attr)
|
|
195
|
+
|
|
196
|
+
def testGetattr(self):
|
|
197
|
+
obj = H1()
|
|
198
|
+
self.assertEqual(obj.larry, 1)
|
|
199
|
+
self.assertEqual(obj.curly, 2)
|
|
200
|
+
self.assertEqual(obj.moe, 3)
|
|
201
|
+
|
|
202
|
+
self.jar.add(obj)
|
|
203
|
+
obj._p_deactivate()
|
|
204
|
+
|
|
205
|
+
# The simple Jar used for testing re-initializes the object.
|
|
206
|
+
self.assertEqual(obj.larry, 1)
|
|
207
|
+
# The getattr hook modified the object, so it should now be
|
|
208
|
+
# in the changed state.
|
|
209
|
+
self.assertEqual(obj._p_changed, 1)
|
|
210
|
+
self.assertEqual(obj.curly, 2)
|
|
211
|
+
self.assertEqual(obj.moe, 3)
|
|
212
|
+
|
|
213
|
+
def testGetattribute(self):
|
|
214
|
+
obj = H2()
|
|
215
|
+
self.assertEqual(obj.larry, 1)
|
|
216
|
+
self.assertEqual(obj.curly, 2)
|
|
217
|
+
self.assertEqual(obj.moe, 3)
|
|
218
|
+
|
|
219
|
+
self.jar.add(obj)
|
|
220
|
+
obj._p_deactivate()
|
|
221
|
+
|
|
222
|
+
# The simple Jar used for testing re-initializes the object.
|
|
223
|
+
self.assertEqual(obj.larry, 1)
|
|
224
|
+
# The getattr hook modified the object, so it should now be
|
|
225
|
+
# in the changed state.
|
|
226
|
+
self.assertEqual(obj._p_changed, 1)
|
|
227
|
+
self.assertEqual(obj.curly, 2)
|
|
228
|
+
self.assertEqual(obj.moe, 3)
|
|
229
|
+
|
|
230
|
+
# TODO: Need to decide how __setattr__ and __delattr__ should work,
|
|
231
|
+
# then write tests.
|
|
232
|
+
|
|
233
|
+
def test_compilation(self):
|
|
234
|
+
self.assertEqual(CAPI, not (IS_PYPY or IS_PURE))
|
|
235
|
+
try:
|
|
236
|
+
import persistent.cPersistence # noqa: F401 needed for CPython
|
|
237
|
+
|
|
238
|
+
from Persistence import _Persistence
|
|
239
|
+
|
|
240
|
+
cPersistent = _Persistence.Persistent
|
|
241
|
+
except ImportError: # ModuleNotFoundError is wrong here
|
|
242
|
+
cPersistent = None # PyPy never has a C module.
|
|
243
|
+
if CAPI: # pragma: no cover
|
|
244
|
+
self.assertEqual(Persistent, cPersistent)
|
|
245
|
+
else:
|
|
246
|
+
self.assertNotEqual(Persistent, cPersistent)
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: Persistence
|
|
3
|
+
Version: 5.2
|
|
4
|
+
Summary: Persistent ExtensionClass
|
|
5
|
+
Home-page: https://github.com/zopefoundation/Persistence
|
|
6
|
+
Author: Zope Foundation and Contributors
|
|
7
|
+
Author-email: zope-dev@zope.dev
|
|
8
|
+
License: ZPL-2.1
|
|
9
|
+
Classifier: Development Status :: 6 - Mature
|
|
10
|
+
Classifier: Environment :: Web Environment
|
|
11
|
+
Classifier: Framework :: Zope
|
|
12
|
+
Classifier: Framework :: Zope :: 4
|
|
13
|
+
Classifier: Framework :: Zope :: 5
|
|
14
|
+
Classifier: License :: OSI Approved :: Zope Public License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
24
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Description-Content-Type: text/x-rst
|
|
27
|
+
License-File: LICENSE.txt
|
|
28
|
+
Requires-Dist: ExtensionClass>=4.6
|
|
29
|
+
Requires-Dist: persistent>=4.1.1
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: zope.testrunner; extra == "test"
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: author-email
|
|
34
|
+
Dynamic: classifier
|
|
35
|
+
Dynamic: description
|
|
36
|
+
Dynamic: description-content-type
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: license
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: provides-extra
|
|
41
|
+
Dynamic: requires-dist
|
|
42
|
+
Dynamic: requires-python
|
|
43
|
+
Dynamic: summary
|
|
44
|
+
|
|
45
|
+
Overview
|
|
46
|
+
========
|
|
47
|
+
|
|
48
|
+
This package provides a variant of the persistent base class that's an
|
|
49
|
+
ExtensionClass_. Unless you need ExtensionClass_ semantics, you probably want to
|
|
50
|
+
use ``persistent.Persistent`` from the persistent_ distribution (formerly in ZODB3).
|
|
51
|
+
|
|
52
|
+
.. _ExtensionClass : https://pypi.org/project/ExtensionClass/
|
|
53
|
+
.. _persistent : https://pypi.org/project/persistent/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Changelog
|
|
57
|
+
=========
|
|
58
|
+
|
|
59
|
+
5.2 (2025-11-06)
|
|
60
|
+
----------------
|
|
61
|
+
|
|
62
|
+
- Add support for Python 3.14.
|
|
63
|
+
|
|
64
|
+
- Drop support for Python 3.8, 3.9.
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
5.1 (2024-09-17)
|
|
68
|
+
----------------
|
|
69
|
+
|
|
70
|
+
- Add final support for Python 3.13.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
5.0 (2024-05-30)
|
|
74
|
+
----------------
|
|
75
|
+
|
|
76
|
+
- Drop support for Python 3.7.
|
|
77
|
+
|
|
78
|
+
- Add preliminary support for Python 3.13 as of 3.13a3.
|
|
79
|
+
|
|
80
|
+
- Build Windows wheels on GHA.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
4.1 (2023-10-05)
|
|
84
|
+
----------------
|
|
85
|
+
|
|
86
|
+
- Add support for Python 3.12.
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
4.0.post1 (2023-03-24)
|
|
90
|
+
----------------------
|
|
91
|
+
|
|
92
|
+
- Add missing ``python_requires`` in ``setup.py``.
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
4.0 (2023-03-24)
|
|
96
|
+
----------------
|
|
97
|
+
|
|
98
|
+
- Build Linux binary wheels for Python 3.11.
|
|
99
|
+
|
|
100
|
+
- Drop support for Python 2.7, 3.5, 3.6.
|
|
101
|
+
|
|
102
|
+
- Add preliminary support for Python 3.12a5.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
3.6 (2022-11-17)
|
|
106
|
+
----------------
|
|
107
|
+
|
|
108
|
+
- Add support for building arm64 wheels on macOS.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
3.5 (2022-11-03)
|
|
112
|
+
----------------
|
|
113
|
+
|
|
114
|
+
- Add support for final Python 3.11 release.
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
3.4 (2022-10-11)
|
|
118
|
+
----------------
|
|
119
|
+
|
|
120
|
+
- Add support for Python 3.11 as of (3.11.0rc2).
|
|
121
|
+
|
|
122
|
+
- Disable unsafe math optimizations in C code.
|
|
123
|
+
(`#55 <https://github.com/zopefoundation/ExtensionClass/pull/55>`_)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
3.3 (2022-03-10)
|
|
127
|
+
----------------
|
|
128
|
+
|
|
129
|
+
- Add support for Python 3.11 as of (3.11.0a5).
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
3.2 (2022-03-02)
|
|
133
|
+
----------------
|
|
134
|
+
|
|
135
|
+
- Add support for Python 3.10.
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
3.1 (2021-07-23)
|
|
139
|
+
----------------
|
|
140
|
+
|
|
141
|
+
- Create wheels for Linux (2010, 2014 and aarch64) and MacOS.
|
|
142
|
+
|
|
143
|
+
- Add support for Python 3.9.
|
|
144
|
+
|
|
145
|
+
- On CPython no longer omit compiling the C code when ``PURE_PYTHON`` is set.
|
|
146
|
+
Just evaluate it at runtime.
|
|
147
|
+
(`#27 <https://github.com/zopefoundation/Persistence/issues/27>`_)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
3.0 (2019-05-08)
|
|
151
|
+
----------------
|
|
152
|
+
|
|
153
|
+
Changes since 2.13.2:
|
|
154
|
+
|
|
155
|
+
- Add support for Python 3.5, 3.6, 3.7 and 3.8a3.
|
|
156
|
+
|
|
157
|
+
- Drop support for Python 2.6.
|
|
158
|
+
|
|
159
|
+
- Make tests compatible with `persistent >= 4.2.3`.
|
|
160
|
+
|
|
161
|
+
- Fix for compilers that only support C89 syntax (e.g. on Windows).
|
|
162
|
+
|
|
163
|
+
- Ensure our dependencies match our expectations about C extensions.
|
|
164
|
+
(`#4 <https://github.com/zopefoundation/Persistence/issues/4>`_)
|
|
165
|
+
|
|
166
|
+
- Update ExtensionClass and persistent headers.
|
|
167
|
+
|
|
168
|
+
- Fix isinstance/issubclass for the Python version of PersistentMapping.
|
|
169
|
+
|
|
170
|
+
- Add AppVeyor configuration to automate building Windows eggs.
|
|
171
|
+
|
|
172
|
+
2.13.2 (2010-06-16)
|
|
173
|
+
-------------------
|
|
174
|
+
|
|
175
|
+
- LP #587760: Handle tp_basicsize correctly.
|
|
176
|
+
|
|
177
|
+
2.13.1 (2010-04-30)
|
|
178
|
+
-------------------
|
|
179
|
+
|
|
180
|
+
- Removed undeclared testing dependency on zope.testing.
|
|
181
|
+
|
|
182
|
+
2.13.0 (2010-02-23)
|
|
183
|
+
-------------------
|
|
184
|
+
|
|
185
|
+
- Update to include ExtensionClass 2.13.0.
|
|
186
|
+
|
|
187
|
+
2.12.0 (2010-02-14)
|
|
188
|
+
-------------------
|
|
189
|
+
|
|
190
|
+
- Added support for method cache in Persistence. Patch contributed by
|
|
191
|
+
Yoshinori K. Okuji. See https://bugs.launchpad.net/zope2/+bug/486193.
|
|
192
|
+
|
|
193
|
+
- Updated C includes to ExtensionClass 2.12.0.
|
|
194
|
+
|
|
195
|
+
- Updated package metadata and remove old build artifacts.
|
|
196
|
+
|
|
197
|
+
2.11.1 (2009-02-19)
|
|
198
|
+
-------------------
|
|
199
|
+
|
|
200
|
+
- First egg release.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Persistence/_Persistence.c,sha256=yC1hoqn7YlAUSCX4UmTY0Bvw0TrPiT_I2u6gc5cG2Qs,4753
|
|
2
|
+
Persistence/_Persistence.cp314-win_amd64.pyd,sha256=UgQcuYMAh21kq51UugagXGSvY0EUY25ZWriXJjG4ouQ,12800
|
|
3
|
+
Persistence/__init__.py,sha256=mG8PFG8yGLSNTu4bv5rBCnPd3tZnShYgckCJPvdFi7Q,2146
|
|
4
|
+
Persistence/mapping.py,sha256=4o9sKNq3NEX17A5Ju-irhUfSxadKPgXc6jiMhuKG8Oo,1852
|
|
5
|
+
Persistence/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
Persistence/tests/test_ec.py,sha256=oqLCD3SbnkcW92Y2yBYEfNe9ARZ3g47xnG61LpgnwsM,11807
|
|
7
|
+
Persistence/tests/test_mapping.py,sha256=cak9NX9-H3XrUYEN13zXsBdyqx1Gse31UJ6OqjiyZ7U,1072
|
|
8
|
+
Persistence/tests/test_persistent.py,sha256=i0GBH-Lx1uQqtht_1Q8HVyAk45ahRCktGqQeZdeHi1E,7183
|
|
9
|
+
persistence-5.2.dist-info/licenses/LICENSE.txt,sha256=bHkPG2Oy1PmxiQVWnzhtYjAlM1wCWbZQ6AyenUetrS0,2114
|
|
10
|
+
persistence-5.2.dist-info/METADATA,sha256=-QH0R6lU5cy9D-hOIpfk2MH2l8DnAD0wWryRdymt2g0,4819
|
|
11
|
+
persistence-5.2.dist-info/WHEEL,sha256=7k6Wcy588iJYe5lf5K095NLg-uoBTnE-T8eHJ92G4_4,101
|
|
12
|
+
persistence-5.2.dist-info/top_level.txt,sha256=hSmmw3BscrovQFfpVAMuBsNDyshEZkza6RhMLTZf74g,12
|
|
13
|
+
persistence-5.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
Zope Public License (ZPL) Version 2.1
|
|
2
|
+
|
|
3
|
+
A copyright notice accompanies this license document that identifies the
|
|
4
|
+
copyright holders.
|
|
5
|
+
|
|
6
|
+
This license has been certified as open source. It has also been designated as
|
|
7
|
+
GPL compatible by the Free Software Foundation (FSF).
|
|
8
|
+
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
1. Redistributions in source code must retain the accompanying copyright
|
|
13
|
+
notice, this list of conditions, and the following disclaimer.
|
|
14
|
+
|
|
15
|
+
2. Redistributions in binary form must reproduce the accompanying copyright
|
|
16
|
+
notice, this list of conditions, and the following disclaimer in the
|
|
17
|
+
documentation and/or other materials provided with the distribution.
|
|
18
|
+
|
|
19
|
+
3. Names of the copyright holders must not be used to endorse or promote
|
|
20
|
+
products derived from this software without prior written permission from the
|
|
21
|
+
copyright holders.
|
|
22
|
+
|
|
23
|
+
4. The right to distribute this software or to use it for any purpose does not
|
|
24
|
+
give you the right to use Servicemarks (sm) or Trademarks (tm) of the
|
|
25
|
+
copyright
|
|
26
|
+
holders. Use of them is covered by separate agreement with the copyright
|
|
27
|
+
holders.
|
|
28
|
+
|
|
29
|
+
5. If any files are modified, you must cause the modified files to carry
|
|
30
|
+
prominent notices stating that you changed the files and the date of any
|
|
31
|
+
change.
|
|
32
|
+
|
|
33
|
+
Disclaimer
|
|
34
|
+
|
|
35
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED
|
|
36
|
+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
37
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
38
|
+
EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
39
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
40
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
41
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
42
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
43
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
44
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Persistence
|