Ignore:
Timestamp:
04/16/06 19:45:21 (9 years ago)
Author:
xi
Message:

Refactor resolver.

File:
1 edited

Legend:

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

    r136 r137  
    1212from representer import * 
    1313 
    14 from detector import * 
     14from resolver import * 
    1515 
    1616from tokens import * 
     
    197197    return dump_all([data], stream, Dumper=SafeDumper, **kwds) 
    198198 
    199 def add_detector(tag, regexp, first=None, Loader=Loader, Dumper=Dumper): 
     199def add_implicit_detector(tag, regexp, first=None, 
     200        Loader=Loader, Dumper=Dumper): 
    200201    """ 
    201202    Add an implicit scalar detector. 
     
    204205    first is a sequence of possible initial characters or None. 
    205206    """ 
    206     Loader.add_detector(tag, regexp, first) 
    207     Dumper.add_detector(tag, regexp, first) 
    208  
    209 def add_resolver(tag, path, Loader=Loader): 
     207    Loader.add_implicit_resolver(tag, regexp, first) 
     208    Dumper.add_implicit_resolver(tag, regexp, first) 
     209 
     210def add_path_resolver(tag, path, kind=None, Loader=Loader, Dumper=Dumper): 
    210211    """ 
    211212    Add a path based resolver for the given tag. 
     
    214215    Keys can be string values, integers, or None. 
    215216    """ 
    216     Loader.add_resolver(tag, path) 
     217    Loader.add_path_resolver(tag, path, kind) 
     218    Dumper.add_path_resolver(tag, path, kind) 
    217219 
    218220def add_constructor(tag, constructor, Loader=Loader): 
     
    232234    """ 
    233235    Loader.add_multi_constructor(tag_prefix, multi_constructor) 
     236 
     237def add_representer(data_type, representer, Dumper=Dumper): 
     238    """ 
     239    Add a representer for the given type. 
     240    Representer is a function accepting a Dumper instance 
     241    and an instance of the given data type 
     242    and producing the corresponding representation node. 
     243    """ 
     244    Dumper.add_representer(data_type, representer) 
    234245 
    235246class YAMLObjectMetaclass(type): 
Note: See TracChangeset for help on using the changeset viewer.