Changeset 1dcfd1f
- Timestamp:
- 2013-03-19T20:30:24Z (12 years ago)
- Children:
- 76ca5cb
- Parents:
- 26f3b5f
- Location:
- protocols/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/python/examples/sampleplugin.py
r26f3b5f r1dcfd1f 9 9 print "hello, I'm a test plugin running on Python", sys.version_info 10 10 11 print bpython.Protocol Plugin12 print bpython.Protocol Plugin()11 print bpython.Protocol 12 print bpython.Protocol() 13 13 print bpython.register_protocol 14 14 15 15 try: 16 class MyProtocol(bpython.Protocol Plugin):16 class MyProtocol(bpython.Protocol): 17 17 pass 18 18 except Exception, e: -
protocols/python/src/bpython.c
r26f3b5f r1dcfd1f 23 23 */ 24 24 25 #include <bitlbee.h>26 25 #include <Python.h> 27 26 #include "bytesobject.h" 27 #include "structmember.h" 28 29 #include <bitlbee.h> 28 30 29 31 /* Python module classes: */ … … 31 33 typedef struct { 32 34 PyObject_HEAD 33 34 } bpython_ProtocolObject; 35 36 static PyTypeObject bpython_ProtocolType = { 35 PyObject * name; /* protocol name */ 36 } Protocol; 37 38 static void Protocol_dealloc(Protocol * self) { 39 Py_XDECREF(self->name); 40 self->ob_type->tp_free((PyObject*)self); 41 } 42 43 static PyObject * Protocol_new(PyTypeObject * type, PyObject * args, PyObject * kwds) { 44 Protocol * self; 45 46 self = (Protocol *)type->tp_alloc(type, 0); 47 if (self != NULL) { 48 self->name = PyString_FromString("unnamed"); 49 if (self->name == NULL) { 50 Py_DECREF(self); 51 return NULL; 52 } 53 } 54 55 return (PyObject *)self; 56 } 57 58 static int Protocol_init(Protocol *self, PyObject *args, PyObject *kwds) 59 { 60 PyObject * name; 61 PyObject * tmp; 62 63 static char *kwlist[] = {"name", NULL}; 64 65 if (! PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, 66 &name)) 67 return -1; 68 69 if (name) { 70 tmp = self->name; 71 Py_INCREF(name); 72 self->name = name; 73 Py_XDECREF(tmp); 74 } 75 76 return 0; 77 } 78 79 static PyMemberDef Protocol_members[] = { 80 {"name", T_OBJECT_EX, offsetof(Protocol, name), 0, 81 "protocol name (used in 'account add')"}, 82 {NULL} /* Sentinel */ 83 }; 84 85 86 static PyMethodDef Protocol_methods[] = { 87 //{"name", (PyCFunction)Noddy_name, METH_NOARGS, 88 // "Return the name, combining the first and last name" 89 //}, 90 {NULL} /* Sentinel */ 91 }; 92 93 94 static PyTypeObject ProtocolType = { 37 95 PyObject_HEAD_INIT(NULL) 38 96 0, /*ob_size*/ 39 97 "bpython.Protocol", /*tp_name*/ 40 sizeof( bpython_ProtocolObject), /*tp_basicsize*/98 sizeof(Protocol), /*tp_basicsize*/ 41 99 0, /*tp_itemsize*/ 42 0,/*tp_dealloc*/100 (destructor)Protocol_dealloc, /*tp_dealloc*/ 43 101 0, /*tp_print*/ 44 102 0, /*tp_getattr*/ … … 55 113 0, /*tp_setattro*/ 56 114 0, /*tp_as_buffer*/ 57 Py_TPFLAGS_DEFAULT , /*tp_flags*/115 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ 58 116 "Protocol plugin objects", /* tp_doc */ 117 0, /* tp_traverse */ 118 0, /* tp_clear */ 119 0, /* tp_richcompare */ 120 0, /* tp_weaklistoffset */ 121 0, /* tp_iter */ 122 0, /* tp_iternext */ 123 Protocol_methods, /* tp_methods */ 124 Protocol_members, /* tp_members */ 125 0, /* tp_getset */ 126 0, /* tp_base */ 127 0, /* tp_dict */ 128 0, /* tp_descr_get */ 129 0, /* tp_descr_set */ 130 0, /* tp_dictoffset */ 131 (initproc)Protocol_init, /* tp_init */ 132 0, /* tp_alloc */ 133 Protocol_new, /* tp_new */ 59 134 }; 60 135 … … 72 147 } 73 148 74 static PyMethodDef BpythonMethods[] = {149 static PyMethodDef bpython_methods[] = { 75 150 {"register_protocol", bpython_register_protocol, METH_VARARGS, 76 151 "Register a protocol."}, … … 82 157 PyObject * m; 83 158 84 bpython_ProtocolType.tp_new = PyType_GenericNew;85 if (PyType_Ready(& bpython_ProtocolType) < 0) {86 return; 87 } 88 89 m = Py_InitModule3("bpython", BpythonMethods, "Bitlbee Plugin module");90 91 Py_INCREF(& bpython_ProtocolType);92 PyModule_AddObject(m, "Protocol", (PyObject *)& bpython_ProtocolType);159 ProtocolType.tp_new = PyType_GenericNew; 160 if (PyType_Ready(&ProtocolType) < 0) { 161 return; 162 } 163 164 m = Py_InitModule3("bpython", bpython_methods, "Bitlbee Plugin module"); 165 166 Py_INCREF(&ProtocolType); 167 PyModule_AddObject(m, "Protocol", (PyObject *)&ProtocolType); 93 168 } 94 169
Note: See TracChangeset
for help on using the changeset viewer.