܍~c\PddlmZddlmZddlmZmZmZmZddl Z e j Z eddZ Gdde j Z Gd d e j Ze d e jGd d e jjZdeeeeefffdZdZddZdS)) namedtuple)chain)AnyDictListTupleNSchemaPathMarks)path start_markend_markceZdZfdZxZS)_CustomSafeLoadercFt|SN)superconstruct_scalar)selfnode __class__s 4/usr/lib/python3/dist-packages/cloudinit/safeyaml.pyconstruct_python_unicodez*_CustomSafeLoader.construct_python_unicodesww''---)__name__ __module__ __qualname__r __classcell__rs@rrrs8.........rrcHeZdZdZfdZdZfdZdfd ZfdZxZ S) _CustomSafeLoaderWithMarksaA loader which provides line and column start and end marks for YAML. If the YAML loaded represents a dictionary, get_single_data will inject a top-level "schemamarks" key in that dictionary which can be used at call-sites to process YAML paths schemamark metadata when annotating YAML files for errors. The schemamarks key is dictionary where each key is a dot-delimited path into the YAML object. Each dot represents an element that is nested under a parent and list items are represented with the format `.`. The values in schemamarks will be the line number in the original content where YAML element begins to aid in annotation when encountering schema errors. The example YAML shows expected schemamarks for both dicts and lists: one: val1 two: subtwo: val2 three: [val3, val4] schemamarks == { "one": 1, "two": 2, "two.subtwo": 3, "three": 4, "three.0": 4, "three.1": 4 } cXt|i|_dSr)r__init__schemamarks_by_line)rstreamrs rr!z#_CustomSafeLoaderWithMarks.__init__:s)    EG   rc|jj|jvr&|j|jjdddSt|jdD]\}}|dddD]x}|jj|jjkr\|jj|jjkrB|jj|jjkr(|jj|jjkr|jdccSydS)Nr.T)reverse)r liner"sorteditemscolumnr r )rr _line_num schema_marksmarks r_get_nested_path_prefixz2_CustomSafeLoaderWithMarks._get_nested_path_prefix>s  ? 4#; ; ;.t/CDQGJMMM M'-  $ * * , ,d( ( ( + + #I|%TTrT* + +O(DO,@@@.$/2HHH *dm.@@@ , 0DDD"i???***** +rrc\t|}||}|jD]l\}}||j}|jj}t ||j|j}||jvr |g|j|<L|j| |m|Sr) rconstruct_mappingr0valuer r)r r r"append) rrmappingnested_path_prefixkey_node value_node node_key_pathline_numr/rs rr2z,_CustomSafeLoaderWithMarks.construct_mappingNs''++D11!99$??$(J @ @ Hj1C8>CCM*/H"x2J4GDt7776:V(22(299$????rFcpt|d}||}t|jD]g\}}|jj}||}t||j|j} ||j vr | g|j |<G|j | | h|S)NT)deep) rconstruct_sequencer0 enumerater3r r)r r r"r4) rrr<sequencer6index sequence_itemr:r9marksrs rr=z-_CustomSafeLoaderWithMarks.construct_sequence]s77--d->>!99$??$-dj$9$9 A A E=$/4H1:5::M#}79OEt7776;W(22(299%@@@@rct}t|tr:tdt |jD|d<|S)Nc:g|]}|j|jjdzfS))r r r)).0vs r z>_CustomSafeLoaderWithMarks.get_single_data..ps9VQ\.23r schemamarks)rget_single_data isinstancedictrr"values)rdatars rrJz*_CustomSafeLoaderWithMarks.get_single_datalsuww&&(( dD ! ! "&"D$<$C$C$E$EF##D   r)F) rrr__doc__r!r0r2r=rJrrs@rrrs:HHHHH                    rrz tag:yaml.org,2002:python/unicodeceZdZdZdZdS)NoAliasSafeDumperz>A class which avoids constructing anchors/aliases on yaml dumpcdS)NT)rrNs rignore_aliasesz NoAliasSafeDumper.ignore_aliasesstrN)rrrrOrTrSrrrQrQ~s)HHrrQreturnctj|t}t|tsi}n|d}||fS)aPerform YAML SafeLoad and track start and end marks during parse. JSON schema errors come with an encoded object path such as: .. YAML loader needs to preserve a mapping of schema path to line and column marks to annotate original content with JSON schema error marks for the command: cloud-init devel schema --annotate LoaderrI)yamlloadrrKrLpop)blobresultrIs rload_with_marksr^sNYt$> ? ? ?F fd # #0 jj// ; rc8tj|tS)NrW)rYrZr)r\s rrZrZs 9T"3 4 4 44rTFc htj|dd||d|rtntjjS)z%Return data in nicely formatted yaml. F) line_breakindentexplicit_start explicit_enddefault_flow_styleDumper)rYdumprQdumper SafeDumper)objrerfnoaliass rdumpsrnsB 9 %! %,H!!$+2H   r)TTF) collectionsr itertoolsrtypingrrrrrY YAMLErrorr SafeLoaderrradd_constructorrrjrkrQstrintr^rZrnrSrrrws#""""")))))))))))) N *9 ........ YYYYYYYYx!!&.  .U3S#X#67*555      r