Commit af2df247 authored by Hanno Schlichting's avatar Hanno Schlichting

Backported r110334:110335 from trunk - split out some packages with C dependencies

parent 8ee83a28
......@@ -41,10 +41,15 @@ eggs =
Acquisition
DateTime
ExtensionClass
five.formlib
initgroups
Missing
MultiMapping
Persistence
Record
RestrictedPython
five.formlib
tempstorage
ThreadLock
zLOG
ZopeUndo
zope.annotation
......
......@@ -15,7 +15,12 @@ Features Added
- DateTime = 2.12.1
- ExtensionClass = 2.13.1
- initgroups = 2.13.0
- Missing = 2.13.0
- MultiMapping = 2.13.0
- Persistence = 2.13.1
- Record = 2.13.0
- ThreadLock = 2.13.0
- ZODB3 = 3.9.5
Bugs Fixed
......
......@@ -11,8 +11,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Setup for the Acquisition egg package
"""
import os
from setuptools import setup, find_packages, Extension
......@@ -49,32 +48,6 @@ params = dict(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,13 +62,18 @@ params = dict(name='Zope2',
'Acquisition',
'DateTime',
'ExtensionClass',
'Missing',
'MultiMapping',
'Persistence',
'Record',
'RestrictedPython',
'ThreadLock',
'ZConfig',
'ZODB3',
'ZopeUndo',
'docutils',
'five.formlib',
'initgroups',
'pytz',
'setuptools',
'tempstorage',
......
<extension _Missing>
source _Missing.c
</extension>
/*****************************************************************************
Copyright (c) 1996-2002 Zope Foundation 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 Foundation 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 distutils.core import setup, Extension
setup(name="_Missing", version="2.0",
ext_modules=[
Extension("_Missing", ["_Missing.c"],
include_dirs = ['.', '../ExtensionClass'],
depends = ['../ExtensionClass/ExtensionClass.h']),
])
##############################################################################
#
# Copyright (c) 2003 Zope Foundation 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()
<extension _MultiMapping>
source _MultiMapping.c
</extension>
/*****************************************************************************
Copyright (c) 1996-2003 Zope Foundation 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 Foundation 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 distutils.core import setup, Extension
setup(name="_MultiMapping", version="2.0",
ext_modules=[
Extension("_MultiMapping", ["_MultiMapping.c"],
include_dirs = ['.', '../ExtensionClass'],
depends = ['../ExtensionClass/ExtensionClass.h']),
])
##############################################################################
#
# Copyright (c) 2003 Zope Foundation 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()
<extension _Record>
source _Record.c
</extension>
/*****************************************************************************
Copyright (c) 1996-2002 Zope Foundation 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 Record_module_documentation[] =
""
"\n$Id: _Record.c,v 1.2 2003/11/28 16:46:36 jim Exp $"
;
#include "ExtensionClass/ExtensionClass.h"
/* ----------------------------------------------------- */
static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#define ASSIGN(V,E) PyVar_Assign(&(V),(E))
#define UNLESS(E) if(!(E))
#define UNLESS_ASSIGN(V,E) ASSIGN(V,E); UNLESS(V)
#define OBJECT(O) ((PyObject*)(O))
static PyObject *py___record_schema__;
/* Declarations for objects of type Record */
typedef struct {
PyObject_HEAD
PyObject **data;
PyObject *schema;
} Record;
staticforward PyExtensionClass RecordType;
/* ---------------------------------------------------------------- */
static int
Record_init(Record *self)
{
int l;
UNLESS(self->schema)
UNLESS(self->schema=PyObject_GetAttr(OBJECT(self->ob_type),
py___record_schema__)) return -1;
if((l=PyObject_Length(self->schema)) < 0) return -1;
UNLESS(self->data)
{
UNLESS(self->data=malloc(sizeof(PyObject*)*(l+1)))
{
PyErr_NoMemory();
return -1;
}
memset(self->data, 0, sizeof(PyObject*)*(l+1));
}
return l;
}
static PyObject *
Record___setstate__(Record *self, PyObject *args)
{
PyObject *state=0, *parent, **d;
int l, ls, i;
if((l=Record_init(self)) < 0) return NULL;
UNLESS(PyArg_ParseTuple(args, "|OO", &state, &parent)) return NULL;
if(state) {
if(PyDict_Check(state))
{
PyObject *k, *v;
for(i=0; PyDict_Next(state, &i, &k, &v);)
if(k && v && PyObject_SetAttr(OBJECT(self),k,v) < 0)
PyErr_Clear();
}
else
{
if((ls=PyObject_Length(state)) < 0) return NULL;
for(i=0, d=self->data; i < l && i < ls; i++, d++)
{
ASSIGN(*d, PySequence_GetItem(state, i));
UNLESS(*d) return NULL;
}
}
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
Record___getstate__( Record *self, PyObject *args)
{
PyObject *r, **d, *v;
int i, l;
UNLESS(self->data) return PyTuple_New(0);
if((l=Record_init(self)) < 0) return NULL;
UNLESS(r=PyTuple_New(l)) return NULL;
for(d=self->data, i=0; i < l; i++, d++)
{
v= *d;
if(!v) v=Py_None;
Py_INCREF(v);
PyTuple_SET_ITEM(r,i,v);
}
return r;
}
static void
Record_deal(Record *self)
{
int l;
PyObject **d;
if(self->schema)
{
l=PyObject_Length(self->schema);
for(d=self->data; --l >= 0; d++)
{
Py_XDECREF(*d);
}
Py_DECREF(self->schema);
free(self->data);
}
}
static struct PyMethodDef Record_methods[] = {
{"__getstate__", (PyCFunction)Record___getstate__, METH_VARARGS,
"__getstate__() -- Get the record's data"
},
{"__setstate__", (PyCFunction)Record___setstate__, METH_VARARGS,
"__setstate__(v) -- Set the record's data"
},
{"__init__", (PyCFunction)Record___setstate__, METH_VARARGS,
"__init__([v]) -- Initialize a record, possibly with state"
},
{NULL, NULL} /* sentinel */
};
/* ---------- */
static void
Record_dealloc(Record *self)
{
Record_deal(self);
Py_DECREF(self->ob_type);
PyObject_DEL(self);
}
static PyObject *
Record_getattr(Record *self, PyObject *name)
{
int l, i;
PyObject *io;
if((l=Record_init(self)) < 0) return NULL;
if ((io=Py_FindAttr((PyObject *)self, name))) return io;
PyErr_Clear();
if((io=PyObject_GetItem(self->schema, name)))
{
UNLESS(PyInt_Check(io))
{
PyErr_SetString(PyExc_TypeError, "invalid record schema");
return NULL;
}
i=PyInt_AsLong(io);
if(i >= 0 && i < l)
{
ASSIGN(io, self->data[i]);
UNLESS(io) io=Py_None;
}
else ASSIGN(io, Py_None);
Py_INCREF(io);
return io;
}
PyErr_SetObject(PyExc_AttributeError, name);
return NULL;
}
static int
Record_setattr(Record *self, PyObject *name, PyObject *v)
{
int l, i;
PyObject *io;
if((l=Record_init(self)) < 0) return -1;
if((io=PyObject_GetItem(self->schema, name)))
{
UNLESS(PyInt_Check(io))
{
PyErr_SetString(PyExc_TypeError, "invalid record schema");
return -1;
}
i=PyInt_AsLong(io);
Py_DECREF(io);
if(i >= 0 && i < l)
{
Py_XINCREF(v);
ASSIGN(self->data[i],v);
return 0;
}
}
PyErr_SetObject(PyExc_AttributeError, name);
return -1;
}
static int
Record_compare(Record *v, Record *w)
{
int lv, lw, i, c;
PyObject **dv, **dw;
if((lv=Record_init(v)) < 0) return -1;
if((lw=Record_init(w)) < 0) return -1;
if(lw < lv) lv=lw;
for(i=0, dv=v->data, dw=w->data; i < lv; i++, dv++, dw++)
{
if(*dv)
if(*dw)
{
if((c=PyObject_Compare(*dv,*dw))) return c;
}
else return 1;
else if(*dw) return -1;
}
if(*dv) return 1;
if(*dw) return -1;
return 0;
}
/* Code to handle accessing Record objects as sequence objects */
static PyObject *
Record_concat(Record *self, PyObject *bb)
{
PyErr_SetString(PyExc_TypeError,
"Record objects do not support concatenation");
return NULL;
}
static PyObject *
Record_repeat(Record *self, int n)
{
PyErr_SetString(PyExc_TypeError,
"Record objects do not support repetition");
return NULL;
}
static PyObject *
IndexError(int i)
{
PyObject *v;
if((v=PyInt_FromLong(i)))
{
PyErr_SetObject(PyExc_IndexError, v);
Py_DECREF(v);
}
return NULL;
}
static PyObject *
Record_item(Record *self, int i)
{
PyObject *o;
int l;
if((l=Record_init(self)) < 0) return NULL;
if(i < 0 || i >= l) return IndexError(i);
o=self->data[i];
UNLESS(o) o=Py_None;
Py_INCREF(o);
return o;
}
static PyObject *
Record_slice(Record *self, int ilow, int ihigh)
{
PyErr_SetString(PyExc_TypeError,
"Record objects do not support slicing");
return NULL;
}
static int
Record_ass_item(Record *self, int i, PyObject *v)
{
int l;
if((l=Record_init(self)) < 0) return -1;
if(i < 0 || i >= l)
{
IndexError(i);
return -1;
}
UNLESS(v)
{
PyErr_SetString(PyExc_TypeError,"cannot delete record items");
return -1;
}
Py_INCREF(v);
ASSIGN(self->data[i], v);
return 0;
}
static int
Record_ass_slice(Record *self, int ilow, int ihigh, PyObject *v)
{
PyErr_SetString(PyExc_TypeError,
"Record objects do not support slice assignment");
return -1;
}
static PySequenceMethods Record_as_sequence = {
(inquiry)Record_init, /*sq_length*/
(binaryfunc)Record_concat, /*sq_concat*/
(intargfunc)Record_repeat, /*sq_repeat*/
(intargfunc)Record_item, /*sq_item*/
(intintargfunc)Record_slice, /*sq_slice*/
(intobjargproc)Record_ass_item, /*sq_ass_item*/
(intintobjargproc)Record_ass_slice, /*sq_ass_slice*/
};
/* -------------------------------------------------------------- */
static PyObject *
Record_subscript(Record *self, PyObject *key)
{
int i, l;
PyObject *io;
if((l=Record_init(self)) < 0) return NULL;
if(PyInt_Check(key))
{
i=PyInt_AsLong(key);
if(i<0) i+=l;
return Record_item(self, i);
}
if((io=PyObject_GetItem(self->schema, key)))
{
UNLESS(PyInt_Check(io))
{
PyErr_SetString(PyExc_TypeError, "invalid record schema");
return NULL;
}
i=PyInt_AsLong(io);
if(i >= 0 && i < l)
{
ASSIGN(io, self->data[i]);
UNLESS(io) io=Py_None;
}
else ASSIGN(io, Py_None);
Py_INCREF(io);
return io;
}
PyErr_Clear();
if ((io=PyObject_GetAttr(OBJECT(self), key))) return io;
PyErr_SetObject(PyExc_KeyError, key);
return NULL;
}
static int
Record_ass_sub(Record *self, PyObject *key, PyObject *v)
{
int i, l;
PyObject *io;
if((l=Record_init(self)) < 0) return -1;
if(PyInt_Check(key))
{
i=PyInt_AsLong(key);
if(i<0) i+=l;
return Record_ass_item(self, i, v);
}
if((io=PyObject_GetItem(self->schema, key)))
{
UNLESS(PyInt_Check(io))
{
PyErr_SetString(PyExc_TypeError, "invalid record schema");
return -1;
}
i=PyInt_AsLong(io);
Py_DECREF(io);
if(i >= 0 && i < l)
{
Py_XINCREF(v);
ASSIGN(self->data[i],v);
return 0;
}
}
return -1;
}
static PyMappingMethods Record_as_mapping = {
(inquiry)Record_init, /*mp_length*/
(binaryfunc)Record_subscript, /*mp_subscript*/
(objobjargproc)Record_ass_sub, /*mp_ass_subscript*/
};
/* -------------------------------------------------------- */
static PyExtensionClass RecordType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"Record", /*tp_name*/
sizeof(Record), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)Record_dealloc, /*tp_dealloc*/
(printfunc)0, /*tp_print*/
(getattrfunc)0, /*obsolete tp_getattr*/
(setattrfunc)0, /*obsolete tp_setattr*/
(cmpfunc)Record_compare, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
&Record_as_sequence, /*tp_as_sequence*/
&Record_as_mapping, /*tp_as_mapping*/
(hashfunc)0, /*tp_hash*/
(ternaryfunc)0, /*tp_call*/
(reprfunc)0, /*tp_str*/
(getattrofunc)Record_getattr, /*tp_getattro*/
(setattrofunc)Record_setattr, /*tp_setattro*/
/* Space for future expansion */
0L,0L,
"Simple Record Types", /* Documentation string */
METHOD_CHAIN(Record_methods),
(void*)(EXTENSIONCLASS_NOINSTDICT_FLAG),
};
/* End of code for Record objects */
/* -------------------------------------------------------- */
/* List of methods defined in the module */
static struct PyMethodDef Module_Level__methods[] = {
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
};
/* Initialization function for the module (*must* be called initRecord) */
void
init_Record(void)
{
PyObject *m, *d;
UNLESS(py___record_schema__=PyString_FromString("__record_schema__")) return;
UNLESS(ExtensionClassImported) return;
/* Create the module and add the functions */
m = Py_InitModule4("_Record", Module_Level__methods,
Record_module_documentation,
(PyObject*)NULL,PYTHON_API_VERSION);
/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"Record",RecordType);
}
##############################################################################
#
# Copyright (c) 2003 Zope Foundation 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 Foundation 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 distutils.core import setup, Extension
setup(name="_Record", version="2.0",
ext_modules=[
Extension("_Record", ["_Record.c"],
include_dirs = ['.', '../ExtensionClass'],
depends = ['../ExtensionClass/ExtensionClass.h']),
])
##############################################################################
#
# Copyright (c) 2003 Zope Foundation 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()
<extension _ThreadLock>
source _ThreadLock.c
</extension>
/*****************************************************************************
Copyright (c) 1996-2003 Zope Foundation 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 Foundation 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 distutils.core import setup, Extension
setup(name="_ThreadLock", version="2.0",
ext_modules=[
Extension("_ThreadLock", ["_ThreadLock.c"],
include_dirs = ['.', '../ExtensionClass'],
depends = ['../ExtensionClass/ExtensionClass.h']),
])
##############################################################################
#
# Copyright (c) 2003 Zope Foundation 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()
<extension _initgroups>
source _initgroups.c
</extension>
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Foundation 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 Foundation and Contributors.
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);
}
......@@ -10,15 +10,23 @@ distribute = 0.6.10
docutils = 0.6
ExtensionClass = 2.13.1
five.formlib = 1.0.2
initgroups = 2.13.0
Jinja2 = 2.4.1
lxml = 2.2
mechanize = 0.1.11
Missing = 2.13.0
MultiMapping = 2.13.0
Persistence = 2.13.1
Pygments = 1.3.1
python-gettext = 1.0
pytz = 2010b
Record = 2.13.0
RestrictedPython = 3.5.1
roman = 1.4.0
setuptools = 0.6c11
Sphinx = 0.6.5
tempstorage = 2.11.2
ThreadLock = 2.13.0
transaction = 1.0.0
zc.buildout = 1.4.3
zc.lockfile = 1.0.0
......
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