<s> from error import * <EOL> from tokens import * <EOL> from events import * <EOL> from nodes import * <EOL> from loader import * <EOL> from dumper import * <EOL> try : <EOL> from cyaml import * <EOL> except ImportError : <EOL> pass <EOL> def scan ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> while loader . check_token ( ) : <EOL> yield loader . get_token ( ) <EOL> def parse ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> while loader . check_event ( ) : <EOL> yield loader . get_event ( ) <EOL> def compose ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> if loader . check_node ( ) : <EOL> return loader . get_node ( ) <EOL> def compose_all ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> while loader . check_node ( ) : <EOL> yield loader . get_node ( ) <EOL> def load_all ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> while loader . check_data ( ) : <EOL> yield loader . get_data ( ) <EOL> def load ( stream , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> loader = Loader ( stream ) <EOL> if loader . check_data ( ) : <EOL> return loader . get_data ( ) <EOL> def safe_load_all ( stream ) : <EOL> """<STR_LIT>""" <EOL> return load_all ( stream , SafeLoader ) <EOL> def safe_load ( stream ) : <EOL> """<STR_LIT>""" <EOL> return load ( stream , SafeLoader ) <EOL> def emit ( events , stream = None , Dumper = Dumper , <EOL> canonical = None , indent = None , width = None , <EOL> allow_unicode = None , line_break = None ) : <EOL> """<STR_LIT>""" <EOL> getvalue = None <EOL> if stream is None : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> stream = StringIO ( ) <EOL> getvalue = stream . getvalue <EOL> dumper = Dumper ( stream , canonical = canonical , indent = indent , width = width , <EOL> allow_unicode = allow_unicode , line_break = line_break ) <EOL> for event in events : <EOL> dumper . emit ( event ) <EOL> if getvalue : <EOL> return getvalue ( ) <EOL> def serialize_all ( nodes , stream = None , Dumper = Dumper , <EOL> canonical = None , indent = None , width = None , <EOL> allow_unicode = None , line_break = None , <EOL> encoding = '<STR_LIT:utf-8>' , explicit_start = None , explicit_end = None , <EOL> version = None , tags = None ) : <EOL> """<STR_LIT>""" <EOL> getvalue = None <EOL> if stream is None : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> stream = StringIO ( ) <EOL> getvalue = stream . getvalue <EOL> dumper = Dumper ( stream , canonical = canonical , indent = indent , width = width , <EOL> allow_unicode = allow_unicode , line_break = line_break , <EOL> encoding = encoding , version = version , tags = tags , <EOL> explicit_start = explicit_start , explicit_end = explicit_end ) <EOL> dumper . open ( ) <EOL> for node in nodes : <EOL> dumper . serialize ( node ) <EOL> dumper . close ( ) <EOL> if getvalue : <EOL> return getvalue ( ) <EOL> def serialize ( node , stream = None , Dumper = Dumper , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> return serialize_all ( [ node ] , stream , Dumper = Dumper , ** kwds ) <EOL> def dump_all ( documents , stream = None , Dumper = Dumper , <EOL> default_style = None , default_flow_style = None , <EOL> canonical = None , indent = None , width = None , <EOL> allow_unicode = None , line_break = None , <EOL> encoding = '<STR_LIT:utf-8>' , explicit_start = None , explicit_end = None , <EOL> version = None , tags = None ) : <EOL> """<STR_LIT>""" <EOL> getvalue = None <EOL> if stream is None : <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> stream = StringIO ( ) <EOL> getvalue = stream . getvalue <EOL> dumper = Dumper ( stream , default_style = default_style , <EOL> default_flow_style = default_flow_style , <EOL> canonical = canonical , indent = indent , width = width , <EOL> allow_unicode = allow_unicode , line_break = line_break , <EOL> encoding = encoding , version = version , tags = tags , <EOL> explicit_start = explicit_start , explicit_end = explicit_end ) <EOL> dumper . open ( ) <EOL> for data in documents : <EOL> dumper . represent ( data ) <EOL> dumper . close ( ) <EOL> if getvalue : <EOL> return getvalue ( ) <EOL> def dump ( data , stream = None , Dumper = Dumper , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> return dump_all ( [ data ] , stream , Dumper = Dumper , ** kwds ) <EOL> def safe_dump_all ( documents , stream = None , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> return dump_all ( documents , stream , Dumper = SafeDumper , ** kwds ) <EOL> def safe_dump ( data , stream = None , ** kwds ) : <EOL> """<STR_LIT>""" <EOL> return dump_all ( [ data ] , stream , Dumper = SafeDumper , ** kwds ) <EOL> def add_implicit_resolver ( tag , regexp , first = None , <EOL> Loader = Loader , Dumper = Dumper ) : <EOL> """<STR_LIT>""" <EOL> Loader . add_implicit_resolver ( tag , regexp , first ) <EOL> Dumper . add_implicit_resolver ( tag , regexp , first ) <EOL> def add_path_resolver ( tag , path , kind = None , Loader = Loader , Dumper = Dumper ) : <EOL> """<STR_LIT>""" <EOL> Loader . add_path_resolver ( tag , path , kind ) <EOL> Dumper . add_path_resolver ( tag , path , kind ) <EOL> def add_constructor ( tag , constructor , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> Loader . add_constructor ( tag , constructor ) <EOL> def add_multi_constructor ( tag_prefix , multi_constructor , Loader = Loader ) : <EOL> """<STR_LIT>""" <EOL> Loader . add_multi_constructor ( tag_prefix , multi_constructor ) <EOL> def add_representer ( data_type , representer , Dumper = Dumper ) : <EOL> """<STR_LIT>""" <EOL> Dumper . add_representer ( data_type , representer ) <EOL> def add_multi_representer ( data_type , multi_representer , Dumper = Dumper ) : <EOL> """<STR_LIT>""" <EOL> Dumper . add_multi_representer ( data_type , multi_representer ) <EOL> class YAMLObjectMetaclass ( type ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( cls , name , bases , kwds ) : <EOL> super ( YAMLObjectMetaclass , cls ) . __init__ ( name , bases , kwds ) <EOL> if '<STR_LIT>' in kwds and kwds [ '<STR_LIT>' ] is not None : <EOL> cls . yaml_loader . add_constructor ( cls . yaml_tag , cls . from_yaml ) <EOL> cls . yaml_dumper . add_representer ( cls , cls . to_yaml ) <EOL> class YAMLObject ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = YAMLObjectMetaclass <EOL> __slots__ = ( ) <EOL> yaml_loader = Loader <EOL> yaml_dumper = Dumper <EOL> yaml_tag = None <EOL> yaml_flow_style = None <EOL> def from_yaml ( cls , loader , node ) : <EOL> """<STR_LIT>""" <EOL> return loader . construct_yaml_object ( node , cls ) <EOL> from_yaml = classmethod ( from_yaml ) <EOL> def to_yaml ( cls , dumper , data ) : <EOL> """<STR_LIT>""" <EOL> return dumper . represent_yaml_object ( cls . yaml_tag , data , cls , <EOL> flow_style = cls . yaml_flow_style ) <EOL> to_yaml = classmethod ( to_yaml ) </s>
