[Checkins] SVN: zope.hookable/branches/regebro-python3/s Python 3.1 support
Lennart Regebro
regebro at gmail.com
Wed Jul 21 09:13:11 EDT 2010
Log message for revision 114898:
Python 3.1 support
Changed:
U zope.hookable/branches/regebro-python3/setup.py
U zope.hookable/branches/regebro-python3/src/zope/hookable/__init__.py
U zope.hookable/branches/regebro-python3/src/zope/hookable/_zope_hookable.c
-=-
Modified: zope.hookable/branches/regebro-python3/setup.py
===================================================================
--- zope.hookable/branches/regebro-python3/setup.py 2010-07-21 13:09:57 UTC (rev 114897)
+++ zope.hookable/branches/regebro-python3/setup.py 2010-07-21 13:13:11 UTC (rev 114898)
@@ -31,18 +31,30 @@
author='Zope Foundation and Contributors',
author_email='zope-dev at zope.org',
long_description="Hookable object support.",
+ classifiers=[
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: Zope Public License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: 2.4",
+ "Programming Language :: Python :: 2.5",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 3.1",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
packages=find_packages('src'),
- package_dir = {'': 'src'},
+ package_dir={'': 'src'},
ext_modules=[Extension("zope.hookable._zope_hookable",
[os.path.join('src', 'zope', 'hookable',
"_zope_hookable.c")
- ]),
+ ], extra_compile_args=['-g']),
],
namespace_packages=['zope',],
extras_require=dict(test=['zope.testing']),
install_requires=['setuptools'],
- include_package_data = True,
-
- zip_safe = False,
+ include_package_data=True,
+ zip_safe=False,
+
+ test_suite='zope.hookable.tests.test_hookable.test_suite',
)
Modified: zope.hookable/branches/regebro-python3/src/zope/hookable/__init__.py
===================================================================
--- zope.hookable/branches/regebro-python3/src/zope/hookable/__init__.py 2010-07-21 13:09:57 UTC (rev 114897)
+++ zope.hookable/branches/regebro-python3/src/zope/hookable/__init__.py 2010-07-21 13:13:11 UTC (rev 114898)
@@ -45,18 +45,18 @@
>>> f()
41
- >>> del f.original
- Traceback (most recent call last):
- ...
- TypeError: readonly attribute
+ >>> try:
+ ... del f.original
+ ... raise "Could delete read only attribute"
+ ... except (TypeError, AttributeError):
+ ... pass
- >>> del f.implementation
- Traceback (most recent call last):
- ...
- TypeError: readonly attribute
+ >>> try:
+ ... del f.implementation
+ ... raise "Could delete read only attribute"
+ ... except (TypeError, AttributeError):
+ ... pass
- Some error cases.
-
>>> g = hookable() # not enough args
Traceback (most recent call last):
...
@@ -76,7 +76,7 @@
"""
__docformat__ = 'restructuredtext'
-from _zope_hookable import *
+from zope.hookable._zope_hookable import *
# DocTest:
if __name__ == "__main__":
Modified: zope.hookable/branches/regebro-python3/src/zope/hookable/_zope_hookable.c
===================================================================
--- zope.hookable/branches/regebro-python3/src/zope/hookable/_zope_hookable.c 2010-07-21 13:09:57 UTC (rev 114897)
+++ zope.hookable/branches/regebro-python3/src/zope/hookable/_zope_hookable.c 2010-07-21 13:13:11 UTC (rev 114898)
@@ -21,6 +21,28 @@
#include "Python.h"
#include "structmember.h"
+/* Support for Python 2.4 and 2.5: */
+
+#ifndef Py_TYPE
+ #define Py_TYPE(o) ((o)->ob_type)
+#endif
+
+#ifndef cmpfunc
+ #define cmpfunc int
+#endif
+
+#ifndef PyVarObject_HEAD_INIT
+ #define PyVarObject_HEAD_INIT(type, size) _PyObject_EXTRA_INIT\
+ 1, type, size,
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+ #define MOD_ERROR_VAL NULL
+#else
+ #define MOD_ERROR_VAL
+#endif
+
+
typedef struct {
PyObject_HEAD
PyObject *old;
@@ -78,19 +100,14 @@
PyObject_GC_UnTrack((PyObject *)self);
Py_XDECREF(self->old);
Py_XDECREF(self->implementation);
- self->ob_type->tp_free((PyObject*)self);
+ Py_TYPE(self)->tp_free((PyObject*)self);
}
static PyObject *
-hookable_sethook(hookable *self, PyObject *args, PyObject *kwds)
+hookable_sethook(hookable *self, PyObject *implementation)
{
- static char *kwlist[] = {"implementation:sethook", NULL};
- PyObject *implementation, *old;
+ PyObject *old;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist,
- &implementation))
- return NULL;
-
old = self->implementation;
Py_INCREF(implementation);
self->implementation = implementation;
@@ -115,7 +132,7 @@
}
static struct PyMethodDef hookable_methods[] = {
- {"sethook", (PyCFunction)hookable_sethook, METH_KEYWORDS,
+ {"sethook", (PyCFunction)hookable_sethook, METH_O,
"Set the hook implementation for the hookable object"},
{"reset", (PyCFunction)hookable_reset, METH_NOARGS,
"Reset the hook to the original value"},
@@ -133,8 +150,8 @@
}
static PyMemberDef hookable_members[] = {
- { "original", T_OBJECT_EX, offsetof(hookable, old), RO },
- { "implementation", T_OBJECT_EX, offsetof(hookable, implementation), RO },
+ { "original", T_OBJECT_EX, offsetof(hookable, old), READONLY },
+ { "implementation", T_OBJECT_EX, offsetof(hookable, implementation), READONLY },
{NULL} /* Sentinel */
};
@@ -144,8 +161,7 @@
;
static PyTypeObject hookabletype = {
- PyObject_HEAD_INIT(NULL)
- /* ob_size */ 0,
+ PyVarObject_HEAD_INIT(NULL, 0)
/* tp_name */ "zope.hookable."
"hookable",
/* tp_basicsize */ sizeof(hookable),
@@ -189,15 +205,67 @@
/* tp_free */ 0/*_PyObject_GC_Del*/,
};
+
+/* Generic Module hacks */
+struct module_state {
+ PyObject *error;
+};
+
+#if PY_MAJOR_VERSION >= 3
+
+ #define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
+
+ static int extension_traverse(PyObject *m, visitproc visit, void *arg) {
+ Py_VISIT(GETSTATE(m)->error);
+ return 0;
+ }
+
+ static int extension_clear(PyObject *m) {
+ Py_CLEAR(GETSTATE(m)->error);
+ return 0;
+ }
+
+#else
+ #define GETSTATE(m) (&_state)
+ static struct module_state _state;
+#endif
+
+/* End module hacks */
+
+static PyObject *
+error_out(PyObject *m) {
+ struct module_state *st = GETSTATE(m);
+ PyErr_SetString(st->error, "zope.hookable module initialization failed");
+ return NULL;
+}
+
static struct PyMethodDef zch_methods[] = {
- {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
+ {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL},
+ {NULL, NULL}
};
-#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
+
+#if PY_MAJOR_VERSION >= 3
+ static struct PyModuleDef moduledef = {
+ PyModuleDef_HEAD_INIT,
+ "_zope_hookable",/* m_name */
+ "Provide an efficient implementation for hookable objects",/* m_doc */
+ sizeof(struct module_state),/* m_size */
+ zch_methods,/* m_methods */
+ NULL,/* m_reload */
+ extension_traverse,/* m_traverse */
+ extension_clear,/* m_clear */
+ NULL,/* m_free */
+ };
#endif
+
+#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC
+PyInit__zope_hookable(void)
+#else
+void
init_zope_hookable(void)
+#endif
{
PyObject *m;
@@ -206,16 +274,29 @@
hookabletype.tp_free = _PyObject_GC_Del;
if (PyType_Ready(&hookabletype) < 0)
- return;
+ return MOD_ERROR_VAL;
+#if PY_MAJOR_VERSION >= 3
+ m = PyModule_Create(&moduledef);
+#else
m = Py_InitModule3("_zope_hookable", zch_methods,
"Provide an efficient implementation for hookable objects"
);
+#endif
if (m == NULL)
- return;
+ return MOD_ERROR_VAL;
+ struct module_state *st = GETSTATE(m);
+ st->error = PyErr_NewException("myextension.Error", NULL, NULL);
+ if (st->error == NULL) {
+ Py_DECREF(m);
+ return MOD_ERROR_VAL;
+ }
+
if (PyModule_AddObject(m, "hookable", (PyObject *)&hookabletype) < 0)
- return;
+ return MOD_ERROR_VAL;
+
+ return m;
}
More information about the checkins
mailing list