Changeset 16686

Show
Ignore:
Timestamp:
06/23/08 20:28:08 (4 months ago)
Author:
piotras
Message:

Initialize metadata class explicitly.
Rename attribute setter/getter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midgard/apis/python/py_midgard_object.c

    r16685 r16686  
    9393} 
    9494 
     95PyTypeObject G_GNUC_INTERNAL Pymidgard_metadata_Type = { 
     96    PyObject_HEAD_INIT(NULL) 
     97    0,                                 /* ob_size */ 
     98    "metadata",                   /* tp_name */ 
     99    sizeof(PyGObject),          /* tp_basicsize */ 
     100    0,                                 /* tp_itemsize */ 
     101    /* methods */ 
     102    (destructor)0,        /* tp_dealloc */ 
     103    (printfunc)0,                      /* tp_print */ 
     104    (getattrfunc)0,       /* tp_getattr */ 
     105    (setattrfunc)0,       /* tp_setattr */ 
     106    (cmpfunc)0,           /* tp_compare */ 
     107    (reprfunc)0,             /* tp_repr */ 
     108    (PyNumberMethods*)0,     /* tp_as_number */ 
     109    (PySequenceMethods*)0, /* tp_as_sequence */ 
     110    (PyMappingMethods*)0,   /* tp_as_mapping */ 
     111    (hashfunc)0,             /* tp_hash */ 
     112    (ternaryfunc)0,          /* tp_call */ 
     113    (reprfunc)0,              /* tp_str */ 
     114    _py_midgard_get_object_attribute, /* tp_getattro */ 
     115    _py_midgard_set_object_attribute, /* tp_setattro */ 
     116    (PyBufferProcs*)0,  /* tp_as_buffer */ 
     117    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,                      /* tp_flags */ 
     118    NULL,                        /* Documentation string */ 
     119    (traverseproc)0,     /* tp_traverse */ 
     120    (inquiry)0,             /* tp_clear */ 
     121    (richcmpfunc)0,   /* tp_richcompare */ 
     122    offsetof(PyGObject, weakreflist),             /* tp_weaklistoffset */ 
     123    (getiterfunc)0,          /* tp_iter */ 
     124    (iternextfunc)0,     /* tp_iternext */ 
     125    (struct PyMethodDef*)NULL, /* tp_methods */ 
     126    (struct PyMemberDef*)0,              /* tp_members */ 
     127    (struct PyGetSetDef*)0,  /* tp_getset */ 
     128    NULL,                              /* tp_base */ 
     129    NULL,                              /* tp_dict */ 
     130    (descrgetfunc)0,    /* tp_descr_get */ 
     131    (descrsetfunc)0,    /* tp_descr_set */ 
     132    offsetof(PyGObject, inst_dict),                 /* tp_dictoffset */ 
     133    (initproc)0,             /* tp_init */ 
     134    (allocfunc)0,           /* tp_alloc */ 
     135    (newfunc)0,               /* tp_new */ 
     136    (freefunc)0,             /* tp_free */ 
     137    (inquiry)0              /* tp_is_gc */ 
     138}; 
     139 
     140void py_midgard_metadata_register_class( 
     141                PyObject *d, gpointer pygobject_type) 
     142{ 
     143        pygobject_register_class(d,  
     144                        "metadata",  
     145                        MIDGARD_TYPE_METADATA,  
     146                        &Pymidgard_metadata_Type,  
     147                        Py_BuildValue("(O)", pygobject_type)); 
     148 
     149        pyg_set_object_has_new_constructor(MIDGARD_TYPE_OBJECT); 
     150} 
     151 
     152 
    95153/* MgdSchema classes */ 
    96154static int __schema_object_construct(PyGObject *self, PyObject *args, PyObject *kwargs) 
     
    453511}; 
    454512 
    455 static PyMethodDef *__midgard_object_methods_pmd() 
    456 
    457         PyMethodDef *pmd = g_new(PyMethodDef, 26); 
    458          
    459         pmd[0].ml_name = "get_by_id"; 
    460         pmd[0].ml_meth = (PyCFunction)pymidgard_object_get_by_id; 
    461         pmd[0].ml_flags = METH_VARARGS; 
    462         pmd[0].ml_doc = NULL; 
    463  
    464         pmd[1].ml_name = "get_by_guid";  
    465         pmd[1].ml_meth = (PyCFunction)pymidgard_object_get_by_guid; 
    466         pmd[1].ml_flags = METH_VARARGS; 
    467         pmd[1].ml_doc = NULL; 
    468  
    469         pmd[2].ml_name = "create"; 
    470         pmd[2].ml_meth = (PyCFunction)pymidgard_object_create; 
    471         pmd[2].ml_flags = METH_VARARGS; 
    472         pmd[2].ml_doc = NULL; 
    473  
    474         pmd[3].ml_name = "update"; 
    475         pmd[3].ml_meth = (PyCFunction)pymidgard_object_update; 
    476         pmd[3].ml_flags = METH_VARARGS; 
    477         pmd[3].ml_doc = NULL; 
    478  
    479         pmd[4].ml_name = "delete"; 
    480         pmd[4].ml_meth = (PyCFunction)pymidgard_object_delete; 
    481         pmd[4].ml_flags = METH_VARARGS; 
    482         pmd[4].ml_doc = NULL; 
    483  
    484         pmd[5].ml_name = "purge"; 
    485         pmd[5].ml_meth = (PyCFunction)pymidgard_object_purge; 
    486         pmd[5].ml_flags = METH_VARARGS; 
    487         pmd[5].ml_doc = NULL; 
    488  
    489         pmd[6].ml_name = "is_in_parent_tree"; 
    490         pmd[6].ml_meth = (PyCFunction)pymidgard_object_is_in_parent_tree; 
    491         pmd[6].ml_flags = METH_VARARGS; 
    492         pmd[6].ml_doc = NULL; 
    493  
    494         pmd[7].ml_name = "is_in_tree"; 
    495         pmd[7].ml_meth = (PyCFunction)pymidgard_object_is_in_tree; 
    496         pmd[7].ml_flags = METH_VARARGS; 
    497         pmd[7].ml_doc = NULL; 
    498  
    499         pmd[8].ml_name = "get_parent"; 
    500         pmd[8].ml_meth = (PyCFunction)pymidgard_object_get_parent; 
    501         pmd[8].ml_flags = METH_VARARGS; 
    502         pmd[8].ml_doc = NULL; 
    503  
    504         pmd[9].ml_name = "parent"; 
    505         pmd[9].ml_meth = (PyCFunction)pymidgard_object_parent; 
    506         pmd[9].ml_flags = METH_VARARGS; 
    507         pmd[9].ml_doc = NULL; 
    508  
    509         pmd[10].ml_name = "list"; 
    510         pmd[10].ml_meth = (PyCFunction)pymidgard_object_list; 
    511         pmd[10].ml_flags = METH_VARARGS; 
    512         pmd[10].ml_doc = NULL; 
    513  
    514         pmd[11].ml_name = "list_children"; 
    515         pmd[11].ml_meth = (PyCFunction)pymidgard_object_list_children; 
    516         pmd[11].ml_flags = METH_VARARGS; 
    517         pmd[11].ml_doc = NULL; 
    518  
    519         pmd[12].ml_name = "get_languages"; 
    520         pmd[12].ml_meth = (PyCFunction)pymidgard_object_get_languages; 
    521         pmd[12].ml_flags = METH_VARARGS; 
    522         pmd[12].ml_doc = NULL; 
    523  
    524         pmd[13].ml_name = "get_by_path"; 
    525         pmd[13].ml_meth = (PyCFunction)pymidgard_object_get_by_path; 
    526         pmd[13].ml_flags = METH_VARARGS; 
    527         pmd[13].ml_doc = NULL; 
    528  
    529         pmd[14].ml_name = "get_parameter"; 
    530         pmd[14].ml_meth = (PyCFunction)pymidgard_object_get_parameter; 
    531         pmd[14].ml_flags = METH_VARARGS; 
    532         pmd[14].ml_doc = NULL; 
    533  
    534         pmd[15].ml_name = "set_parameter"; 
    535         pmd[15].ml_meth = (PyCFunction)pymidgard_object_set_parameter; 
    536         pmd[15].ml_flags = METH_VARARGS; 
    537         pmd[15].ml_doc = NULL; 
    538  
    539         pmd[16].ml_name = "delete_parameters"; 
    540         pmd[16].ml_meth = (PyCFunction)pymidgard_object_delete_parameters; 
    541         pmd[16].ml_flags = METH_VARARGS; 
    542         pmd[16].ml_doc = NULL; 
    543  
    544         pmd[17].ml_name = "purge_parameters"; 
    545         pmd[17].ml_meth = (PyCFunction)pymidgard_object_purge_parameters; 
    546         pmd[17].ml_flags = METH_VARARGS; 
    547         pmd[17].ml_doc = NULL; 
    548  
    549         pmd[18].ml_name = "list_parameters"; 
    550         pmd[18].ml_meth = (PyCFunction)pymidgard_object_list_parameters; 
    551         pmd[18].ml_flags = METH_VARARGS; 
    552         pmd[18].ml_doc = NULL; 
    553  
    554         pmd[19].ml_name = "find_parameters"; 
    555         pmd[19].ml_meth = (PyCFunction)pymidgard_object_find_parameters; 
    556         pmd[19].ml_flags = METH_VARARGS; 
    557         pmd[19].ml_doc = NULL; 
    558  
    559         pmd[20].ml_name = "delete_attachments"; 
    560         pmd[20].ml_meth = (PyCFunction)pymidgard_object_delete_attachments; 
    561         pmd[20].ml_flags = METH_VARARGS; 
    562         pmd[20].ml_doc = NULL; 
    563  
    564         pmd[21].ml_name = "purge_attachments"; 
    565         pmd[21].ml_meth = (PyCFunction)pymidgard_object_purge_attachments; 
    566         pmd[21].ml_flags = METH_VARARGS; 
    567         pmd[21].ml_doc = NULL; 
    568  
    569         pmd[22].ml_name = "list_attachments"; 
    570         pmd[22].ml_meth = (PyCFunction)pymidgard_object_list_attachments; 
    571         pmd[22].ml_flags = METH_VARARGS; 
    572         pmd[22].ml_doc = NULL; 
    573  
    574         pmd[23].ml_name = "find_attachments"; 
    575         pmd[23].ml_meth = (PyCFunction)pymidgard_object_find_attachments; 
    576         pmd[23].ml_flags = METH_VARARGS; 
    577         pmd[23].ml_doc = NULL; 
    578  
    579         pmd[24].ml_name = "create_attachment"; 
    580         pmd[24].ml_meth = (PyCFunction)pymidgard_object_create_attachment; 
    581         pmd[24].ml_flags = METH_VARARGS; 
    582         pmd[24].ml_doc = NULL; 
    583  
    584         pmd[25].ml_name = NULL; 
    585         pmd[25].ml_meth = NULL; 
    586         pmd[25].ml_flags = 0; 
    587         pmd[25].ml_doc = NULL; 
    588  
    589         return pmd; 
    590 
    591  
    592 static PyObject * 
    593 __get_attro(PyObject *self, PyObject *attr) 
     513PyObject * 
     514_py_midgard_get_object_attribute(PyObject *self, PyObject *attr) 
    594515{ 
    595516        GObject *object = G_OBJECT(((PyGObject*)self)->obj); 
     
    624545} 
    625546 
    626 static int 
    627 __set_attro(PyObject *self, PyObject *attr, PyObject *value) 
     547int 
     548_py_midgard_set_object_attribute(PyObject *self, PyObject *attr, PyObject *value) 
    628549{ 
    629550        GObject *object = G_OBJECT(((PyGObject*)self)->obj);     
     
    682603        ot->tp_call = 0; 
    683604        ot->tp_str = 0; 
    684         ot->tp_getattro = __get_attro
    685         ot->tp_setattro = __set_attro
     605        ot->tp_getattro = _py_midgard_get_object_attribute
     606        ot->tp_setattro = _py_midgard_set_object_attribute
    686607        ot->tp_as_buffer = 0; 
    687608        ot->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE; 
     
    692613        ot->tp_weaklistoffset = offsetof(PyGObject, weakreflist); 
    693614        ot->tp_iter = 0; 
    694         ot->tp_iternext = 0; 
    695         /* It fails on 64bit systems, so we allocate methods structure per class */ 
     615        ot->tp_iternext = 0;     
    696616        ot->tp_methods = pymidgard_object_methods; 
    697         //ot->tp_methods = __midgard_object_methods_pmd(); 
    698617        //ot->tp_methods = NULL; 
    699618        ot->tp_members = 0;