Commit 78d1b370 authored by Hanno Schlichting's avatar Hanno Schlichting

Split out standalone packages with C dependencies into their own packages

parent e37190e8
......@@ -85,6 +85,11 @@ Features Added
- Updated packages:
- initgroups = 2.13.0
- Missing = 2.13.0
- MultiMapping = 2.13.0
- Record = 2.13.0
- ThreadLock = 2.13.0
- zope.annotation = 3.5.0
- zope.app.form = 3.12.1
- zope.broken = 3.6.0
......
......@@ -11,8 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Setup for the Zope2 package
"""
import os
from setuptools import setup, find_packages, Extension
......@@ -49,32 +48,6 @@ setup(name='Zope2',
include_dirs=EXTENSIONCLASS_INCLUDEDIRS,
sources=['src/DocumentTemplate/cDocumentTemplate.c']),
Extension(
name='MultiMapping._MultiMapping',
include_dirs=EXTENSIONCLASS_INCLUDEDIRS,
sources=["src/MultiMapping/_MultiMapping.c"],
depends=["include/ExtensionClass/ExtensionClass.h"]),
Extension(
name='ThreadLock._ThreadLock',
include_dirs=EXTENSIONCLASS_INCLUDEDIRS,
sources=["src/ThreadLock/_ThreadLock.c"],
depends=["include/ExtensionClass/ExtensionClass.h"]),
Extension(
name='Missing._Missing',
include_dirs=EXTENSIONCLASS_INCLUDEDIRS,
sources=["src/Missing/_Missing.c"],
depends=["include/ExtensionClass/ExtensionClass.h"]),
Extension(
name='Record._Record',
include_dirs=EXTENSIONCLASS_INCLUDEDIRS,
sources=["src/Record/_Record.c"],
depends=["include/ExtensionClass/ExtensionClass.h"]),
# initgroups
Extension(
name='initgroups._initgroups',
sources=['src/initgroups/_initgroups.c']),
# indexes
Extension(
name='Products.ZCTextIndex.stopper',
......@@ -89,11 +62,16 @@ setup(name='Zope2',
'Acquisition',
'DateTime',
'ExtensionClass',
'Missing',
'MultiMapping',
'Persistence',
'Record',
'RestrictedPython',
'ThreadLock',
'ZConfig',
'ZODB3',
'docutils',
'initgroups',
'pytz',
'setuptools',
'tempstorage',
......
/*****************************************************************************
Copyright (c) 1996-2002 Zope Corporation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (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 Missing_module_documentation[] =
""
"\n$Id$"
;
#include "ExtensionClass/ExtensionClass.h"
/* Declarations for objects of type Missing */
typedef struct {
PyObject_HEAD
} Missing;
static PyObject *vname=0, *Missing_dot_Value=0, *empty_string=0, *reduce=0;
static PyObject *theValue, *notMissing;
static void
Missing_dealloc(Missing *self)
{
Py_DECREF(self->ob_type);
PyObject_DEL(self);
}
static PyObject *
Missing_repr(Missing *self)
{
Py_INCREF(Missing_dot_Value);
return Missing_dot_Value;
}
static PyObject *
Missing_str(Missing *self)
{
Py_INCREF(empty_string);
return empty_string;
}
/* Code to access Missing objects as numbers.
We must guarantee that notMissing is never returned to Python code,
because it would violate the guarantee that all Python-accessible
Missing values are equal to each other.
*/
static PyObject *
Missing_bin(PyObject *v, PyObject *w)
{
if (v == notMissing)
v = w;
assert(v != notMissing);
Py_INCREF(v);
return v;
}
static PyObject *
Missing_pow(PyObject *v, PyObject *w, PyObject *z)
{
if (v == notMissing)
v = w;
assert(v != notMissing);
Py_INCREF(v);
return v;
}
static PyObject *
Missing_un(PyObject *v)
{
Py_INCREF(v);
return v;
}
static int
Missing_nonzero(PyObject *v)
{
return 0;
}
/* Always return the distinguished notMissing object as the result
of the coercion. The notMissing object does not compare equal
to other Missing objects.
*/
static int
Missing_coerce(PyObject **pv, PyObject **pw)
{
Py_INCREF(*pv);
Py_INCREF(notMissing);
*pw = notMissing;
return 0;
}
static PyNumberMethods Missing_as_number = {
(binaryfunc)Missing_bin, /*nb_add*/
(binaryfunc)Missing_bin, /*nb_subtract*/
(binaryfunc)Missing_bin, /*nb_multiply*/
(binaryfunc)Missing_bin, /*nb_divide*/
(binaryfunc)Missing_bin, /*nb_remainder*/
(binaryfunc)Missing_bin, /*nb_divmod*/
(ternaryfunc)Missing_pow, /*nb_power*/
(unaryfunc)Missing_un, /*nb_negative*/
(unaryfunc)Missing_un, /*nb_positive*/
(unaryfunc)Missing_un, /*nb_absolute*/
(inquiry)Missing_nonzero, /*nb_nonzero*/
(unaryfunc)Missing_un, /*nb_invert*/
(binaryfunc)Missing_bin, /*nb_lshift*/
(binaryfunc)Missing_bin, /*nb_rshift*/
(binaryfunc)Missing_bin, /*nb_and*/
(binaryfunc)Missing_bin, /*nb_xor*/
(binaryfunc)Missing_bin, /*nb_or*/
(coercion)Missing_coerce, /*nb_coerce*/
0, /*nb_int*/
0, /*nb_long*/
0, /*nb_float*/
0, /*nb_oct*/
0, /*nb_hex*/
#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION != 1
0, /* nb_inplace_add */
0, /* nb_inplace_subtract */
0, /* nb_inplace_multiply */
0, /* nb_inplace_divide */
0, /* nb_inplace_remainder */
0, /* nb_inplace_power */
0, /* nb_inplace_lshift */
0, /* nb_inplace_rshift */
0, /* nb_inplace_and */
0, /* nb_inplace_xor */
0, /* nb_inplace_or */
Missing_bin, /* nb_floor_divide */
Missing_bin, /* nb_true_divide */
0, /* nb_inplace_floor_divide */
0, /* nb_inplace_true_divide */
#endif
};
/* ------------------------------------------------------- */
static PyObject *
Missing_reduce(PyObject *self, PyObject *args, PyObject *kw)
{
if(self==theValue)
{
Py_INCREF(vname);
return vname;
}
return Py_BuildValue("O()",self->ob_type);
}
static struct PyMethodDef reduce_ml[] = {
{"__reduce__", (PyCFunction)Missing_reduce, 1,
"Return a missing value reduced to standard python objects"
}
};
static PyObject *
Missing_getattr(PyObject *self, PyObject *name)
{
char *c, *legal;
if(!(c=PyString_AsString(name))) return NULL;
legal=c;
if (strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
*legal) != NULL)
{
for (legal++; *legal; legal++)
if (strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",
*legal) == NULL)
{
legal=NULL;
break;
}
}
else legal=NULL;
if(! legal)
{
if(strcmp(c,"__reduce__")==0)
{
if(self==theValue)
{
Py_INCREF(reduce);
return reduce;
}
return PyCFunction_New(reduce_ml, self);
}
PyErr_SetObject(PyExc_AttributeError, name);
return NULL;
}
Py_INCREF(self);
return self;
}
static PyObject *
Missing_call(PyObject *self, PyObject *args, PyObject *kw)
{
Py_INCREF(self);
return self;
}
/* All Missing objects are equal to each other, except for the
special notMissing object. It is returned by coerce to
indicate that Missing is being compare to something else.
*/
static int
Missing_cmp(PyObject *m1, PyObject *m2)
{
if (m1 == notMissing)
return -1;
return (m2 == notMissing);
}
static PyExtensionClass MissingType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Missing", /*tp_name*/
sizeof(Missing), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)Missing_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
(getattrfunc)0, /*obsolete tp_getattr*/
(setattrfunc)0, /*obsolete tp_setattr*/
Missing_cmp, /*tp_compare*/
(reprfunc)Missing_repr, /*tp_repr*/
&Missing_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(hashfunc)0, /*tp_hash*/
(ternaryfunc)Missing_call, /*tp_call*/
(reprfunc)Missing_str, /*tp_str*/
(getattrofunc)Missing_getattr, /*tp_getattro*/
(setattrofunc)0, /*tp_setattro*/
/* Space for future expansion */
0L,0L,
"Represent totally unknown quantities\n"
"\n"
"Missing values are used to represent numeric quantities that are\n"
"unknown. They support all mathematical operations except\n"
"conversions by returning themselves.\n",
METHOD_CHAIN(NULL)
};
/* End of code for Missing objects */
/* -------------------------------------------------------- */
/* List of methods defined in the module */
static struct PyMethodDef Module_Level__methods[] = {
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
void
init_Missing(void)
{
PyObject *m, *d;
if(! ((vname=PyString_FromString("V"))
&& (Missing_dot_Value=PyString_FromString("Missing.Value"))
&& (empty_string=PyString_FromString(""))
)) return;
/* Create the module and add the functions */
m = Py_InitModule4("_Missing", Module_Level__methods,
Missing_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"Missing",MissingType);
theValue = PyObject_CallObject((PyObject*)&MissingType, NULL);
notMissing = PyObject_CallObject((PyObject*)&MissingType, NULL);
reduce=PyCFunction_New(reduce_ml, theValue);
PyDict_SetItemString(d, "Value", theValue);
PyDict_SetItemString(d, "V", theValue);
PyDict_SetItemString(d, "MV", theValue);
}
from _Missing import *
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Test for missing values.
>>> from Missing import Value
>>> Value != 12
1
>>> 12 != Value
1
>>> u"abc" != Value
1
>>> Value != u"abc"
1
>>> 1 + Value == Value
1
>>> Value + 1 == Value
1
>>> Value == 1 + Value
1
>>> Value == Value + 1
1
$Id$
"""
import unittest
from doctest import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
/*****************************************************************************
Copyright (c) 1996-2003 Zope Corporation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (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
****************************************************************************/
#include "ExtensionClass/ExtensionClass.h"
#define UNLESS(E) if(!(E))
typedef struct {
PyObject_HEAD
PyObject *data;
} MMobject;
staticforward PyExtensionClass MMtype;
static PyObject *
MM_push(MMobject *self, PyObject *args)
{
PyObject *src;
UNLESS(PyArg_ParseTuple(args, "O", &src)) return NULL;
UNLESS(-1 != PyList_Append(self->data,src)) return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
MM_pop(MMobject *self, PyObject *args)
{
int i=1, l;
PyObject *r;
if(args) UNLESS(PyArg_ParseTuple(args, "|i", &i)) return NULL;
if((l=PyList_Size(self->data)) < 0) return NULL;
i=l-i;
UNLESS(r=PySequence_GetItem(self->data,l-1)) return NULL;
if(PyList_SetSlice(self->data,i,l,NULL) < 0) goto err;
return r;
err:
Py_DECREF(r);
return NULL;
}
static PyObject *
MM__init__(MMobject *self, PyObject *args)
{
UNLESS(self->data=PyList_New(0)) return NULL;
if (args)
{
int l, i;
if ((l=PyTuple_Size(args)) < 0) return NULL;
for (i=0; i < l; i++)
if (PyList_Append(self->data, PyTuple_GET_ITEM(args, i)) < 0)
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
MM_subscript(MMobject *self, PyObject *key)
{
long i;
PyObject *e;
UNLESS(-1 != (i=PyList_Size(self->data))) return NULL;
while(--i >= 0)
{
e=PyList_GetItem(self->data,i);
if((e=PyObject_GetItem(e,key))) return e;
PyErr_Clear();
}
PyErr_SetObject(PyExc_KeyError,key);
return NULL;
}
static PyObject *
MM_has_key(MMobject *self, PyObject *args)
{
PyObject *key;
UNLESS(PyArg_ParseTuple(args,"O",&key)) return NULL;
if((key=MM_subscript(self, key)))
{
Py_DECREF(key);
return PyInt_FromLong(1);
}
PyErr_Clear();
return PyInt_FromLong(0);
}
static PyObject *
MM_get(MMobject *self, PyObject *args)
{
PyObject *key, *d=Py_None;
UNLESS(PyArg_ParseTuple(args,"O|O",&key,&d)) return NULL;
if((key=MM_subscript(self, key))) return key;
PyErr_Clear();
Py_INCREF(d);
return d;
}
static struct PyMethodDef MM_methods[] = {
{"__init__", (PyCFunction)MM__init__, METH_VARARGS,
"__init__([m1, m2, ...]) -- Create a new empty multi-mapping"},
{"get", (PyCFunction) MM_get, METH_VARARGS,
"get(key,[default]) -- Return a value for the given key or a default"},
{"has_key", (PyCFunction) MM_has_key, METH_VARARGS,
"has_key(key) -- Return 1 if the mapping has the key, and 0 otherwise"},
{"push", (PyCFunction) MM_push, METH_VARARGS,
"push(mapping_object) -- Add a data source"},
{"pop", (PyCFunction) MM_pop, METH_VARARGS,
"pop([n]) -- Remove and return the last data source added"},
{NULL, NULL} /* sentinel */
};
static void
MM_dealloc(MMobject *self)
{
Py_XDECREF(self->data);
Py_DECREF(self->ob_type);
PyObject_DEL(self);
}
static PyObject *
MM_getattr(MMobject *self, char *name)
{
return Py_FindMethod(MM_methods, (PyObject *)self, name);
}
static int
MM_length(MMobject *self)
{
long l=0, el, i;
PyObject *e=0;
UNLESS(-1 != (i=PyList_Size(self->data))) return -1;
while(--i >= 0)
{
e=PyList_GetItem(self->data,i);
UNLESS(-1 != (el=PyObject_Length(e))) return -1;
l+=el;
}
return l;
}
static PyMappingMethods MM_as_mapping = {
(inquiry)MM_length, /*mp_length*/
(binaryfunc)MM_subscript, /*mp_subscript*/
(objobjargproc)NULL, /*mp_ass_subscript*/
};
/* -------------------------------------------------------- */
static char MMtype__doc__[] =
"MultiMapping -- Combine multiple mapping objects for lookup"
;
static PyExtensionClass MMtype = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"MultiMapping", /*tp_name*/
sizeof(MMobject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)MM_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
(getattrfunc)MM_getattr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
&MM_as_mapping, /*tp_as_mapping*/
(hashfunc)0, /*tp_hash*/
(ternaryfunc)0, /*tp_call*/
(reprfunc)0, /*tp_str*/
/* Space for future expansion */
0L,0L,0L,0L,
MMtype__doc__, /* Documentation string */
METHOD_CHAIN(MM_methods)
};
static struct PyMethodDef MultiMapping_methods[] = {
{NULL, NULL} /* sentinel */
};
void
init_MultiMapping(void)
{
PyObject *m, *d;
m = Py_InitModule4(
"_MultiMapping", MultiMapping_methods,
"MultiMapping -- Wrap multiple mapping objects for lookup"
"\n\n"
"$Id$\n",
(PyObject*)NULL,PYTHON_API_VERSION);
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"MultiMapping",MMtype);
if (PyErr_Occurred()) Py_FatalError("can't initialize module MultiMapping");
}
from _MultiMapping import *
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Multi-mapping tests
>>> from MultiMapping import *
>>> def sortprint(L):
... L.sort()
... print L
>>> m=MultiMapping()
>>> m.push({'spam':1, 'eggs':2})
>>> print m['spam']
1
>>> print m['eggs']
2
>>> m.push({'spam':3})
>>> print m['spam']
3
>>> print m['eggs']
2
>>> sortprint(m.pop().items())
[('spam', 3)]
>>> sortprint(m.pop().items())
[('eggs', 2), ('spam', 1)]
>>> try:
... print m.pop()
... raise "That\'s odd", "This last pop should have failed!"
... except: # I should probably raise a specific error in this case.
... pass
$Id$
"""
import unittest
from doctest import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
This diff is collapsed.
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Records
Records are used to provide compact storage for database query result rows.
They don't use instance dictionaries. Rather, they store they data in
a compact array internally. They use a record schema to map names to
positions within the array.
>>> class R(Record):
... __record_schema__ = {'a': 0, 'b': 1, 'c': 2}
>>> r = R()
>>> r.__dict__
Traceback (most recent call last):
...
AttributeError: __dict__
>>> r.a
>>> r.a = 1
>>> r.a
1
>>> r.b
>>> r.c
Records can be used as mapping objects:
>>> "%(a)s %(b)s %(c)s" % r
'1 None None'
>>> r['a']
1
>>> r['b'] = 42
And like sequences:
>>> r[0]
1
>>> r[1]
42
>>> list(r)
[1, 42, None]
$Id: __init__.py,v 1.2 2003/11/28 16:46:36 jim Exp $
"""
from _Record import Record
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""Record tests
$Id: tests.py,v 1.2 2003/11/28 16:46:36 jim Exp $
"""
from Record import Record
import pickle
class P(Record):
__record_schema__ = {'a': 0, 'b': 1, 'c': 2}
def test_RecordPickling():
"""
We can create records from sequences:
>>> r = P(('x', 42, 1.23))
We can pickle them:
>>> r2 = pickle.loads(pickle.dumps(r))
>>> list(r) == list(r2)
1
>>> r.__record_schema__ == r2.__record_schema__
1
"""
import unittest
from doctest import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite('Record'),
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
/*****************************************************************************
Copyright (c) 1996-2003 Zope Corporation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (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 ThreadLock_module_documentation[] =
""
"\n$Id: _ThreadLock.c,v 1.2 2003/11/28 16:46:39 jim Exp $"
;
#include "Python.h"
#ifdef WITH_THREAD
#include "listobject.h"
#ifdef PyList_SET_ITEM
#include "pythread.h"
#define get_thread_ident PyThread_get_thread_ident
#define acquire_lock PyThread_acquire_lock
#define release_lock PyThread_release_lock
#define type_lock PyThread_type_lock
#define free_lock PyThread_free_lock
#define allocate_lock PyThread_allocate_lock
#else
#include "thread.h"
#endif
#endif
static PyObject *ErrorObject;
/* ----------------------------------------------------- */
#define UNLESS(E) if(!(E))
/* Declarations for objects of type ThreadLock */
typedef struct {
PyObject_HEAD
int count;
long id;
#ifdef WITH_THREAD
type_lock lock;
#endif
} ThreadLockObject;
staticforward PyTypeObject ThreadLockType;
static int
cacquire(ThreadLockObject *self, int wait)
{
int acquired = 1;
#ifdef WITH_THREAD
long id = get_thread_ident();
#else
long id = 1;
#endif
if(self->count >= 0 && self->id==id)
{
/* Somebody has locked me. It is either the current thread or
another thread. */
/* So this thread has it. I can't have a race condition, because,
if another thread had the lock, then the id would not be this
one. */
self->count++;
}
else
{
#ifdef WITH_THREAD
Py_BEGIN_ALLOW_THREADS
acquired = acquire_lock(self->lock, wait ? WAIT_LOCK : NOWAIT_LOCK);
Py_END_ALLOW_THREADS
#endif
if (acquired)
{
self->count=0;
self->id=id;
}
}
return acquired;
}
static PyObject *
acquire(ThreadLockObject *self, PyObject *args)
{
int wait = -1, acquired;
if (! PyArg_ParseTuple(args, "|i", &wait)) return NULL;
acquired=cacquire(self, wait);
if(acquired < 0) return NULL;
if (wait >= 0) return PyInt_FromLong(acquired);
Py_INCREF(Py_None);
return Py_None;
}
static int
crelease(ThreadLockObject *self)
{
#ifdef WITH_THREAD
long id = get_thread_ident();
#else
long id = 1;
#endif
if(self->count >= 0 && self->id==id)
{
/* Somebody has locked me. It is either the current thread or
another thread. */
/* So this thread has it. I can't have a race condition, because,
if another thread had the lock, then the id would not be this
one. */
self->count--;
#ifdef WITH_THREAD
if(self->count < 0) release_lock(self->lock);
#endif
}
else
{
PyErr_SetString(ErrorObject, "release unlocked lock");
return -1;
}
return 0;
}
static PyObject *
release(ThreadLockObject *self, PyObject *args)
{
if (! PyArg_ParseTuple(args, "")) return NULL;
if(crelease(self) < 0) return NULL;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
call_method(ThreadLockObject *self, PyObject *args)
{
PyObject *f, *a=0, *k=0;
UNLESS(PyArg_ParseTuple(args,"OO|O",&f, &a, &k)) return NULL;
if(cacquire(self, -1) < 0) return NULL;
f=PyEval_CallObjectWithKeywords(f,a,k);
if(crelease(self) < 0)
{
Py_XDECREF(f);
f=NULL;
}
return f;
}
static struct PyMethodDef ThreadLock_methods[] = {
{"guarded_apply", (PyCFunction)call_method, 1,
"guarded_apply(FUNCTION, ARGS[, KEYWORDS]) -- Make a guarded function call\n"
"\n"
"Acquire the lock, call the function, and then release the lock.\n"
},
{"acquire", (PyCFunction)acquire, 1,
"acquire([wait]) -- Acquire a lock, taking the thread ID into account"
},
{"release", (PyCFunction)release, 1,
"release() -- Release a lock, taking the thread ID into account"
},
{NULL, NULL} /* sentinel */
};
static void
ThreadLock_dealloc(ThreadLockObject *self)
{
#ifdef WITH_THREAD
free_lock(self->lock);
#endif
PyObject_DEL(self);
}
static PyObject *
ThreadLock_getattr(ThreadLockObject *self, PyObject *name)
{
char *cname;
if((cname=PyString_AsString(name)))
{
if(*cname=='c' && strcmp(cname,"count")==0)
return PyInt_FromLong(self->count);
if(*cname=='i' && strcmp(cname,"id")==0)
return PyInt_FromLong(self->id);
return Py_FindMethod(ThreadLock_methods, (PyObject *)self, cname);
}
PyErr_SetObject(PyExc_AttributeError, name);
return NULL;
}
static PyTypeObject ThreadLockType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"ThreadLock", /*tp_name*/
sizeof(ThreadLockObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)ThreadLock_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
(getattrfunc)0, /*obsolete tp_getattr*/
(setattrfunc)0, /*obsolete tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
(hashfunc)0, /*tp_hash*/
(ternaryfunc)0, /*tp_call*/
(reprfunc)0, /*tp_str*/
(getattrofunc)ThreadLock_getattr, /*tp_getattro*/
0, /*tp_setattro*/
/* Space for future expansion */
0L,0L,
"Thread-based lock objects\n"
"\n"
"These lock objects may be allocated multiple times by the same\n"
"thread, but may only be allocated by one thread at a time.\n"
"This is useful for locking instances in possibly nested method calls\n"
};
static PyObject *
newThreadLockObject(ThreadLockObject *self, PyObject *args)
{
UNLESS(PyArg_ParseTuple(args,"")) return NULL;
UNLESS(self = PyObject_NEW(ThreadLockObject, &ThreadLockType)) return NULL;
self->count=-1;
#ifdef WITH_THREAD
self->lock = allocate_lock();
if (self->lock == NULL) {
PyObject_DEL(self);
self = NULL;
PyErr_SetString(ErrorObject, "can't allocate lock");
}
#endif
return (PyObject*)self;
}
static PyObject *
ident(PyObject *self, PyObject *args)
{
#ifdef WITH_THREAD
return PyInt_FromLong(get_thread_ident());
#else
return PyInt_FromLong(0);
#endif
}
static struct PyMethodDef Module_methods[] = {
{ "allocate_lock", (PyCFunction)newThreadLockObject, 1,
"allocate_lock() -- Return a new lock object"
},
{ "get_ident", (PyCFunction)ident, 1,
"get_ident() -- Get the id of the current thread"
},
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
void
init_ThreadLock(void)
{
PyObject *m, *d;
m = Py_InitModule4("_ThreadLock", Module_methods,
ThreadLock_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
d = PyModule_GetDict(m);
ThreadLockType.ob_type=&PyType_Type;
PyDict_SetItemString(d,"ThreadLockType", (PyObject*)&ThreadLockType);
ErrorObject = PyString_FromString("ThreadLock.error");
PyDict_SetItemString(d, "error", ErrorObject);
#ifdef WITH_THREAD
PyDict_SetItemString(d, "WITH_THREAD", PyInt_FromLong(1));
#else
PyDict_SetItemString(d, "WITH_THREAD", Py_None);
#endif
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize module ThreadLock");
}
from _ThreadLock import *
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (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.
#
##############################################################################
"""ThreadLock tests
>>> lock = ThreadLock.allocate_lock()
>>> twoshouldstart = threading.Event()
>>> n = 0
>>> readbytwo = None
>>> def one():
... global n
... lock.acquire()
... twoshouldstart.set()
... for i in range(10):
... time.sleep(.001)
... lock.acquire()
... n += 1
...
... for i in range(10):
... time.sleep(.001)
... lock.release()
...
... lock.release()
>>> def two():
... global readbytwo
... twoshouldstart.wait()
... lock.acquire()
... readbytwo = n
... lock.release()
>>> ttwo = threading.Thread(target=two)
>>> ttwo.start()
>>> time.sleep(0.001)
>>> tone = threading.Thread(target=one)
>>> tone.start()
>>> tone.join()
>>> ttwo.join()
>>> readbytwo
10
$Id: tests.py,v 1.2 2003/11/28 16:46:39 jim Exp $
"""
import ThreadLock, threading, time
import unittest
from doctest import DocTestSuite
def test_suite():
return unittest.TestSuite((
DocTestSuite(),
))
if __name__ == '__main__': unittest.main()
##############################################################################
#
# 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.1 (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.
#
##############################################################################
from _initgroups import initgroups
/*****************************************************************************
Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (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
****************************************************************************/
#include "Python.h"
#if defined(__unix__) || defined(unix) || defined(__NetBSD__) || defined(__MACH__) /* Mac OS X */
#include <grp.h>
#include <sys/types.h>
#include <unistd.h>
static PyObject *
initgroups_initgroups(PyObject *self, PyObject *args)
{
char *username;
unsigned int igid;
gid_t gid;
if (!PyArg_ParseTuple(args, "sI:initgroups", &username, &igid))
return NULL;
gid = igid;
if (initgroups(username, gid) == -1)
return PyErr_SetFromErrno(PyExc_OSError);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef InitgroupsMethods[] = {
{"initgroups", initgroups_initgroups, METH_VARARGS},
{NULL, NULL}
};
#else
/* This module is empty on non-UNIX systems. */
static PyMethodDef InitgroupsMethods[] = {
{NULL, NULL}
};
#endif /* defined(__unix__) || defined(unix) */
void
init_initgroups(void)
{
Py_InitModule("_initgroups", InitgroupsMethods);
}
......@@ -8,16 +8,21 @@ DateTime = 2.12.0
distribute = 0.6.10
docutils = 0.6
ExtensionClass = 2.13.0
initgroups = 2.13.0
Jinja2 = 2.3.1
mechanize = 0.1.11
Missing = 2.13.0
MultiMapping = 2.13.0
Persistence = 2.13.0
Pygments = 1.3.1
python-gettext = 1.0
pytz = 2010b
Record = 2.13.0
RestrictedPython = 3.5.1
Sphinx = 0.6.5
setuptools= 0.6c11
tempstorage = 2.11.2
ThreadLock = 2.13.0
tl.eggdeps = 0.4
transaction = 1.0.0
z3c.recipe.depgraph = 0.5
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment