Changeset 5409
- Timestamp:
- May 4, 2015, 5:11:36 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/uq/lang/python/Rappture/library.py
r3177 r5409 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.