[Zope3-checkins] CVS: Zope3/lib/python/Zope/Proxy - proxy.c:1.1 setup.py:1.1

Fred L. Drake, Jr. fdrake@acm.org
Tue, 13 Aug 2002 13:21:30 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Proxy
In directory cvs.zope.org:/tmp/cvs-serv15998/lib/python/Zope/Proxy

Added Files:
	proxy.c setup.py 
Log Message:
Move the proxy base class implementation from Zope.ContextWrapper to
Zope.Proxy.


=== Added File Zope3/lib/python/Zope/Proxy/proxy.c === (670/770 lines abridged)
#include "Python.h"
#include "modsupport.h"

#define PROXY_MODULE
#include "Zope/Proxy/proxy.h"

static PyTypeObject ProxyType;

#define Proxy_Check(wrapper)   (PyObject_TypeCheck((wrapper), &ProxyType))

static PyObject *
empty_tuple = NULL;


/*
 *   Slot methods.
 */

static PyObject *
wrap_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    PyObject *result = NULL;
    PyObject *object;

    if (PyArg_UnpackTuple(args, "__new__", 1, 1, &object)) {
        if (kwds != NULL && PyDict_Size(kwds) != 0) {
            PyErr_SetString(PyExc_TypeError,
                            "proxy.__new__ does not accept keyword args");
            return NULL;
        }
        result = PyType_GenericNew(type, args, kwds);
        if (result != NULL) {
            ProxyObject *wrapper = (ProxyObject *) result;
            Py_INCREF(object);
            wrapper->proxy_object = object;
        }
    }
    return result;
}

static int
wrap_init(PyObject *self, PyObject *args, PyObject *kwds)
{
    int result = -1;
    PyObject *object;

    if (PyArg_UnpackTuple(args, "__init__", 1, 1, &object)) {
        ProxyObject *wrapper = (ProxyObject *)self;
        if (kwds != NULL && PyDict_Size(kwds) != 0) {
            PyErr_SetString(PyExc_TypeError,

[-=- -=- -=- 670 lines omitted -=- -=- -=-]

    }
    else
        PyErr_Format(PyExc_TypeError,
		     "expected proxy, got %s", obj->ob_type->tp_name);
    return result;
}

static PyMethodDef
module_functions[] = {
    {"getobject", wrapper_getobject, METH_O, getobject__doc__},
    {NULL}
};

static char
module___doc__[] =
"Association between an object, a context object, and a dictionary.\n\
\n\
The context object and dictionary give additional context information\n\
associated with a reference to the basic object.  The wrapper objects\n\
act as proxies for the original object.";


void
initproxy(void)
{
    PyObject *m = Py_InitModule3("proxy", module_functions, module___doc__);

    if (m == NULL)
        return;

    if (empty_tuple == NULL)
        empty_tuple = PyTuple_New(0);

    ProxyType.ob_type = &PyType_Type;
    ProxyType.tp_alloc = PyType_GenericAlloc;
    ProxyType.tp_free = _PyObject_GC_Del;
    if (PyType_Ready(&ProxyType) < 0)
        return;

    Py_INCREF(&ProxyType);
    PyModule_AddObject(m, "proxy", (PyObject *)&ProxyType);

    if (api_object == NULL) {
        api_object = PyCObject_FromVoidPtr(&wrapper_capi, NULL);
        if (api_object == NULL)
            return;
    }
    Py_INCREF(api_object);
    PyModule_AddObject(m, "_CAPI", api_object);
}


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

from distutils.core import setup, Extension

setup(name="Zope.Proxy", version = "0.2",
      ext_modules=[Extension("proxy", ["proxy.c"])])