- Timestamp:
- May 19, 2015, 8:02:32 AM (9 years ago)
- Location:
- branches/1.3/lang/python/Rappture
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3/lang/python/Rappture/PyRpLibrary.cc
r3638 r5557 48 48 49 49 50 static int 50 static int 51 51 getArgCount(PyObject *args, PyObject *keywds, int *argc) 52 52 { … … 129 129 130 130 static int 131 PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName, 131 PyObjectToBoolean(PyObject *objPtr, const char *defValue, const char *argName, 132 132 int *resultPtr) 133 133 { … … 147 147 value = PyObject_IsTrue(objPtr); 148 148 if (value < 0) { 149 PyErr_Format(PyExc_ValueError, 149 PyErr_Format(PyExc_ValueError, 150 150 "PyObjectToBoolean: bad boolean object"); 151 151 return RP_ERROR; … … 168 168 } else if (PyString_Check(objPtr)) { 169 169 const char *string; 170 170 171 171 string = PyString_AsString(objPtr); 172 172 if (string == NULL) { … … 370 370 371 371 PyDoc_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\ 373 373 \n\ 374 374 Clients use this to query a particular element within the \n\ … … 381 381 By default, this method returns an object representing the \n\ 382 382 DOM node referenced by the path. This is changed by setting \n\ 383 the \" as\" argument to \"id\" (for name of the tail element), \n\383 the \"type\" argument to \"id\" (for name of the tail element), \n\ 384 384 to \"type\" (for the type of the tail element), to \"component\" \n\ 385 385 (for the component name \"type(id)\"), or to \"object\" \n\ … … 391 391 { 392 392 char* path = (char *)""; 393 char* as= (char *)"object";393 char* type = (char *)"object"; 394 394 RpLibrary* retlib = NULL; 395 395 PyObject* retVal = NULL; … … 398 398 static char *kwlist[] = { 399 399 (char *)"path", 400 (char *)" as",400 (char *)"type", 401 401 NULL 402 402 }; … … 422 422 423 423 if (!PyArg_ParseTupleAndKeywords(args, keywds, "|ss", 424 kwlist, &path, & as)) {424 kwlist, &path, &type)) { 425 425 /* incorrect input values */ 426 426 // tested with ElementTests.testArguments_ArgsWrongType2() 427 PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, as=\'object\'])");427 PyErr_Format(PyExc_TypeError,"element ([path=\'\'][, type=\'object\'])"); 428 428 return retVal; 429 429 } … … 432 432 433 433 if (retlib != NULL) { 434 if (( as == NULL) || ((*as == 'o') && (strcmp("object",as) == 0)) ) {434 if ((type == NULL) || ((*type == 'o') && (strcmp("object",type) == 0)) ) { 435 435 // tested with ElementTests.testArguments_PathArg() 436 436 retVal = RpLibraryObject_FromLibrary(retlib); 437 } else if ((* as == 'c') && (strcmp("component",as) == 0)) {437 } else if ((*type == 'c') && (strcmp("component",type) == 0)) { 438 438 // tested with ElementTests.testArguments_TwoArgs() 439 439 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() 442 442 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() 445 445 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)) { 447 447 // tested with ElementTests.testArguments_TwoKeywordArgs() 448 448 retVal = PyString_FromString(retlib->nodePath().c_str()); 449 449 } else { 450 // tested with ElementTests.testArguments_Unrecognized As()450 // tested with ElementTests.testArguments_Unrecognizedtype() 451 451 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\'"); 453 453 } 454 454 } … … 649 649 NULL 650 650 }; 651 651 652 appendFlag = compressFlag = FALSE; 652 653 strObjPtr = appendObjPtr = valueObjPtr = compressObjPtr = NULL; … … 670 671 return NULL; 671 672 } 672 if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path, 673 if (!PyArg_ParseTupleAndKeywords(args, keywds, "sO|sOsO", kwlist, &path, 673 674 &valueObjPtr, &id, &appendObjPtr, &type, &compressObjPtr)) { 674 675 return NULL; … … 690 691 strObjPtr = PyObject_Str(valueObjPtr); 691 692 if (RpLibraryObject_IsValid(valueObjPtr)) { 692 self->lib->put( std::string(path), 693 self->lib->put( std::string(path), 693 694 RpLibraryObject_AsLibrary(valueObjPtr), "", appendFlag); 694 695 } else if (strObjPtr != NULL) { … … 704 705 std::string(string), "", appendFlag); 705 706 } else { 706 self->lib->putData( std::string(path), string, length, 707 self->lib->putData( std::string(path), string, length, 707 708 appendFlag); 708 709 } … … 755 756 756 757 static char *kwlist[] = { 757 (char *)"status", 758 (char *)"status", 758 759 NULL 759 760 }; -
branches/1.3/lang/python/Rappture/library.py
r3177 r5557 43 43 44 44 # ------------------------------------------------------------------ 45 def element(self, path="", as="object"):45 def element(self, path="", type="object"): 46 46 """ 47 47 Clients use this to query a particular element within the … … 54 54 By default, this method returns an object representing the 55 55 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), 57 57 to "type" (for the type of the tail element), to "component" 58 58 (for the component name "type(id)"), or to "object" … … 64 64 return None 65 65 66 if as== 'object':66 if type == 'object': 67 67 return library(node) 68 elif as== 'component':68 elif type == 'component': 69 69 return self._node2comp(node) 70 elif as== 'id':70 elif type == 'id': 71 71 return self._node2name(node) 72 elif as== 'type':72 elif type == 'type': 73 73 return node.tagName 74 74 75 raise ValueError, "bad as value '%s': should be component, id, object, type" % as76 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): 79 79 """ 80 80 Clients use this to query the children of a particular element 81 81 within the entire data structure. This is just like the 82 82 element() method, but it returns the children of the element 83 instead of the element itself. If the optional type argument83 instead of the element itself. If the optional rtype argument 84 84 is specified, then the return list is restricted to children 85 85 of the specified type. 86 86 87 87 By default, this method returns a list of objects representing 88 the children. This is changed by setting the " as" argument88 the children. This is changed by setting the "type" argument 89 89 to "id" (for tail names of all children), to "type" (for the 90 90 types of all children), to "component" (for the path component … … 99 99 nlist = [n for n in node.childNodes if not n.nodeName.startswith('#')] 100 100 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': 105 105 return [library(n) for n in nlist] 106 elif as== 'component':106 elif type == 'component': 107 107 return [self._node2comp(n) for n in nlist] 108 elif as== 'id':108 elif type == 'id': 109 109 return [self._node2name(n) for n in nlist] 110 elif as== 'type':110 elif type == 'type': 111 111 return [n.tagName for n in nlist] 112 112 113 raise ValueError, "bad as value '%s': should be component, id, object, type" % as113 raise ValueError, "bad type value '%s': should be component, id, object, type" % type 114 114 115 115 # ------------------------------------------------------------------ … … 276 276 277 277 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, 279 279 the path "foo.bar#" called the first time will create "foo.bar", 280 280 the second time "foo.bar1", the third time "foo.bar2" and
Note: See TracChangeset
for help on using the changeset viewer.