CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 17 Jul 2025 06:48:48 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071208093420
location: https://web.archive.org/web/20071208093420/https://wiki.python.org/moin/CAPI_CookBook
server-timing: captures_list;dur=0.716485, exclusion.robots;dur=0.023710, exclusion.robots.policy;dur=0.010733, esindex;dur=0.013005, cdx.remote;dur=27.881607, LoadShardBlock;dur=135.662034, PetaboxLoader3.datanode;dur=126.681402
x-app-server: wwwb-app203
x-ts: 302
x-tr: 201
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app203; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Thu, 17 Jul 2025 06:48:49 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Sat, 08 Dec 2007 09:34:20 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 08 Dec 2007 09:34:20 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sat, 08 Dec 2007 09:34:20 GMT", ; rel="memento"; datetime="Sat, 08 Dec 2007 09:34:20 GMT", ; rel="last memento"; datetime="Sat, 08 Dec 2007 09:34:20 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_1_20071208084132_crawl105-c/52_1_20071208093411_crawl107.arc.gz
server-timing: captures_list;dur=0.458781, exclusion.robots;dur=0.017520, exclusion.robots.policy;dur=0.007356, esindex;dur=0.009438, cdx.remote;dur=17.971419, LoadShardBlock;dur=263.487004, PetaboxLoader3.datanode;dur=261.691205, load_resource;dur=156.260503, PetaboxLoader3.resolve;dur=72.086539
x-app-server: wwwb-app203
x-ts: 200
x-tr: 475
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
CAPI CookBook - PythonInfo Wiki
CAPI CookBook
Describe CAPI CookBook here.
Functions for returning an error with one call
PyObject *EXPP_ReturnPyObjError( PyObject * type, char *error_msg ) { /* same as above, just to change its name smoothly */ PyErr_SetString( type, error_msg ); return NULL; }
int EXPP_ReturnIntError( PyObject * type, char *error_msg ) { PyErr_SetString( type, error_msg ); return -1; }
Return in incremented reference
PyObject *EXPP_incr_ret( PyObject * object ) { Py_INCREF( object ); return ( object ); }
Check sequence type
/*****************************************************************************/ /* Description: Checks whether all objects in a PySequence are of a same */ /* given type. Returns 0 if not, 1 on success. */ /*****************************************************************************/ int EXPP_check_sequence_consistency( PyObject * seq, PyTypeObject * against ) { PyObject *ob; int len = PySequence_Length( seq ); int i, result = 1; for( i = 0; i < len; i++ ) { ob = PySequence_GetItem( seq, i ); if( ob == Py_None ) result = 2; else if( ob->ob_type != against ) { Py_DECREF( ob ); return 0; } Py_DECREF( ob ); } return result; /* 1 if all of 'against' type, 2 if there are (also) Nones */ }
Tuple Prepend
/* * Helper function for subtypes that use the base types methods. * The command below needs to have args modified to have 'self' added at the start * ret = PyObject_Call(PyDict_GetItemString(PyList_Type.tp_dict, "sort"), args, keywds); * * This is not easy with the python API so adding a function here, * remember to Py_DECREF the tuple after */ PyObject * EXPP_PyTuple_New_Prepend(PyObject *tuple, PyObject *value) { PyObject *item; PyObject *new_tuple; int i; i = PyTuple_Size(tuple); new_tuple = PyTuple_New(i+1); PyTuple_SetItem(new_tuple, 0, value); Py_INCREF(value); while (i) { i--; item = PyTuple_GetItem(tuple, i); PyTuple_SetItem(new_tuple, i+1, item); Py_INCREF(item); } return new_tuple; }
Methods into dictionary
/* this function adds methods to a dictionary. * in cases where the methods do not go into a module as is useual * - for instance if you want to add methods to a type */ void EXPP_PyMethodsToDict(PyObject *dict, struct PyMethodDef *meth) { PyObject *value; while (meth->ml_name) { value = PyCFunction_New(meth, NULL); PyDict_SetItemString(dict, meth->ml_name, value); Py_DECREF(value); meth++; } }
Anonymous Pointer Comparison
add to the header...
/* for anonymous comparisons */ typedef struct { PyObject_HEAD void * pointer; } BPyAnonymousObject;
comparison function...
/* * This is to compare any 2 types that have a pointer directly after the * PyObject in their struct, this covers quite a few. * */ int EXPP_Anonymous_compare( BPyAnonymousObject * a, BPyAnonymousObject * b ) { return ( a->pointer == b->pointer) ? 0 : -1; }
EditText (last edited 2007-09-06 23:54:38 by d58-104-15-14)
DeleteCache (cached 2007-11-21 07:45:28)- Login
- Navigation
- Actions
- Your recent pages