Changeset 5409


Ignore:
Timestamp:
May 4, 2015, 5:11:36 AM (9 years ago)
Author:
mmh
Message:

change keyword \"as\" to \"type\"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/uq/lang/python/Rappture/library.py

    r3177 r5409  
    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.