Changeset 5557 for branches


Ignore:
Timestamp:
May 19, 2015, 8:02:32 AM (9 years ago)
Author:
mmh
Message:

fix code that used "as" as a keyword

Location:
branches/1.3/lang/python/Rappture
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/1.3/lang/python/Rappture/PyRpLibrary.cc

    r3638 r5557  
    4848
    4949
    50 static int 
     50static int
    5151getArgCount(PyObject *args, PyObject *keywds, int *argc)
    5252{
     
    129129
    130130static int
    131 PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName, 
     131PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName,
    132132                  int *resultPtr)
    133133{
     
    147147        value = PyObject_IsTrue(objPtr);
    148148        if (value < 0) {
    149              PyErr_Format(PyExc_ValueError, 
     149             PyErr_Format(PyExc_ValueError,
    150150                "PyObjectToBoolean: bad boolean object");
    151151            return RP_ERROR;
     
    168168    } else if (PyString_Check(objPtr)) {
    169169        const char *string;
    170        
     170
    171171        string = PyString_AsString(objPtr);
    172172        if (string == NULL) {
     
    370370
    371371PyDoc_STRVAR(ElementProcDoc,
    372 "element ([path=\'\'][, as=\'object\']) -> returns string or Rappture Library Object\n\
     372"element ([path=\'\'][, type=\'object\']) -> returns string or Rappture Library Object\n\
    373373\n\
    374374Clients use this to query a particular element within the \n\
     
    381381By default, this method returns an object representing the \n\
    382382DOM node referenced by the path.  This is changed by setting \n\
    383 the \"as\" argument to \"id\" (for name of the tail element), \n\
     383the \"type\" argument to \"id\" (for name of the tail element), \n\
    384384to \"type\" (for the type of the tail element), to \"component\" \n\
    385385(for the component name \"type(id)\"), or to \"object\" \n\
     
    391391{
    392392    char* path = (char *)"";
    393     char* as = (char *)"object";
     393    char* type = (char *)"object";
    394394    RpLibrary* retlib = NULL;
    395395    PyObject* retVal = NULL;
     
    398398    static char *kwlist[] = {
    399399        (char *)"path",
    400         (char *)"as",
     400        (char *)"type",
    401401        NULL
    402402    };
     
    422422
    423423    if (!PyArg_ParseTupleAndKeywords(args, keywds, "|ss",
    424                 kwlist, &path, &as)) {
     424                kwlist, &path, &type)) {
    425425        /* incorrect input values */
    426426        // tested with ElementTests.testArguments_ArgsWrongType2()
    427         PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, as=\'object\'])");
     427        PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, type=\'object\'])");
    428428        return retVal;
    429429    }
     
    432432
    433433    if (retlib != NULL) {
    434         if ((as == NULL) || ((*as == 'o') && (strcmp("object",as) == 0)) ) {
     434        if ((type == NULL) || ((*type == 'o') && (strcmp("object",type) == 0)) ) {
    435435            // tested with ElementTests.testArguments_PathArg()
    436436            retVal = RpLibraryObject_FromLibrary(retlib);
    437         } else if ((*as == 'c') && (strcmp("component",as) == 0)) {
     437        } else if ((*type == 'c') && (strcmp("component",type) == 0)) {
    438438            // tested with ElementTests.testArguments_TwoArgs()
    439439            retVal = PyString_FromString(retlib->nodeComp().c_str());
    440         } else if ((*as == 'i') && (strcmp("id",as) == 0)) {
    441             // tested with ElementTests.testArguments_AsId()
     440        } else if ((*type == 'i') && (strcmp("id",type) == 0)) {
     441            // tested with ElementTests.testArguments_typeId()
    442442            retVal = PyString_FromString(retlib->nodeId().c_str());
    443         } else if ((*as == 't') && (strcmp("type",as) == 0)) {
    444             // tested with ElementTests.testArguments_AsKeywordArgs()
     443        } else if ((*type == 't') && (strcmp("type",type) == 0)) {
     444            // tested with ElementTests.testArguments_typeKeywordArgs()
    445445            retVal = PyString_FromString(retlib->nodeType().c_str());
    446         } else if ((*as == 'p') && (strcmp("path",as) == 0)) {
     446        } else if ((*type == 'p') && (strcmp("path",type) == 0)) {
    447447            // tested with ElementTests.testArguments_TwoKeywordArgs()
    448448            retVal = PyString_FromString(retlib->nodePath().c_str());
    449449        } else {
    450             // tested with ElementTests.testArguments_UnrecognizedAs()
     450            // tested with ElementTests.testArguments_Unrecognizedtype()
    451451            PyErr_Format(PyExc_ValueError,
    452                 "element() \'as\' arg must be \'object\' or \'component\' or \'id\' or \'type\' or \'path\'");
     452                "element() \'type\' arg must be \'object\' or \'component\' or \'id\' or \'type\' or \'path\'");
    453453        }
    454454    }
     
    649649        NULL
    650650    };
     651
    651652    appendFlag = compressFlag = FALSE;
    652653    strObjPtr = appendObjPtr = valueObjPtr = compressObjPtr = NULL;
     
    670671        return NULL;
    671672    }
    672     if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path, 
     673    if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path,
    673674        &valueObjPtr, &id, &appendObjPtr, &type, &compressObjPtr)) {
    674675        return NULL;
     
    690691    strObjPtr = PyObject_Str(valueObjPtr);
    691692    if (RpLibraryObject_IsValid(valueObjPtr)) {
    692         self->lib->put( std::string(path), 
     693        self->lib->put( std::string(path),
    693694                RpLibraryObject_AsLibrary(valueObjPtr), "", appendFlag);
    694695    } else if (strObjPtr != NULL) {
     
    704705                                std::string(string), "", appendFlag);
    705706            } else {
    706                 self->lib->putData( std::string(path), string, length, 
     707                self->lib->putData( std::string(path), string, length,
    707708                        appendFlag);
    708709            }
     
    755756
    756757    static char *kwlist[] = {
    757         (char *)"status", 
     758        (char *)"status",
    758759        NULL
    759760    };
  • branches/1.3/lang/python/Rappture/library.py

    r3177 r5557  
    4343
    4444    # ------------------------------------------------------------------
    45     def element(self, path="", as="object"):
     45    def element(self, path="", type="object"):
    4646        """
    4747        Clients use this to query a particular element within the
     
    5454        By default, this method returns an object representing the
    5555        DOM node referenced by the path.  This is changed by setting
    56         the "as" argument to "id" (for name of the tail element),
     56        the "type" argument to "id" (for name of the tail element),
    5757        to "type" (for the type of the tail element), to "component"
    5858        (for the component name "type(id)"), or to "object"
     
    6464            return None
    6565
    66         if as == 'object':
     66        if type == 'object':
    6767            return library(node)
    68         elif as == 'component':
     68        elif type == 'component':
    6969            return self._node2comp(node)
    70         elif as == 'id':
     70        elif type == 'id':
    7171            return self._node2name(node)
    72         elif as == 'type':
     72        elif type == 'type':
    7373            return node.tagName
    7474
    75         raise ValueError, "bad as value '%s': should be component, id, object, type" % as
    76 
    77     # ------------------------------------------------------------------
    78     def children(self, path="", as="object", type=None):
     75        raise ValueError, "bad type value '%s': should be component, id, object, type" % type
     76
     77    # ------------------------------------------------------------------
     78    def children(self, path="", type="object", rtype=None):
    7979        """
    8080        Clients use this to query the children of a particular element
    8181        within the entire data structure.  This is just like the
    8282        element() method, but it returns the children of the element
    83         instead of the element itself.  If the optional type argument
     83        instead of the element itself.  If the optional rtype argument
    8484        is specified, then the return list is restricted to children
    8585        of the specified type.
    8686
    8787        By default, this method returns a list of objects representing
    88         the children.  This is changed by setting the "as" argument
     88        the children.  This is changed by setting the "type" argument
    8989        to "id" (for tail names of all children), to "type" (for the
    9090        types of all children), to "component" (for the path component
     
    9999        nlist = [n for n in node.childNodes if not n.nodeName.startswith('#')]
    100100
    101         if type:
    102             nlist = [n for n in nlist if n.nodeName == type]
    103 
    104         if as == 'object':
     101        if rtype:
     102            nlist = [n for n in nlist if n.nodeName == rtype]
     103
     104        if type == 'object':
    105105            return [library(n) for n in nlist]
    106         elif as == 'component':
     106        elif type == 'component':
    107107            return [self._node2comp(n) for n in nlist]
    108         elif as == 'id':
     108        elif type == 'id':
    109109            return [self._node2name(n) for n in nlist]
    110         elif as == 'type':
     110        elif type == 'type':
    111111            return [n.tagName for n in nlist]
    112112
    113         raise ValueError, "bad as value '%s': should be component, id, object, type" % as
     113        raise ValueError, "bad type value '%s': should be component, id, object, type" % type
    114114
    115115    # ------------------------------------------------------------------
     
    276276
    277277        If you include "#" instead of a specific number, a node
    278         will be created automatically with a new number.  For example, 
     278        will be created automatically with a new number.  For example,
    279279        the path "foo.bar#" called the first time will create "foo.bar",
    280280        the second time "foo.bar1", the third time "foo.bar2" and
Note: See TracChangeset for help on using the changeset viewer.