Annotation of gpl/axl/py-axl/py_axl_dtd.c, revision 1.1

1.1     ! misho       1: /** 
        !             2:  *  PyAxl: Axl Library python bindings
        !             3:  *  Copyright (C) 2009 Advanced Software Production Line, S.L.
        !             4:  *
        !             5:  *  This program is free software; you can redistribute it and/or
        !             6:  *  modify it under the terms of the GNU Lesser General Public License
        !             7:  *  as published by the Free Software Foundation; either version 2.1
        !             8:  *  of the License, or (at your option) any later version.
        !             9:  *
        !            10:  *  This program is distributed in the hope that it will be useful,
        !            11:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            13:  *  Lesser General Public License for more details.
        !            14:  *
        !            15:  *  You should have received a copy of the GNU Lesser General Public
        !            16:  *  License along with this program; if not, write to the Free
        !            17:  *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
        !            18:  *  02111-1307 USA
        !            19:  *  
        !            20:  *  You may find a copy of the license under this software is released
        !            21:  *  at COPYING file. This is LGPL software: you are welcome to develop
        !            22:  *  proprietary applications using this library without any royalty or
        !            23:  *  fee but returning back any change, improvement or addition in the
        !            24:  *  form of source code, project image, documentation patches, etc.
        !            25:  *
        !            26:  *  For commercial support for XML enabled solutions contact us:
        !            27:  *          
        !            28:  *      Postal address:
        !            29:  *         Advanced Software Production Line, S.L.
        !            30:  *         C/ Antonio Suarez Nº 10, 
        !            31:  *         Edificio Alius A, Despacho 102
        !            32:  *         Alcalá de Henares 28802 (Madrid)
        !            33:  *         Spain
        !            34:  *
        !            35:  *      Email address:
        !            36:  *         info@aspl.es - http://www.aspl.es/axl
        !            37:  */
        !            38: #include <py_axl_dtd.h>
        !            39: 
        !            40: #define LOG_DOMAIN "py-axl-dtd"
        !            41: 
        !            42: struct _PyAxlDtd {
        !            43:        /* header required to initialize python required bits for
        !            44:           every python object */
        !            45:        PyObject_HEAD
        !            46: 
        !            47:        /* pointer to the axl dtd */
        !            48:        axlDtd * dtd;
        !            49: };
        !            50: 
        !            51: static int py_axl_dtd_init_type (PyAxlDtd *self, PyObject *args, PyObject *kwds)
        !            52: {
        !            53:     return 0;
        !            54: }
        !            55: 
        !            56: /** 
        !            57:  * @brief Function used to allocate memory required by the object
        !            58:  * axl.Dtd
        !            59:  */
        !            60: static PyObject * py_axl_dtd_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
        !            61: {
        !            62:        PyAxlDtd *self;
        !            63: 
        !            64:        /* create the object */
        !            65:        self = (PyAxlDtd *)type->tp_alloc(type, 0);
        !            66: 
        !            67:        return (PyObject *)self;
        !            68: }
        !            69: 
        !            70: /** 
        !            71:  * @brief Function used to finish and dealloc memory used by the
        !            72:  * object axl.Dtd
        !            73:  */
        !            74: static void py_axl_dtd_dealloc (PyAxlDtd* self)
        !            75: {
        !            76: 
        !            77:        axl_dtd_free (self->dtd);
        !            78:        self->dtd = NULL;
        !            79: 
        !            80:        /* free the dtd it self */
        !            81:        self->ob_type->tp_free ((PyObject*)self);
        !            82: 
        !            83:        return;
        !            84: }
        !            85: 
        !            86: /** 
        !            87:  * @brief This function implements the generic attribute getting that
        !            88:  * allows to perform complex member resolution (not merely direct
        !            89:  * member access).
        !            90:  */
        !            91: PyObject * py_axl_dtd_get_attr (PyObject *o, PyObject *attr_name) {
        !            92:        const char      * attr = NULL;
        !            93:        PyObject        * result;
        !            94: /*     PyAxlDtd        * self = (PyAxlDtd *) o; */
        !            95: 
        !            96:        /* now implement other attributes */
        !            97:        if (! PyArg_Parse (attr_name, "s", &attr))
        !            98:                return NULL;
        !            99: 
        !           100:        __axl_log (LOG_DOMAIN, AXL_LEVEL_DEBUG, "received request to report dtd attr name %s (self: %p)",
        !           101:                   attr, o);
        !           102: 
        !           103:        /* first implement generic attr already defined */
        !           104:        result = PyObject_GenericGetAttr (o, attr_name);
        !           105:        if (result)
        !           106:                return result;
        !           107:        
        !           108:        return NULL;
        !           109: }
        !           110: 
        !           111: /** 
        !           112:  * @brief Implements attribute set operation.
        !           113:  */
        !           114: int py_axl_dtd_set_attr (PyObject *o, PyObject *attr_name, PyObject *v)
        !           115: {
        !           116:        const char      * attr = NULL;
        !           117: /*     PyAxlDtd        * self = (PyAxlDtd *) o; */
        !           118: /*     axl_bool          boolean_value = axl_false; */
        !           119: 
        !           120:        /* now implement other attributes */
        !           121:        if (! PyArg_Parse (attr_name, "s", &attr))
        !           122:                return -1;
        !           123: 
        !           124:        /* now implement generic setter */
        !           125:        return PyObject_GenericSetAttr (o, attr_name, v);
        !           126: }
        !           127: 
        !           128: static PyObject * py_axl_dtd_validate (PyObject * _self, PyObject * args)
        !           129: {
        !           130:        PyAxlDtd  * self    = (PyAxlDtd *) _self;
        !           131:        PyAxlDoc  * doc     = NULL;
        !           132:        axlError  * error   = NULL;
        !           133: 
        !           134:        /* parse and check result */
        !           135:        if (! PyArg_ParseTuple (args, "O", &doc))
        !           136:                return NULL;
        !           137: 
        !           138:        /* check doc object */
        !           139:        if (! py_axl_doc_check (__PY_OBJECT (doc))) {
        !           140:                /* set exception */
        !           141:                PyErr_SetString (PyExc_TypeError, "Expected to receive a axl.Doc object but received something different");
        !           142:                return NULL;
        !           143:        } /* end if */
        !           144: 
        !           145:        /* return none to signal no error */
        !           146:        if (axl_dtd_validate (py_axl_doc_get (__PY_OBJECT (doc)), self->dtd, &error)) {
        !           147:                Py_INCREF (Py_None);
        !           148:                return Py_None;
        !           149:        } /* end if */
        !           150:        
        !           151:        /* error found */
        !           152:        return py_axl_error_create (error);
        !           153: }
        !           154: 
        !           155: 
        !           156: static PyMethodDef py_axl_dtd_methods[] = { 
        !           157:        /* next_called */
        !           158:        {"validate", (PyCFunction) py_axl_dtd_validate, METH_VARARGS,
        !           159:         "Allows to validate a document returning an axl.Error in the case or error or None if validates ok."},
        !           160:        {NULL, NULL, 0, NULL}  
        !           161: }; 
        !           162: 
        !           163: static PyTypeObject PyAxlDtdType = {
        !           164:     PyObject_HEAD_INIT(NULL)
        !           165:     0,                         /* ob_size*/
        !           166:     "axl.Dtd",                 /* tp_name*/
        !           167:     sizeof(PyAxlDtd),       /* tp_basicsize*/
        !           168:     0,                         /* tp_itemsize*/
        !           169:     (destructor)py_axl_dtd_dealloc, /* tp_dealloc*/
        !           170:     0,                         /* tp_print*/
        !           171:     0,                         /* tp_getattr*/
        !           172:     0,                         /* tp_setattr*/
        !           173:     0,                         /* tp_compare*/
        !           174:     0,                         /* tp_repr*/
        !           175:     0,                         /* tp_as_number*/
        !           176:     0,                         /* tp_as_sequence*/
        !           177:     0,                         /* tp_as_mapping*/
        !           178:     0,                         /* tp_hash */
        !           179:     0,                         /* tp_call*/
        !           180:     0,                         /* tp_str*/
        !           181:     py_axl_dtd_get_attr,    /* tp_getattro*/
        !           182:     py_axl_dtd_set_attr,    /* tp_setattro*/
        !           183:     0,                         /* tp_as_buffer*/
        !           184:     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags*/
        !           185:     "Dtd object; wrapper of axlDtd API type",           /* tp_doc */
        !           186:     0,                        /* tp_traverse */
        !           187:     0,                        /* tp_clear */
        !           188:     0,                        /* tp_richcompare */
        !           189:     0,                        /* tp_weaklistoffset */
        !           190:     0,                        /* tp_iter */
        !           191:     0,                        /* tp_iternext */
        !           192:     py_axl_dtd_methods,     /* tp_methods */
        !           193:     0, /* py_axl_dtd_members, */     /* tp_members */
        !           194:     0,                         /* tp_getset */
        !           195:     0,                         /* tp_base */
        !           196:     0,                         /* tp_dict */
        !           197:     0,                         /* tp_descr_get */
        !           198:     0,                         /* tp_descr_set */
        !           199:     0,                         /* tp_dictoffset */
        !           200:     (initproc)py_axl_dtd_init_type,      /* tp_init */
        !           201:     0,                         /* tp_alloc */
        !           202:     py_axl_dtd_new,         /* tp_new */
        !           203: 
        !           204: };
        !           205: 
        !           206: 
        !           207: /** 
        !           208:  * @brief Allows to check if the PyObject received represents a
        !           209:  * PyAxlDtd reference.
        !           210:  */
        !           211: axl_bool             py_axl_dtd_check    (PyObject          * obj)
        !           212: {
        !           213:        /* check null references */
        !           214:        if (obj == NULL)
        !           215:                return axl_false;
        !           216: 
        !           217:        /* return check result */
        !           218:        return PyObject_TypeCheck (obj, &PyAxlDtdType);
        !           219: }
        !           220: 
        !           221: PyObject   * py_axl_dtd_create    (axlDtd * dtd)
        !           222: {
        !           223:        /* return a new instance */
        !           224:        PyAxlDtd * obj = (PyAxlDtd *) PyObject_CallObject ((PyObject *) &PyAxlDtdType, NULL); 
        !           225: 
        !           226:        /* check ref created */
        !           227:        if (obj == NULL) {
        !           228:                __axl_log (LOG_DOMAIN, AXL_LEVEL_CRITICAL, "Failed to create PyAxlDtd object, returning NULL");
        !           229:                return NULL;
        !           230:        } /* end if */
        !           231: 
        !           232:        /* set dtd if defined */
        !           233:        if (dtd)
        !           234:                obj->dtd = dtd;
        !           235: 
        !           236:        return __PY_OBJECT (obj);
        !           237: }
        !           238: 
        !           239: void        init_axl_dtd      (PyObject * module)
        !           240: {
        !           241:        /* register type */
        !           242:        if (PyType_Ready(&PyAxlDtdType) < 0)
        !           243:                return;
        !           244:        
        !           245:        Py_INCREF (&PyAxlDtdType);
        !           246:        PyModule_AddObject(module, "Dtd", (PyObject *)&PyAxlDtdType);
        !           247: 
        !           248: }
        !           249: 
        !           250: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>