Back to index

python3.2  3.2.2
Defines | Functions | Variables
microprotocols.h File Reference
#include <Python.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define MICROPROTOCOLS_GETQUOTED_NAME   "getquoted"
 the names of the three mandatory methods
#define MICROPROTOCOLS_GETSTRING_NAME   "getstring"
#define MICROPROTOCOLS_GETBINARY_NAME   "getbinary"
#define pysqlite_adapt_doc   "adapt(obj, protocol, alternate) -> adapt obj to given protocol. Non-standard."

Functions

int pysqlite_microprotocols_init (PyObject *dict)
 exported functions
int pysqlite_microprotocols_add (PyTypeObject *type, PyObject *proto, PyObject *cast)
PyObjectpysqlite_microprotocols_adapt (PyObject *obj, PyObject *proto, PyObject *alt)
PyObjectpysqlite_adapt (pysqlite_Cursor *self, PyObject *args)
 module-level functions

Variables

PyObjectpsyco_adapters
 adapters registry

Define Documentation

#define MICROPROTOCOLS_GETBINARY_NAME   "getbinary"

Definition at line 39 of file microprotocols.h.

#define MICROPROTOCOLS_GETQUOTED_NAME   "getquoted"

the names of the three mandatory methods

Definition at line 37 of file microprotocols.h.

#define MICROPROTOCOLS_GETSTRING_NAME   "getstring"

Definition at line 38 of file microprotocols.h.

#define pysqlite_adapt_doc   "adapt(obj, protocol, alternate) -> adapt obj to given protocol. Non-standard."

Definition at line 52 of file microprotocols.h.


Function Documentation

PyObject* pysqlite_adapt ( pysqlite_Cursor self,
PyObject args 
)

module-level functions

Definition at line 135 of file microprotocols.c.

{
    PyObject *obj, *alt = NULL;
    PyObject *proto = (PyObject*)&pysqlite_PrepareProtocolType;

    if (!PyArg_ParseTuple(args, "O|OO", &obj, &proto, &alt)) return NULL;
    return pysqlite_microprotocols_adapt(obj, proto, alt);
}

Here is the call graph for this function:

PyObject* pysqlite_microprotocols_adapt ( PyObject obj,
PyObject proto,
PyObject alt 
)

Definition at line 76 of file microprotocols.c.

{
    PyObject *adapter, *key;

    /* we don't check for exact type conformance as specified in PEP 246
       because the pysqlite_PrepareProtocolType type is abstract and there is no
       way to get a quotable object to be its instance */

    /* look for an adapter in the registry */
    key = Py_BuildValue("(OO)", (PyObject*)obj->ob_type, proto);
    if (!key) {
        return NULL;
    }
    adapter = PyDict_GetItem(psyco_adapters, key);
    Py_DECREF(key);
    if (adapter) {
        PyObject *adapted = PyObject_CallFunctionObjArgs(adapter, obj, NULL);
        return adapted;
    }

    /* try to have the protocol adapt this object*/
    if (PyObject_HasAttrString(proto, "__adapt__")) {
        PyObject *adapted = PyObject_CallMethod(proto, "__adapt__", "O", obj);
        if (adapted) {
            if (adapted != Py_None) {
                return adapted;
            } else {
                Py_DECREF(adapted);
            }
        }

        if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_TypeError))
            return NULL;
    }

    /* and finally try to have the object adapt itself */
    if (PyObject_HasAttrString(obj, "__conform__")) {
        PyObject *adapted = PyObject_CallMethod(obj, "__conform__","O", proto);
        if (adapted) {
            if (adapted != Py_None) {
                return adapted;
            } else {
                Py_DECREF(adapted);
            }
        }

        if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_TypeError)) {
            return NULL;
        }
    }

    /* else set the right exception and return NULL */
    PyErr_SetString(pysqlite_ProgrammingError, "can't adapt");
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pysqlite_microprotocols_add ( PyTypeObject type,
PyObject proto,
PyObject cast 
)

Definition at line 55 of file microprotocols.c.

{
    PyObject* key;
    int rc;

    if (proto == NULL) proto = (PyObject*)&pysqlite_PrepareProtocolType;

    key = Py_BuildValue("(OO)", (PyObject*)type, proto);
    if (!key) {
        return -1;
    }

    rc = PyDict_SetItem(psyco_adapters, key, cast);
    Py_DECREF(key);

    return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

exported functions

Definition at line 41 of file microprotocols.c.

{
    /* create adapters dictionary and put it in module namespace */
    if ((psyco_adapters = PyDict_New()) == NULL) {
        return -1;
    }

    return PyDict_SetItemString(dict, "adapters", psyco_adapters);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

adapters registry

Definition at line 36 of file microprotocols.c.