3 Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&dIdJZ'dKdLZ(dMdNZ)dOdPZ*dQdRZ+dSdTZ,dUdVZ-dWdXZ.dYdZZ/d[d\Z0d]d^Z1d_d`Z2dadbZ3dcddZ4dedfZ5dgdhZ6didjZ7dkdlZ8dmdnZ9dodpZ:dqdrZ;dsdtZdydzZ?d{d|Z@d}d~ddddddddddddddddZAddddZBddZCddZDddZEddZFddZGddZHddZIddZJddZKdS)rcCs<d|_d|_g|_|jd|_d|_g|_d|_i|_dS)zInitialize the scanner.FrTN) done flow_leveltokensfetch_stream_start tokens_takenindentindentsallow_simple_keypossible_simple_keys)rr r r r0s zScanner.__init__cGsJx|jr|jqW|jrF|s$dSx |D]}t|jd|r*dSq*WdS)NTrF)need_more_tokensfetch_more_tokensr isinstance)rchoicesZchoicer r r check_tokenqs   zScanner.check_tokencCs*x|jr|jqW|jr&|jdSdS)Nr)rr r)rr r r peek_token}s  zScanner.peek_tokencCs:x|jr|jqW|jr6|jd7_|jjdSdS)Nrr)rr rrpop)rr r r get_tokens   zScanner.get_tokencCs2|jr dS|jsdS|j|j|jkr.dSdS)NFT)rrstale_possible_simple_keysnext_possible_simple_keyr)rr r r rszScanner.need_more_tokenscCs|j|j|j|j|j}|dkr4|jS|dkrL|jrL|jS|dkrd|jrd|j S|dkr||j r||j S|dkr|j S|dkr|j S|dkr|jS|dkr|jS|d kr|jS|dkr|jr|jS|d kr|jr|jS|d kr|jr|jS|d kr*|jS|d kr<|jS|dkrN|jS|dkrj|j rj|jS|dkr|j r|jS|dkr|jS|dkr|jS|jr|j St!ddd||j"dS)N%-.[{]},?:r&!|>'"z!while scanning for the next tokenz.found character %r that cannot start any token)#scan_to_next_tokenr' unwind_indentrpeekfetch_stream_endcheck_directivefetch_directivecheck_document_startfetch_document_startcheck_document_endfetch_document_endfetch_flow_sequence_startfetch_flow_mapping_startfetch_flow_sequence_endfetch_flow_mapping_endfetch_flow_entrycheck_block_entryfetch_block_entry check_key fetch_key check_value fetch_value fetch_alias fetch_anchor fetch_tagr fetch_literal fetch_folded fetch_single fetch_double check_plain fetch_plainrget_mark)rchr r r r s^        zScanner.fetch_more_tokenscCs:d}x0|jD]&}|j|}|dks,|j|kr |j}q W|S)N)rr )rZmin_token_numberlevelkeyr r r r(s    z Scanner.next_possible_simple_keycCs`xZt|jD]L}|j|}|j|jks6|j|jdkr |jrPtd|jd|j|j|=q WdS)Nizwhile scanning a simple keyzcould not find expected ':')listrrrr rrrX)rrZr[r r r r's   z"Scanner.stale_possible_simple_keyscCs^|j o|j|jk}|jrZ|j|jt|j}t|||j |j |j|j }||j |j<dS)N) rrrrremove_possible_simple_keyrlenrr rrrXr)rr r r[r r r save_possible_simple_key$sz Scanner.save_possible_simple_keycCs@|j|jkr<|j|j}|jr2td|jd|j|j|j=dS)Nzwhile scanning a simple keyzcould not find expected ':')rrr rrrX)rr[r r r r]5s    z"Scanner.remove_possible_simple_keycCsD|jr dSx4|j|kr>|j}|jj|_|jjt||q WdS)N)rrrXrr%rappendZ BlockEndToken)rrrr r r r;Bs   zScanner.unwind_indentcCs&|j|kr"|jj|j||_dSdS)NTF)rrr`)rrr r r add_indentZs  zScanner.add_indentcCs$|j}|jjt|||jddS)N)encoding)rXrr`ZStreamStartTokenrb)rrr r r rds zScanner.fetch_stream_startcCsB|jd|jd|_i|_|j}|jjt||d|_dS)NrFTr) r;r]rrrXrr`ZStreamEndTokenr)rrr r r r=ps zScanner.fetch_stream_endcCs,|jd|jd|_|jj|jdS)NrFr)r;r]rrr`scan_directive)rr r r r?s zScanner.fetch_directivecCs|jtdS)N)fetch_document_indicatorZDocumentStartToken)rr r r rAszScanner.fetch_document_startcCs|jtdS)N)rdZDocumentEndToken)rr r r rCszScanner.fetch_document_endcCsH|jd|jd|_|j}|jd|j}|jj|||dS)NrFr)r;r]rrXforwardrr`)r TokenClass start_markend_markr r r rds  z Scanner.fetch_document_indicatorcCs|jtdS)N)fetch_flow_collection_startZFlowSequenceStartToken)rr r r rDsz!Scanner.fetch_flow_sequence_startcCs|jtdS)N)rjZFlowMappingStartToken)rr r r rEsz Scanner.fetch_flow_mapping_startcCsJ|j|jd7_d|_|j}|j|j}|jj|||dS)NrT)r_rrrXrfrr`)rrgrhrir r r rjsz#Scanner.fetch_flow_collection_startcCs|jtdS)N)fetch_flow_collection_endZFlowSequenceEndToken)rr r r rFszScanner.fetch_flow_sequence_endcCs|jtdS)N)rkZFlowMappingEndToken)rr r r rGszScanner.fetch_flow_mapping_endcCsJ|j|jd8_d|_|j}|j|j}|jj|||dS)NrF)r]rrrXrfrr`)rrgrhrir r r rksz!Scanner.fetch_flow_collection_endcCs<d|_|j|j}|j|j}|jjt||dS)NT)rr]rXrfrr`ZFlowEntryToken)rrhrir r r rHs zScanner.fetch_flow_entrycCs|jsF|jstddd|j|j|jrF|j}|jjt||nd|_|j |j}|j |j}|jjt ||dS)Nz%sequence entries are not allowed hereT) rrrrXrarrr`ZBlockSequenceStartTokenr]rfZBlockEntryToken)rrrhrir r r rJs  zScanner.fetch_block_entrycCs|jsD|jstddd|j|j|jrD|j}|jjt|||j |_|j |j}|j |j}|jjt ||dS)Nz!mapping keys are not allowed here) rrrrXrarrr`BlockMappingStartTokenr]rfKeyToken)rrrhrir r r rLs   zScanner.fetch_keycCs|j|jkr||j|j}|j|j=|jj|j|jt|j|j|jst|j|j rt|jj|j|jt |j|jd|_ n\|js|j st ddd|j |js|j|j r|j }|jjt |||j |_ |j|j }|j|j }|jjt||dS)NFz#mapping values are not allowed here)rrrinsertr rrmrrarrlrrrXr`r]rfZ ValueToken)rr[rrhrir r r rNs2       zScanner.fetch_valuecCs$|jd|_|jj|jtdS)NF)r_rrr` scan_anchorZ AliasToken)rr r r rOVszScanner.fetch_aliascCs$|jd|_|jj|jtdS)NF)r_rrr`roZ AnchorToken)rr r r rPaszScanner.fetch_anchorcCs"|jd|_|jj|jdS)NF)r_rrr`scan_tag)rr r r rQlszScanner.fetch_tagcCs|jdddS)Nr6)style)fetch_block_scalar)rr r r rRwszScanner.fetch_literalcCs|jdddS)Nr7)rq)rr)rr r r rSzszScanner.fetch_foldedcCs$d|_|j|jj|j|dS)NT)rr]rr`scan_block_scalar)rrqr r r rr}szScanner.fetch_block_scalarcCs|jdddS)Nr8)rq)fetch_flow_scalar)rr r r rTszScanner.fetch_singlecCs|jdddS)Nr9)rq)rt)rr r r rUszScanner.fetch_doublecCs$|jd|_|jj|j|dS)NF)r_rrr`scan_flow_scalar)rrqr r r rtszScanner.fetch_flow_scalarcCs"|jd|_|jj|jdS)NF)r_rrr` scan_plain)rr r r rWszScanner.fetch_plaincCs|jdkrdSdS)NrT)r)rr r r r>s zScanner.check_directivecCs.|jdkr*|jddkr*|jddkr*dSdS)Nrrez---u …

T)rprefixr<)rr r r r@s zScanner.check_document_startcCs.|jdkr*|jddkr*|jddkr*dSdS)Nrrez...u …

T)rrwr<)rr r r rBs zScanner.check_document_endcCs|jddkS)Nru …

)r<)rr r r rIszScanner.check_block_entrycCs|jr dS|jddkSdS)NTru …

)rr<)rr r r rKszScanner.check_keycCs|jr dS|jddkSdS)NTru …

)rr<)rr r r rMszScanner.check_valuecCs6|j}|dkp4|jddko4|dkp4|j o4|dkS)Nu …

-?:,[]{}#&*!|>'"%@`ru …

r+z?:)r<r)rrYr r r rVszScanner.check_plaincCs|jdkr|jdkr|jd}xb|sx|jdkr@|jq*W|jdkrhx|jdkrf|jqPW|jr~|jsd|_q$d}q$WdS)NruF #u …

T)rr<rfscan_line_breakrr)rfoundr r r r:s   zScanner.scan_to_next_tokencCs|j}|j|j|}d}|dkr:|j|}|j}n>|dkrV|j|}|j}n"|j}x|jdkrv|jq`W|j|t||||S)NZYAMLZTAGu …

)rXrfscan_directive_namescan_yaml_directive_valuescan_tag_directive_valuer<scan_directive_ignored_lineZDirectiveToken)rrhnamevaluerir r r rcs       zScanner.scan_directivecCsd}|j|}xfd|ko"dkns`d|ko:dkns`d|koRdkns`|dkrt|d 7}|j|}qW|std |d ||j|j|}|j||j}|d krtd |d ||j|S) Nr09AZazz-_rzwhile scanning a directivez6expected alphabetic or numeric character, but found %ru …

)r<rrXrwrf)rrhlengthrYrr r r r|#s$ J  zScanner.scan_directive_namecCsx|jdkr|jqW|j|}|jdkrJtd|d|j|j|j|j|}|jdkrtd|d|j|j||fS)Nrxr,zwhile scanning a directivez%expected a digit or '.', but found %ru …

z%expected a digit or ' ', but found %r)r<rfscan_yaml_directive_numberrrX)rrhmajorminorr r r r}8s         z!Scanner.scan_yaml_directive_valuecCs|j}d|kodkns6td|d||jd}x*d|j|koTdknrd|d7}q|jq(W|j}|dkrftd|d||j|jdS)Nrxryu …

zwhile scanning a directivez0expected a comment or a line break, but found %r)r<rfrrXrz)rrhrYr r r rrs   z#Scanner.scan_directive_ignored_linec Cs|j}|j}|dkrd}nd}|jd}|j|}xfd|koLdknsd|koddknsd |ko|d kns|d kr|d 7}|j|}q:W|std ||d||j|j|}|j||j}|dkrtd ||d||j|j}||||S)NraliasZanchorrrrrrrrz-_rzwhile scanning an %sz6expected alphabetic or numeric character, but found %ru …

?:,]}%@`)rXr<rfrrw) rrgrhZ indicatorrrrYrrir r r ros2  J    zScanner.scan_anchorc Cs&|j}|jd}|dkrdd}|jd|jd|}|jdkrZtd|d|j|j|jn~|dkr~d}d }|jndd}d }x,|d kr|d krd }P|d7}|j|}qWd }|r|jd|}n d }|j|jd|}|j}|d kr td |d||j||f}|j}t|||S)Nr<tagr7zwhile parsing a tagzexpected '>', but found %ru …

r5Fu …

Tzwhile scanning a tagzexpected ' ', but found %r)rXr<rfrrrZTagToken) rrhrYrsuffixrZ use_handlerrir r r rpsH           zScanner.scan_tagcCs|dkrd}nd}g}|j}|j|j|\}}|j||jd}|dkrTd}|dkrv|j\}} } t|| } n||d} |j| \}} d} x|j| ko|j dkrt|j ||j dk} d}x|j |d kr|d7}qW|j |j ||j||j } |j| \}} |j| krp|j dkrp|rd| d krd| rd|j dkrd|sn|j d n |j | qPqW|dk r|j | |dkr|j |tdj|d|| |S) Nr7TFrr)z ru …

 rx)rXrfscan_block_scalar_indicatorsscan_block_scalar_ignored_linerscan_block_scalar_indentationmaxscan_block_scalar_breaksrr<extendr`rwrz ScalarTokenjoin)rrqZfoldedchunksrhchomping incrementZ min_indentbreaks max_indentrir line_breakZleading_non_spacerr r r rssP              zScanner.scan_block_scalarcCsd}d}|j}|dkrn|dkr&d}nd}|j|j}|dkrt|}|dkrdtd|d|j|jn\|dkrt|}|dkrtd|d|j|j|j}|dkr|dkrd}nd}|j|j}|d krtd|d ||j||fS) Nz+-+TF 0123456789rzwhile scanning a block scalarz|jq(W|j}|dkrftd|d||j|jdS)Nrxryu …

zwhile scanning a block scalarz0expected a comment or a line break, but found %r)r<rfrrXrz)rrhrYr r r rAs    z&Scanner.scan_block_scalar_ignored_linecCshg}d}|j}xL|jdkr\|jdkrB|j|j|j}q|j|j|kr|j}qW|||fS)Nru …

rx)rXr<r`rzrfr)rrrrir r r rOs    z%Scanner.scan_block_scalar_indentationcCsg}|j}x"|j|kr.|jdkr.|jqWxJ|jdkrz|j|j|j}x"|j|krv|jdkrv|jqVWq2W||fS)Nrxu …

)rXrr<rfr`rz)rrrrir r r r^s z Scanner.scan_block_scalar_breakscCs|dkrd}nd}g}|j}|j}|j|j|j||x4|j|krt|j|j|||j|j||qBW|j|j}tdj|d|||S)Nr9TFr)rXr<rfrscan_flow_scalar_non_spacesscan_flow_scalar_spacesrr)rrqdoublerrhZquoterir r r rukszScanner.scan_flow_scalarr) r   rxr9\… u
u
)rrbtrnvfrerxr9rN_LPr)xuUcCsg}xd}x|j|dkr&|d7}qW|rF|j|j||j||j}| r|dkr|jddkr|jd|jdq|r|dks| r|dkr|j||jq|o|dkr|j|j}||jkr|j|j||jn||jkr||j|}|jxBt|D]6}|j|dkrtd |d ||j|f|jqWt |j|d }|jt ||j|n<|d kr|j |j |j ||ntd |d ||jq|SqWdS)Nru'"\ …

rr8rz"\r0123456789ABCDEFabcdefz%while scanning a double-quoted scalarz?expected escape sequence of %d hexdecimal numbers, but found %ru …

z!found unknown escape character %r)r<r`rwrfESCAPE_REPLACEMENTS ESCAPE_CODESrangerrXrchrrzrscan_flow_scalar_breaks)rrrhrrrYkcoder r r rsL            z#Scanner.scan_flow_scalar_non_spacesc Csg}d}x|j|dkr"|d7}q W|j|}|j||j}|dkr\td|d|jnT|dkr|j}|j||}|dkr|j|n|s|jd |j|n |j||S) Nrz rr)zwhile scanning a quoted scalarzfound unexpected end of streamu …

rrx) r<rwrfrrXrzrr`r) rrrhrr whitespacesrYrrr r r rs(        zScanner.scan_flow_scalar_spacescCsg}xx|jd}|dks |dkr@|jddkr@td|d|jx|jdkrX|jqBW|jdkrv|j|jq|SqWdS) Nrez---z...u …

zwhile scanning a quoted scalarz#found unexpected document separatorz u …

)rwr<rrXrfr`rz)rrrhrrwr r r rs    zScanner.scan_flow_scalar_breakscCsNg}|j}|}|jd}g}xd}|jdkr4PxP|j|}|dksx|j rj|dkrj|j|ddksx|jrz|dkrzP|d7}q6W|jr|dkr|j|ddkr|j|td|d |jd |dkrPd |_|j||j|j ||j||j}|j ||}| s4|jdks4|j r"|j |kr"Pq"Wt d j |d ||S)Nrrryu …

r3z,:?[]{}u …

,[]{}zwhile scanning a plain scalarzfound unexpected ':'zGPlease check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.FrT)rXrr<rrfrrrr`rwscan_plain_spacesrrr)rrrhrirZspacesrrYr r r rvsF        zScanner.scan_plainc Cs.g}d}x|j|dkr"|d7}q W|j|}|j||j}|dkr|j}d|_|jd}|dksr|dkr|jdd krdSg} x`|jd kr|jdkr|jq| j|j|jd}|dks|dkr|jdd krdSqW|d kr|j|n| s|jd|j| n|r*|j||S) Nrrxru …

Trez---z...u …

u …

r)r<rwrfrzrr`r) rrrhrrrrYrrwrr r r r!s>            zScanner.scan_plain_spacescCs|j}|dkr*td||d||jd}|j|}|dkrxfd|koTdknsd|kold knsd |kod kns|d kr|d7}|j|}qBW|dkr|j|td||d||j|d7}|j|}|j||S) Nr5zwhile scanning a %szexpected '!', but found %rrrxrrrrrrz-_)r<rrXrfrw)rrrhrYrrr r r rFs&  J    zScanner.scan_tag_handlecCsg}d}|j|}xd|ko&dknsdd|ko>dknsdd|koVdknsd|dkr|d kr|j|j||j|d}|j|j||n|d 7}|j|}qW|r|j|j||j|d}|std ||d ||jd j|S)Nrrrrrrrz-;/?:@&=+$,_.!~*'()[]%r*rzwhile parsing a %szexpected URI, but found %rr)r<r`rwrfscan_uri_escapesrrXr)rrrhrrrYr r r r^s( J   zScanner.scan_tag_uricCsg}|j}xx|jdkr|jx>tdD]2}|j|dkr,td||d|j||jq,W|jt|jdd|jdqWyt|j d}Wn8t k r}ztd||t ||WYdd}~XnX|S)Nr*rrzwhile scanning a %szBexpected URI escape sequence of 2 hexdecimal numbers, but found %rrzutf-8) rXr<rfrrr`rrwbytesdecodeUnicodeDecodeErrorstr)rrrhZcodesrrrexcr r r rws  (zScanner.scan_uri_escapescCsN|j}|dkr6|jddkr*|jdn|jdS|dkrJ|j|SdS)Nu …rz ru

r)r<rwrf)rrYr r r rzs  zScanner.scan_line_breakN)Lrrrrr#r$r&rr r(r'r_r]r;rarr=r?rArCrdrDrErjrFrGrkrHrJrLrNrOrPrQrRrSrrrTrUrtrWr>r@rBrIrKrMrVr:rcr|r}rr~rrrrorprsrrrrrurrrrrrvrrrrrzr r r r r.sA   l    !8       #    $)L( +/%N)__all__errorrrrr rr r r r s