Changeset 7654:d24acd5cabb2 in orange


Ignore:
Timestamp:
02/12/11 00:19:12 (3 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
81fcf6a701803b8e93e1471e181ec5a35867395c
Message:

Method and attributes of C++ objects, which were exposed to Python in mixedCase are now in underscore form, with compatibility preserved

Location:
source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • source/orange/_aliases.txt

    r1337 r7654  
    1616EquiDistDiscretizer 
    1717firstVal firstCut 
     18firstVal first_cut 
     19 
     20SymMatrix 
     21getitems get_items 
     22 
     23ExampleGenerator 
     24getitems get_items 
     25 
     26ExampleTable 
     27getitemsref get_items_ref 
     28selectlist select_list 
     29selectref select_ref 
     30selectbool select_bool 
     31filterlist filter_list 
     32filterref filter_ref 
     33filterbool filter_bool 
     34randomexample random_example 
     35 
     36ClassifierByExampleTable 
     37boundset bound_set 
     38 
     39ClassifierByLookupTable 
     40boundset bound_set 
     41getindex get_index 
     42 
     43ContingencyClass 
     44add_attrclass add_var_class 
     45 
     46TreeNode 
     47treesize tree_size 
     48removestoredinfo remove_stored_info 
     49 
     50TreeClassifier 
     51treesize tree_size 
     52 
     53C45Learner 
     54commandline command_line 
  • source/orange/cls_example.cpp

    r6531 r7654  
    306306 
    307307 
    308 PyObject *Example_getweight(TPyExample *pex, PyObject *pyindex) PYARGS(METH_O, "(id) -> weight; Returns example's weight") 
     308PyObject *Example_get_weight(TPyExample *pex, PyObject *pyindex) PYARGS(METH_O, "(id) -> weight; Returns example's weight") 
    309309{ 
    310310  PyTRY 
     
    326326 
    327327 
    328 PyObject *Example_setweight(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "(id[, weight]); Sets example's weight to given value") 
     328PyObject *Example_set_weight(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "(id[, weight]); Sets example's weight to given value") 
    329329{ PyTRY 
    330330    PyObject *pyindex; 
     
    351351 
    352352 
    353 PyObject *Example_removeweight(TPyExample *pex, PyObject *pyindex) PYARGS(METH_O, "(id); Removes examples's weight") 
     353PyObject *Example_remove_weight(TPyExample *pex, PyObject *pyindex) PYARGS(METH_O, "(id); Removes examples's weight") 
    354354{ PyTRY 
    355355    TExample &example = PyExample_AS_ExampleReference(pex); 
     
    370370 
    371371 
    372 PyObject *Example_getmeta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id | var) -> Value; Gets a meta-value") 
     372PyObject *Example_get_meta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id | var) -> Value; Gets a meta-value") 
    373373{ PyTRY 
    374374    PVariable var; 
     
    385385 
    386386 
    387 PyObject *Example_getmetas(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "([key-type]) -> dictionary with a copy of example's meta attributes") 
     387PyObject *Example_get_metas(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "([key-type]) -> dictionary with a copy of example's meta attributes") 
    388388{ 
    389389  PyTRY 
     
    459459 
    460460 
    461 PyObject *Example_hasmeta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id | var) -> bool") 
     461PyObject *Example_has_meta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id | var) -> bool") 
    462462{ PyTRY 
    463463    PVariable var; 
     
    469469 
    470470 
    471 PyObject *Example_setvalue(TPyExample *pex, PyObject *vala) PYARGS(METH_O, "(Value) -> None") 
     471PyObject *Example_set_value(TPyExample *pex, PyObject *vala) PYARGS(METH_O, "(Value) -> None") 
    472472{ PyTRY 
    473473    if (!PyOrValue_Check(vala)) 
     
    491491 
    492492 
    493 PyObject *Example_setmeta(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "(Value, int) | (variable, value); Sets a meta-value") 
     493PyObject *Example_set_meta(TPyExample *pex, PyObject *args) PYARGS(METH_VARARGS, "(Value, int) | (variable, value); Sets a meta-value") 
    494494{ PyTRY 
    495495    PExample example=PyExample_AS_Example(pex); 
     
    567567   
    568568 
    569 PyObject *Example_removemeta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id); Removes a meta-value") 
     569PyObject *Example_remove_meta(TPyExample *pex, PyObject *index) PYARGS(METH_O, "(id); Removes a meta-value") 
    570570{ PyTRY 
    571571    PVariable var; 
     
    581581 
    582582 
    583 PyObject *Example_getclass(TPyExample *pex) PYARGS(METH_NOARGS, "()  -> Value; Returns example's class") 
     583PyObject *Example_get_class(TPyExample *pex) PYARGS(METH_NOARGS, "()  -> Value; Returns example's class") 
    584584{ PyTRY 
    585585      const TExample &example = PyExample_AS_ExampleReference(pex); 
     
    594594 
    595595 
    596 PyObject *Example_setclass(TPyExample *pex, PyObject *val) PYARGS(METH_O, "(value); Sets example's class") 
     596PyObject *Example_set_class(TPyExample *pex, PyObject *val) PYARGS(METH_O, "(value); Sets example's class") 
    597597{ PyTRY 
    598598    PExample &example=PyExample_AS_Example(pex); 
     
    10221022 
    10231023 
     1024char *example_underscores[][2] = { 
     1025    {"getweight", "get_weight"}, 
     1026    {"setweight", "set_weight"}, 
     1027    {"removeweight", "remove_weight"}, 
     1028    {"getmeta", "get_meta"}, 
     1029    {"getmetas", "get_metas"}, 
     1030    {"hasmetas", "has_meta"}, 
     1031    {"setvalue", "set_value"}, 
     1032    {"setmeta", "set_meta"}, 
     1033    {"removemeta", "remove_meta"}, 
     1034    {"getclass", "get_class"}, 
     1035    {"setclass", "set_class"}, 
     1036    {NULL, NULL} 
     1037}; 
     1038 
    10241039PyObject *Example_getattr(TPyExample *self, PyObject *name) 
    10251040{ 
    1026   if (!PyString_Check(name) || strcmp(PyString_AsString(name), "name")) 
     1041  char *orig = PyString_AsString(name); 
     1042  for(char *(*ei)[2] = example_underscores; **ei; ei++) { 
     1043      if (!strcmp(orig, **ei)) { 
     1044          PyObject *trans = PyString_FromString((*ei)[1]); 
     1045          PyObject *value = PyObject_GenericGetAttr((PyObject *)self, trans); 
     1046          Py_DECREF(trans); 
     1047          return value; 
     1048      } 
     1049  } 
     1050 
     1051  if (!PyString_Check(name) || strcmp(orig, "name")) 
    10271052    return PyObject_GenericGetAttr((PyObject *)self, name); 
    10281053 
  • source/orange/cls_misc.cpp

    r6531 r7654  
    156156} 
    157157 
     158PyObject *DomainDepot_getattr(PyObject *self, PyObject *name) 
     159{ 
     160  char *orig = PyString_AsString(name); 
     161  PyObject *trans = NULL; 
     162  if (!strcmp(orig, "checkDomain")) { 
     163      trans = PyString_FromString("check_domain"); 
     164  } 
     165  else if (!strcmp(orig, "prepareDomain")) { 
     166      trans = PyString_FromString("prepare_domain"); 
     167  } 
     168 
     169  PyObject *value = PyObject_GenericGetAttr(self, trans ? trans : name); 
     170  Py_XDECREF(trans); 
     171  return value; 
     172} 
     173 
    158174PyObject *DomainDepot_checkDomain(PyObject *self, PyObject *args, PyObject *) PYARGS(METH_VARARGS, "(domain, list-of-names)") 
    159175{ 
  • source/orange/cls_orange.cpp

    r6531 r7654  
    279279 
    280280 
     281char *camel2underscore(const char *camel) 
     282{ 
     283    const char *ci = camel; 
     284    if ((*ci >= 'A') && (*ci <= 'Z')) { 
     285        return NULL; 
     286    } 
     287 
     288    char *underscored = (char *)malloc(2*strlen(camel)+1); 
     289    char *ui = underscored; 
     290    bool changed = false; 
     291    *ui = *ci; 
     292    while(*ci) { // just copied 
     293        if (   (*ci >= 'a') && (*ci <= 'z')       // a small letter 
     294            && (ci[1] >= 'A') && (ci[1] <= 'Z')   // followed by capital 
     295            && ((ci[2] < 'A') || (ci[2] > 'Z'))) { // not followed by capital  
     296            *++ui = '_'; 
     297            *++ui = *++ci + 32; 
     298            changed = true; 
     299        } 
     300        else { 
     301            *++ui = *++ci; 
     302        } 
     303    } 
     304    if (!changed) { 
     305        free(underscored); 
     306        underscored = NULL; 
     307    } 
     308    return underscored; 
     309} 
     310 
     311 
    281312PyObject *PyOrange_translateObsolete(PyObject *self, PyObject *pyname) 
    282313{  
    283   char *name=PyString_AsString(pyname); 
    284   for(TOrangeType *selftype = PyOrange_OrangeBaseClass(self->ob_type); PyOrange_CheckType((PyTypeObject *)selftype); selftype=(TOrangeType *)(selftype->ot_inherited.tp_base)) 
    285     if (selftype->ot_aliases) 
    286       for(TAttributeAlias *aliases=selftype->ot_aliases; aliases->alias; aliases++) 
    287         if (!strcmp(name, aliases->alias)) 
    288           return PyString_FromString(aliases->realName); 
     314  char *name = PyString_AsString(pyname); 
     315  char *underscored = camel2underscore(name); 
     316  for(TOrangeType *selftype = PyOrange_OrangeBaseClass(self->ob_type); PyOrange_CheckType((PyTypeObject *)selftype); selftype=(TOrangeType *)(selftype->ot_inherited.tp_base)) { 
     317      if (selftype->ot_aliases) { 
     318          for(TAttributeAlias *aliases=selftype->ot_aliases; aliases->alias; aliases++) { 
     319              if (!strcmp(name, aliases->alias) || (underscored && !strcmp(underscored, aliases->alias))) { 
     320                  if (underscored) { 
     321                      free(underscored); 
     322                  } 
     323                  return PyString_FromString(aliases->realName); 
     324              } 
     325          } 
     326      } 
     327  } 
     328  if (underscored) { 
     329      free(underscored); 
     330  } 
    289331  return NULL; 
    290332}     
     
    731773  PyTRY 
    732774    PyObject *res = Orange_getattr1(self, name); 
     775    char *underscored = NULL; 
    733776    if (!res) { 
    734       PyObject *translation = PyOrange_translateObsolete((PyObject *)self, name); 
    735       if (translation) { 
    736         PyErr_Clear(); 
    737         res = Orange_getattr1(self, translation); 
    738         Py_DECREF(translation); 
    739       } 
    740     } 
    741  
     777        char *camel = PyString_AsString(name); 
     778        underscored = camel2underscore(camel); 
     779        if (underscored) { 
     780            PyObject *translation = PyString_FromString(underscored); 
     781            PyErr_Clear(); 
     782            res = Orange_getattr1(self, translation); 
     783            Py_DECREF(translation); 
     784        } 
     785    } 
     786    if (!res) { 
     787        PyObject *translation = PyOrange_translateObsolete((PyObject *)self, name); 
     788        if (translation) { 
     789            PyErr_Clear(); 
     790            res = Orange_getattr1(self, translation); 
     791            Py_DECREF(translation); 
     792        } 
     793    } 
     794 
     795    if (!res && underscored) { 
     796        PyMethodDef *mi = self->ob_type->tp_methods; 
     797        if (mi) { 
     798            for(; mi->ml_name; mi++) { 
     799                if (!strcmp(underscored, mi->ml_name)) { 
     800                    res = PyMethod_New((PyObject *)mi->ml_meth, (PyObject *)self, (PyObject *)(self->ob_type)); 
     801                    break; 
     802                } 
     803            } 
     804        } 
     805    } 
     806 
     807    if (underscored) { 
     808        free(underscored); 
     809    } 
    742810    return res; 
    743811  PyCATCH 
     
    802870      return res; 
    803871     
     872    PyErr_Clear(); 
     873    char *camel = PyString_AsString(pyname); 
     874    char *underscored = camel2underscore(camel); 
     875    if (underscored) { 
     876        PyObject *translation = PyString_FromString(underscored); 
     877        free(underscored); 
     878        res = Orange_setattr1(self, translation, args); 
     879        Py_DECREF(translation); 
     880    } 
     881    if (res!=1) 
     882      return res; 
     883 
    804884    PyErr_Clear(); 
    805885    // Try to translate it as an obsolete alias for C++ class member 
  • source/orange/cls_value.cpp

    r6531 r7654  
    904904 
    905905 
    906 PyObject *Value_randomvalue(TPyValue *self) PYARGS(METH_NOARGS, "(); Sets the value to a random") 
     906char *value_underscores[][2] = { 
     907    {"firstvalue", "first_value"}, 
     908    {"nextvalue", "next_value"}, 
     909    {"randomvalue", "random_value"}, 
     910    {"isDC", "is_DC"}, 
     911    {"isDK", "is_DK"}, 
     912    {"isSpecial", "is_special"}, 
     913    {"varType", "var_type"}, 
     914    {"valueType", "value_type"},     
     915    {NULL, NULL} 
     916}; 
     917 
     918PyObject *Value_getattr(PyObject *self, PyObject *name) 
     919{ 
     920  char *orig = PyString_AsString(name); 
     921  for(char *(*ei)[2] = value_underscores; **ei; ei++) { 
     922      if (!strcmp(orig, **ei)) { 
     923          PyObject *trans = PyString_FromString((*ei)[1]); 
     924          PyObject *value = PyObject_GenericGetAttr((PyObject *)self, trans); 
     925          Py_DECREF(trans); 
     926          return value; 
     927      } 
     928  } 
     929 
     930  return PyObject_GenericGetAttr((PyObject *)self, name); 
     931 
     932} 
     933 
     934PyObject *Value_random_value(TPyValue *self) PYARGS(METH_NOARGS, "(); Sets the value to a random") 
    907935{ PyTRY 
    908936    CHECK_VARIABLE 
     
    913941 
    914942 
    915 PyObject *Value_firstvalue(TPyValue *self)  PYARGS(METH_NOARGS, "() -> bool; Sets the value to the first value") 
     943PyObject *Value_first_value(TPyValue *self)  PYARGS(METH_NOARGS, "() -> bool; Sets the value to the first value") 
    916944{ PyTRY 
    917945    CHECK_VARIABLE 
     
    921949 
    922950 
    923 PyObject *Value_nextvalue(TPyValue *self)  PYARGS(METH_NOARGS, "() -> bool; Increases the value (if possible)") 
     951PyObject *Value_next_value(TPyValue *self)  PYARGS(METH_NOARGS, "() -> bool; Increases the value (if possible)") 
    924952{ PyTRY 
    925953    CHECK_VARIABLE 
  • source/orange/lib_components.cpp

    r6963 r7654  
    733733 
    734734 
    735 PyObject *ContingencyClass_add_attrclass(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(attribute_value, class_value[, w=1]) -> None") 
     735PyObject *ContingencyClass_add_var_class(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(attribute_value, class_value[, w=1]) -> None") 
    736736{ 
    737737    PyTRY 
     
    33063306} 
    33073307 
    3308 PyObject *SymMatrix_getitems(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(List of items -> SymMatrix)") 
     3308PyObject *SymMatrix_get_items(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(List of items -> SymMatrix)") 
    33093309{ 
    33103310    PyTRY 
     
    33133313    PyObject *items; 
    33143314 
    3315     if (!PyArg_ParseTuple(args, "O:SymMatrix.getitems", &items)) 
     3315    if (!PyArg_ParseTuple(args, "O:SymMatrix.get_items", &items)) 
    33163316        return PYNULL; 
    33173317 
  • source/orange/lib_kernel.cpp

    r6955 r7654  
    25612561 
    25622562 
    2563 PyObject *ExampleGenerator_getitems(TPyOrange *self, PyObject *pylist)  PYARGS(METH_O, "(indices) -> ExampleTable") 
     2563PyObject *ExampleGenerator_get_items(TPyOrange *self, PyObject *pylist)  PYARGS(METH_O, "(indices) -> ExampleTable") 
    25642564{ return multipleSelectLow(self, pylist, false); } 
    25652565 
     
    37393739 
    37403740 
    3741 PyObject *ExampleTable_getitemsref(TPyOrange *self, PyObject *pylist)   PYARGS(METH_O, "(indices) -> ExampleTable") 
     3741PyObject *ExampleTable_get_items_ref(TPyOrange *self, PyObject *pylist)   PYARGS(METH_O, "(indices) -> ExampleTable") 
    37423742{ return multipleSelectLow(self, pylist, true); } 
    37433743 
     
    39133913 
    39143914 
    3915 PyObject *ExampleTable_selectlist(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
     3915PyObject *ExampleTable_select_list(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
    39163916{ PyTRY 
    39173917    return ExampleTable_selectLow(self, args, keywords, 1); 
     
    39203920 
    39213921 
    3922 PyObject *ExampleTable_selectref(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
     3922PyObject *ExampleTable_select_ref(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
    39233923{ PyTRY 
    39243924    return ExampleTable_selectLow(self, args, keywords, 0); 
     
    39273927 
    39283928 
    3929 PyObject *ExampleTable_selectbool(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
     3929PyObject *ExampleTable_select_bool(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "see the manual for help") 
    39303930{ PyTRY 
    39313931    return ExampleTable_selectLow(self, args, keywords, 2); 
     
    39343934 
    39353935 
    3936 PyObject *ExampleTable_filterlist(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
     3936PyObject *ExampleTable_filter_list(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
    39373937{ 
    39383938  PyTRY 
     
    39543954    } 
    39553955 
    3956     PYERROR(PyExc_AttributeError, "ExampleGenerator.filterlist expects a list of conditions or orange.Filter", PYNULL) 
    3957   PyCATCH 
    3958 } 
    3959  
    3960  
    3961 PyObject *ExampleTable_filterref(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
     3956    PYERROR(PyExc_AttributeError, "ExampleGenerator.filter_list expects a list of conditions or orange.Filter", PYNULL) 
     3957  PyCATCH 
     3958} 
     3959 
     3960 
     3961PyObject *ExampleTable_filter_ref(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
    39623962{ 
    39633963  PyTRY 
     
    39793979    } 
    39803980 
    3981     PYERROR(PyExc_AttributeError, "ExampleGenerator.filterlist expects a list of conditions or orange.Filter", PYNULL) 
    3982   PyCATCH 
    3983 } 
    3984  
    3985  
    3986 PyObject *ExampleTable_filterbool(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
     3981    PYERROR(PyExc_AttributeError, "ExampleGenerator.filter_ref expects a list of conditions or orange.Filter", PYNULL) 
     3982  PyCATCH 
     3983} 
     3984 
     3985 
     3986PyObject *ExampleTable_filter_bool(TPyOrange *self, PyObject *args, PyObject *keywords) PYARGS(METH_VARARGS | METH_KEYWORDS, "(list-of-attribute-conditions | filter)") 
    39873987{ 
    39883988  PyTRY 
     
    40044004    } 
    40054005 
    4006     PYERROR(PyExc_AttributeError, "ExampleGenerator.filterlist expects a list of conditions or orange.Filter", PYNULL) 
    4007   PyCATCH 
    4008 } 
    4009  
    4010  
    4011 PyObject *ExampleTable_randomexample(TPyOrange *self) PYARGS(0, "() -> Example") 
     4006    PYERROR(PyExc_AttributeError, "ExampleGenerator.filter_bool expects a list of conditions or orange.Filter", PYNULL) 
     4007  PyCATCH 
     4008} 
     4009 
     4010 
     4011PyObject *ExampleTable_random_example(TPyOrange *self) PYARGS(0, "() -> Example") 
    40124012{ PyTRY 
    40134013    CAST_TO(TExampleTable, table); 
     
    54725472} 
    54735473 
    5474 PyObject *ClassifierByExampleTable_boundset(PyObject *self) PYARGS(0, "() -> variables") 
     5474PyObject *ClassifierByExampleTable_bound_set(PyObject *self) PYARGS(0, "() -> variables") 
    54755475{ PyTRY 
    54765476    TVarList &attributes=SELF_AS(TClassifierByExampleTable).domain->attributes.getReference(); 
     
    54845484 
    54855485PyObject *ClassifierByExampleTable_get_variables(PyObject *self) 
    5486 { return ClassifierByExampleTable_boundset(self); } 
    5487  
    5488  
    5489 PyObject *ClassifierByLookupTable_boundset(PyObject *self) PYARGS(0, "() -> (variables)") 
     5486{ return ClassifierByExampleTable_bound_set(self); } 
     5487 
     5488 
     5489/* pyxtract must see ClassifierByLookupTable_get_variables before 
     5490    ClassifierByLookupTable_bound_set, since the former gives the class 
     5491    unambiguously, so the latter can find it */ 
     5492PyObject *ClassifierByLookupTable_bound_set(PyObject *self); 
     5493 
     5494PyObject *ClassifierByLookupTable_get_variables(PyObject *self) 
     5495{ return ClassifierByLookupTable_bound_set(self); } 
     5496 
     5497PyObject *ClassifierByLookupTable_bound_set(PyObject *self) PYARGS(0, "() -> (variables)") 
    54905498{ PyTRY 
    54915499    TVarList vlist; 
     
    55005508 
    55015509 
    5502 PyObject *ClassifierByLookupTable_get_variables(PyObject *self) 
    5503 { return ClassifierByLookupTable_boundset(self); } 
    5504  
    5505  
    5506 PyObject *ClassifierByLookupTable_getindex(PyObject *self, PyObject *pyexample) PYARGS(METH_O, "(example) -> int") 
     5510PyObject *ClassifierByLookupTable_get_index(PyObject *self, PyObject *pyexample) PYARGS(METH_O, "(example) -> int") 
    55075511{ PyTRY 
    55085512    if (!PyOrExample_Check(pyexample)) 
  • source/orange/lib_learner.cpp

    r7134 r7654  
    573573 
    574574 
    575 PyObject *TreeNode_treesize(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> int") 
     575PyObject *TreeNode_tree_size(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> int") 
    576576{ PyTRY 
    577577    return PyInt_FromLong(PyOrange_AsTreeNode(self)->treeSize()); 
     
    580580 
    581581 
    582 PyObject *TreeNode_removestoredinfo(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> None") 
     582PyObject *TreeNode_remove_stored_info(PyObject *self, PyObject *, PyObject *) PYARGS(METH_NOARGS, "() -> None") 
    583583{ PyTRY 
    584584    PyOrange_AsTreeNode(self)->removeStoredInfo(); 
     
    898898C_NAMED(C45Classifier, Classifier, "()") 
    899899 
    900 PyObject *C45Learner_commandline(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(line) -> None") 
     900PyObject *C45Learner_command_line(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(line) -> None") 
    901901{ PyTRY 
    902902    char *line; 
  • source/orange/pythonvars.cpp

    r6531 r7654  
    441441    return true; 
    442442  } 
     443  if (isOverloaded("first_value")) { 
     444    val = toValue(PyObject_CallMethod(MYSELF, "first_value", NULL)); 
     445    return true; 
     446  } 
    443447 
    444448  else 
     
    455459    return true; 
    456460  } 
     461  if (isOverloaded("next_value")) { 
     462    PyObject *pyvalue = toPyObject(val); 
     463    toValue(PyObject_CallMethod(MYSELF, "next_value", "O", pyvalue), val); 
     464    Py_DECREF(pyvalue); 
     465    return true; 
     466  } 
    457467 
    458468  else 
     
    465475  if (isOverloaded("randomvalue")) { 
    466476    return toValue(PyObject_CallMethod(MYSELF, "randomvalue", "i", rand)); 
     477  } 
     478  if (isOverloaded("random_value")) { 
     479    return toValue(PyObject_CallMethod(MYSELF, "random_value", "i", rand)); 
    467480  } 
    468481 
  • source/pyxtract/pyprops.py

    r6538 r7654  
    2525 
    2626win32 = sys.platform == "win32" 
     27 
    2728 
    2829def printNQ(str): 
     
    6869    return x and "true" or "false" 
    6970 
     71f_underscored = open("..\_underscored", "a") 
     72hump = re.compile("([a-z])([A-Z])") 
     73def camel2underscore(s): 
     74    if s[0].isupper(): 
     75        return s 
     76    else: 
     77        u = hump.sub(lambda mo: "%s_%s" % (mo.group(1), 
     78                        mo.group(2).lower() if mo.end()==len(s) or not 'A'<=s[mo.end()]<='Z' 
     79                           else mo.group(2)), s) 
     80        if u != s: 
     81            f_underscored.write("%-40s %s\n" % (s, u)) 
     82        return u 
    7083 
    7184def storeClass(currentClass, hppfile): 
     
    143156                pname = (cname, pname) 
    144157            else: 
    145               pname = cname 
     158              pname = camel2underscore(cname) 
    146159             
    147160            currentClass.properties.append((ctype, cname, pname, pdesc, flags and ("R" in flags) or 0, flags and ("O" in flags) or 0, normal, proptype)) 
  • source/pyxtract/pyxtract.py

    r6538 r7654  
    144144 
    145145 
     146f_underscored = open("..\_underscored", "a") 
     147hump = re.compile("([a-z])([A-Z])") 
     148 
     149def camelChange(mo): 
     150    if mo.end() == len(mo.string) or not 'A'<=mo.string[mo.end()]<='Z': 
     151        sg = mo.group(2).lower() 
     152    else: 
     153        sg = mo.group(2) 
     154    return "%s_%s" % (mo.group(1), sg) 
     155     
     156def camel2underscore(s): 
     157    if s[0].isupper(): 
     158        return s 
     159    else: 
     160        u = hump.sub(camelChange, s) 
     161        if u != s: 
     162            f_underscored.write("%-40s %s\n" % (s, u)) 
     163        return u 
     164 
     165 
    146166def detectConstructors(line, classdefs): 
    147167  found=constrdef_mac.search(line) 
     
    229249def detectMethods(line, classdefs): 
    230250  # The below if is to avoid methods, like, for instance, map's clear to be recognized 
    231   # also as a special method. Special methods never include PYARGS... 
     251  # also as a special method. Special methods never include PYARGS. 
    232252  if line.find("PYARGS")<0: 
    233253    found=specialmethoddef.search(line) 
     
    254274    if not classdefs.has_key(typename) and "_" in typename: 
    255275      com = typename.split("_") 
    256       if len(com)==2 and classdefs.has_key(com[0]): 
    257         typename = com[0] 
    258         cname = com[1] + "_" + cname 
     276      for i in range(1, len(com)): 
     277          subname = "_".join(com[:-i])  
     278          if subname in classdefs: 
     279              typename = subname 
     280              cname = "_".join(com[-i:])+"_"+cname 
     281              break 
    259282 
    260283    if not methodname: 
    261       methodname = cname 
     284      methodname = camel2underscore(cname) 
     285 
    262286       
    263287    addClassDef(classdefs, typename, parsedFile) 
     
    388412        continue 
    389413      detectHierarchy(line, classdefs) # BASED_ON, DATASTRUCTURE those lines get detected twice! 
    390       for i in [detectConstructors, detectAttrs, detectMethods, detectCallDoc]: 
     414      # detectMethods must be before detectAttrs to allow for methods named get_something, set_something 
     415      for i in [detectConstructors, detectMethods, detectAttrs, detectCallDoc]: 
    391416        if i(line, classdefs): 
    392417          break 
     
    546571      outfile.write("PyGetSetDef "+type+"_getset[]=  {\n") 
    547572      for (name, definition) in properties: 
    548         outfile.write('  {"%s"' % name) 
     573        camelname = camel2underscore(name) 
     574        outfile.write('  {"%s"' % camelname) 
    549575        if definition.hasget: 
    550576          outfile.write(", (getter)%s_get_%s" % (type, name)) 
Note: See TracChangeset for help on using the changeset viewer.