0 #ˆl–ß=¿J µ2ÛR‚œP-\l˜´oà ƒuçŸÂÅÆÑa '¡Dgm(ã@sþddlZddlmZddlmZddlmZmZmZm Z ddl Z ddl m Z e  e¡ZGdd„dƒZdd „Zeed œd d „Zeeeeed œdd„ZGdd„de jƒZGdd„de jjƒZe  d¡e eeeeffdœdd„ƒZe  d¡ddd„ƒZdS)éN)Ú defaultdict)Úchain)ÚAnyÚDictÚListÚTuple)Ú performancec@s2eZdZeejejdœdd„Zdd„Zdd„ZdS) ÚSchemaPathMarks©ÚpathÚ start_markÚend_markcCs||_||_||_dS©Nr )Úselfr r r ©rú6/usr/lib/python3.9/site-packages/cloudinit/safeyaml.pyÚ__init__szSchemaPathMarks.__init__cCsp|jj|jjks |jj|jjkr$dS|jj|jjkrH|jj|jjkrHdS|jj|jjkrl|jj|jjkrldSdS)z;Return whether other start/end marks are within self marks.FT)r Úliner Úcolumn©rÚotherrrrÚ __contains__s ÿþÿþÿþzSchemaPathMarks.__contains__cCs@|jj|jjko>|jj|jjko>|jj|jjko>|jj|jjkSr)r rrr rrrrÚ__eq__/sÿþüzSchemaPathMarks.__eq__N) Ú__name__Ú __module__Ú __qualname__ÚstrÚyamlZMarkrrrrrrrr sr cCs0|ddd…D]}||vr||ks|SqdS)Néÿÿÿÿr)Z child_markÚmarksÚmarkrrrÚ_find_closest_parent8s r!)Ú line_markscCs\|D]R}t||ƒ}|r|j dd¡\}}|j|jksB|j |j¡s|j ||jd¡|_qdS)zP Update any SchemaPathMarks.path for items not under the proper parent. Ú.éN)r!r ÚrsplitÚ startswithÚreplace)r"r ÚparentZ path_prefixZ _path_idxrrrÚ_reparent_schema_mark_children?s ÿr))Únew_markrÚreturncCsbg}d}|D]8}||vr$| |¡q ||vr:d}| |¡| |¡q |rTt|ƒn | |¡|S)a=Insert new_mark into marks, ordering ancestors first. Reparent existing SchemaPathMarks.path when new_mark is a parent of an existing mark item. Because schema processing is depth first, leaf/child mappings and sequences may be processed for SchemaPathMarks before their parents. This leads to SchemaPathMarks.path of 'grandchildren' being incorrectly parented by the root dictionary instead of an intermediary parents below root. Walk through the list of existing marks and reparent marks that are contained within the new_mark. FT)Úappendr))r*rÚ new_marksZreparent_pathsr rrrÚ_add_mark_and_reparent_marksNs     r.csPeZdZdZ‡fdd„Zdd„Zd ‡fdd„ Zd‡fd d „ Z‡fd d „Z‡Z S)Ú_CustomSafeLoaderWithMarksaïA 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 } cstƒ |¡ttƒ|_dSr)ÚsuperrrÚ