3 Z d?d@Z!dAdBZ"dCS)Gr!ztag:yaml.org,2002:)r z!!cCs*d|_d|_i|_g|_g|_|j|_dS)N) current_event yaml_version tag_handlesstatesmarksparse_stream_startstate)selfr r r __init__Qs zParser.__init__cCsg|_d|_dS)N)rr)rr r r disposeYszParser.disposecGsN|jdkr|jr|j|_|jdk rJ|s,dSx|D]}t|j|r2dSq2WdS)NTF)r r isinstance)rchoicesZchoicer r r check_event^s     zParser.check_eventcCs |jdkr|jr|j|_|jS)N)r r)rr r r peek_eventks  zParser.peek_eventcCs*|jdkr|jr|j|_|j}d|_|S)N)r r)rvaluer r r get_eventrs   zParser.get_eventcCs(|j}t|j|j|jd}|j|_|S)N)encoding) get_tokenZStreamStartEvent start_markend_markrparse_implicit_document_startr)rtokeneventr r r rs   zParser.parse_stream_startcCs\|jtttsP|j|_|j}|j}}t||dd}|j j |j |j |_ |S|jSdS)NF)explicit) check_tokenDirectiveTokenDocumentStartTokenStreamEndToken DEFAULT_TAGSr peek_tokenrDocumentStartEventrappendparse_document_endparse_block_noderparse_document_start)rr!rrr"r r r r s z$Parser.parse_implicit_document_startcCsx|jtr|jqW|jts|j}|j}|j\}}|jtsdtddd|jj |jj|j}|j }t ||d||d}|j j |j|j|_n|j}t|j|j }d|_|S)Nz)expected '', but found %rT)r#versiontags)r$DocumentEndTokenrr'r)rprocess_directivesr&ridrr*rr+r,parse_document_contentrZStreamEndEvent)rr!rr/r0rr"r r r r.s*         zParser.parse_document_startcCsL|j}|j}}d}|jtr2|j}|j}d}t|||d}|j|_|S)NFT)r#) r)rr$r1rrZDocumentEndEventr.r)rr!rrr#r"r r r r,s  zParser.parse_document_endcCs<|jttttr0|j|jj}|jj |_ |S|j SdS)N) r$r%r&r1r'process_empty_scalarr)rrpoprr-)rr"r r r r4s   zParser.parse_document_contentcCsd|_i|_x|jtr|j}|jdkrp|jdk rDtddd|j|j\}}|dkrftddd|j|j|_q|jdkr|j\}}||jkrtddd||j||j|<qW|jr|j|jj f}n |jdf}x(|j D]}||jkr|j ||j|<qW|S)NZYAMLzfound duplicate YAML directiverz:found incompatible YAML document (version 1.* is required)ZTAGzduplicate tag handle %r) r rr$r%rnamerrrcopyr()rr!majorminorhandleprefixrkeyr r r r2s8            zParser.process_directivescCs |jddS)NT)block) parse_node)rr r r r-szParser.parse_block_nodecCs|jS)N)r?)rr r r parse_flow_node szParser.parse_flow_nodecCs|jdddS)NT)r>indentless_sequence)r?)rr r r 'parse_block_node_or_indentless_sequencesz.Parser.parse_block_node_or_indentless_sequenceFc CsR|jtr4|j}t|j|j|j}|jj|_ nd}d}d}}} |jt r|j}|j}|j}|j}|jt r|j}|j} |j}|j}nF|jt r|j}|j}} |j}|j}|jt r|j}|j}|j}|dk r&|\} } | dk r"| |j krt d|d| | |j | | }n| }|dkr>|jj}}d}|dkpR|dk} |r|jtr|jj}t||| ||}|j|_ n|jtr|j}|j}|jr|dks|dkrd } n|dkrd} nd} t||| |j|||jd}|jj|_ nH|jtr<|jj}t||| ||dd}|j|_ n|jtrp|jj}t||| ||dd}|j|_ n|r|jtr|jj}t||| ||dd}|j|_ n|r|jtr|jj}t||| ||dd}|j|_ nj|dk s|dk rt||| dfd||}|jj|_ n2|r(d } nd } |j}t d | |d |j|j|S)Nzwhile parsing a nodezfound undefined tag handle %rr TF)style) flow_styler>Zflowzwhile parsing a %s nodez'expected the node content, but found %r)TF)FT)FF) r$Z AliasTokenrZ AliasEventrrrrr6rZ AnchorTokenZTagTokenrrr)BlockEntryTokenZSequenceStartEventparse_indentless_sequence_entryZ ScalarTokenZplain ScalarEventrCZFlowSequenceStartTokenparse_flow_sequence_first_entryZFlowMappingStartTokenMappingStartEventparse_flow_mapping_first_keyZBlockSequenceStartToken parse_block_sequence_first_entryZBlockMappingStartTokenparse_block_mapping_first_keyr3)rr>rAr!r"ZanchortagrrZtag_markr;suffixZimplicitZnoder r r r?s                               zParser.parse_nodecCs|j}|jj|j|jS)N)rrr+rparse_block_sequence_entry)rr!r r r rLxsz'Parser.parse_block_sequence_first_entrycCs|jtrH|j}|jtts4|jj|j|jS|j|_|j |j S|jtsv|j }t d|j dd|j|j|j}t|j|j }|jj|_|j j|S)Nz while parsing a block collectionrz"expected , but found %r)r$rFr BlockEndTokenrr+rPr-rr5rr)rrr3rSequenceEndEventr6)rr!r"r r r rP}s        z!Parser.parse_block_sequence_entrycCsr|jtrL|j}|jtttts8|jj|j|j S|j|_ |j |j S|j }t|j|j}|jj|_ |S)N)r$rFrKeyToken ValueTokenrRrr+rGr-rr5rr)rSrr6)rr!r"r r r rGs    z&Parser.parse_indentless_sequence_entrycCs|j}|jj|j|jS)N)rrr+rparse_block_mapping_key)rr!r r r rMsz$Parser.parse_block_mapping_first_keycCs|jtrJ|j}|jttts6|jj|j|jS|j|_ |j |j S|jtsx|j }t d|jdd|j|j|j}t|j|j }|jj|_ |jj|S)Nzwhile parsing a block mappingrz"expected , but found %rrQ)r$rTrrUrRrr+parse_block_mapping_valuerBrr5rr)rrr3rMappingEndEventr6)rr!r"r r r rVs       zParser.parse_block_mapping_keycCsl|jtrL|j}|jttts6|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rUrrTrRrr+rVrBrr5rr)r)rr!r r r rWs z Parser.parse_block_mapping_valuecCs"|j}|jj|j|jddS)NT)first)rrr+rparse_flow_sequence_entry)rr!r r r rIsz&Parser.parse_flow_sequence_first_entrycCs|jts|sF|jtr"|jn$|j}td|jdd|j|j|jt r||j}t ddd|j|j dd}|j |_ |S|jts|jj|j|jS|j}t|j|j }|jj|_ |jj|S)Nzwhile parsing a flow sequencerzexpected ',' or ']', but got %rT)rDrQ)r$FlowSequenceEndTokenFlowEntryTokenrr)rrr3rrTrJr%parse_flow_sequence_entry_mapping_keyrrr+rZr@rSr6)rrYr!r"r r r rZs,        z Parser.parse_flow_sequence_entrycCsD|j}|jttts,|jj|j|jS|j|_ |j |j SdS)N) rr$rUr\r[rr+'parse_flow_sequence_entry_mapping_valuer@rr5r)rr!r r r r]sz,Parser.parse_flow_sequence_entry_mapping_keycCsj|jtrJ|j}|jtts4|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rUrr\r[rr+%parse_flow_sequence_entry_mapping_endr@rr5rr)r)rr!r r r r^s  z.Parser.parse_flow_sequence_entry_mapping_valuecCs|j|_|j}t|j|jS)N)rZrr)rXr)rr!r r r r_sz,Parser.parse_flow_sequence_entry_mapping_endcCs"|j}|jj|j|jddS)NT)rY)rrr+rparse_flow_mapping_key)rr!r r r rKsz#Parser.parse_flow_mapping_first_keycCs|jts|sF|jtr"|jn$|j}td|jdd|j|j|jt r|j}|jt tts||j j |j |jS|j |_|j|jSn |jts|j j |j|jS|j}t|j|j}|j j|_|jj|S)Nzwhile parsing a flow mappingrzexpected ',' or '}', but got %rrQ)r$FlowMappingEndTokenr\rr)rrr3rrTrUrr+parse_flow_mapping_valuer@rr5rparse_flow_mapping_empty_valuerXr6)rrYr!r"r r r r`s.        zParser.parse_flow_mapping_keycCsj|jtrJ|j}|jtts4|jj|j|jS|j|_ |j |j Sn|j|_ |j }|j |j SdS)N)r$rUrr\rarr+r`r@rr5rr)r)rr!r r r rb9s  zParser.parse_flow_mapping_valuecCs|j|_|j|jjS)N)r`rr5r)r)rr r r rcGsz%Parser.parse_flow_mapping_empty_valuecCstdddd||S)NTFrE)TF)rH)rZmarkr r r r5KszParser.process_empty_scalarN)FF)F)F)#rrrr(rrrrrrr r.r,r4r2r-r@rBr?rLrPrGrMrVrWrIrZr]r^r_rKr`rbrcr5r r r r rHsB    / g    N)__all__errorrtokensZeventsscannerrrr r r r >s