Ignore:
Timestamp:
02/23/07 15:45:35 (7 years ago)
Author:
xi
Message:

Fix the bug when the path in add_path_resolver contains boolean values. Fix #43 (thanks to jstroud(at)mbi.ucla.edu for reporting and pointing to the cause).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/resolver.py

    r226 r246  
    3333 
    3434    def add_path_resolver(cls, tag, path, kind=None): 
     35        # Note: `add_path_resolver` is experimental.  The API could be changed. 
     36        # `new_path` is a pattern that is matched against the path from the 
     37        # root to the node that is being considered.  `node_path` elements are 
     38        # tuples `(node_check, index_check)`.  `node_check` is a node class: 
     39        # `ScalarNode`, `SequenceNode`, `MappingNode` or `None`.  `None` 
     40        # matches any kind of a node.  `index_check` could be `None`, a boolean 
     41        # value, a string value, or a number.  `None` and `False` match against 
     42        # any _value_ of sequence and mapping nodes.  `True` matches against 
     43        # any _key_ of a mapping node.  A string `index_check` matches against 
     44        # a mapping value that corresponds to a scalar key which content is 
     45        # equal to the `index_check` value.  An integer `index_check` matches 
     46        # against a sequence value with the index equal to `index_check`. 
    3547        if not 'yaml_path_resolvers' in cls.__dict__: 
    3648            cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy() 
     
    114126        if index_check is True and current_index is not None: 
    115127            return 
    116         if index_check in [False, None] and current_index is None: 
     128        if (index_check is False or index_check is None)    \ 
     129                and current_index is None: 
    117130            return 
    118131        if isinstance(index_check, basestring): 
     
    120133                    and index_check == current_index.value): 
    121134                return 
    122         elif isinstance(index_check, int): 
     135        elif isinstance(index_check, int) and not isinstance(index_check, bool): 
    123136            if index_check != current_index: 
    124137                return 
Note: See TracChangeset for help on using the changeset viewer.