ó
    x[hm(  ã                   ó¬  • S SK r S SKJr  S SKJr  S SKJrJrJrJ	r	  S SK
r
S SKJr  \ R                  " \5      r " S S5      rS rS	\\   4S
 jrS\S\\   S\\   4S jr " S S\
R(                  5      r " S S\
R,                  R.                  5      r\R2                  " S5      S\	\\\\4   4   4S j5       r\R2                  " S5      SS j5       rg)é    N)Údefaultdict)Úchain)ÚAnyÚDictÚListÚTuple)Úperformancec                   ó^   • \ rS rSrS\S\R                  S\R                  4S jrS rS r	Sr
g	)
ÚSchemaPathMarksé   ÚpathÚ
start_markÚend_markc                 ó(   • Xl         X l        X0l        g ©N)r   r   r   )Úselfr   r   r   s       Ú4/usr/lib/python3/dist-packages/cloudinit/safeyaml.pyÚ__init__ÚSchemaPathMarks.__init__   s   € ØŒ	Ø$ŒØ �ó    c                 ó2  • UR                   R                  U R                   R                  :  d.  UR                  R                  U R                  R                  :”  a  gUR                   R                  U R                   R                  :X  a/  UR                   R                  U R                   R                  :  a  gUR                  R                  U R                  R                  :X  a/  UR                  R                  U R                  R                  :”  a  gg)z;Return whether other start/end marks are within self marks.FT)r   Úliner   Úcolumn©r   Úothers     r   Ú__contains__ÚSchemaPathMarks.__contains__   s¾   € ð ×Ñ×!Ñ! D§O¡O×$8Ñ$8Ó8Ø�~‰~×"Ñ" T§]¡]×%7Ñ%7Ó7àà×Ñ×!Ñ! T§_¡_×%9Ñ%9Ó9Ø× Ñ ×'Ñ'¨$¯/©/×*@Ñ*@Ó@àà�N‰N×Ñ 4§=¡=×#5Ñ#5Ó5Ø—‘×%Ñ%¨¯©×(<Ñ(<Ó<àØr   c                 ó”  • U R                   R                  UR                   R                  :H  =(       a•    U R                   R                  UR                   R                  :H  =(       aa    U R                  R                  UR                  R                  :H  =(       a-    U R                  R                  UR                  R                  :H  $ r   )r   r   r   r   r   s     r   Ú__eq__ÚSchemaPathMarks.__eq__/   sŒ   € à�O‰O× Ñ  E×$4Ñ$4×$9Ñ$9Ñ9÷ >Ø—‘×&Ñ&¨%×*:Ñ*:×*AÑ*AÑA÷>à—‘×"Ñ" e§n¡n×&9Ñ&9Ñ9÷>ð —‘×$Ñ$¨¯©×(=Ñ(=Ñ=ð		
r   )r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚstrÚyamlÚMarkr   r   r   Ú__static_attributes__© r   r   r   r      s.   † ð!˜Sð !¨d¯i©ið !À4Ç9Á9ô !ò
õ&
r   r   c                 óB   • US S S2    H  nX;   d  M
  X:X  a  M  Us  $    g )Néÿÿÿÿr)   )Ú
child_markÚmarksÚmarks      r   Ú_find_closest_parentr/   8   s)   € Ø‘d˜�d”ˆØÕ jÕ&8ØŠKñ ð r   Ú
line_marksc                 ó\  • U  H¦  n[        X5      nU(       d  M  UR                  R                  SS5      u  p4UR                  UR                  :X  d,  UR                  R                  UR                  5      (       a  M{  UR                  R	                  X2R                  S5      Ul        M¨     g)zH
Update any SchemaPathMarks.path for items not under the proper parent.
Ú.é   N)r/   r   ÚrsplitÚ
startswithÚreplace)r0   r.   ÚparentÚpath_prefixÚ	_path_idxs        r   Ú_reparent_schema_mark_childrenr:   ?   s�   € ó ˆÜ% dÓ7ˆßˆ6Ø%)§Y¡Y×%5Ñ%5°c¸1Ó%=Ñ"ˆKØ�y‰y˜FŸK™KÓ'¨t¯y©y×/CÑ/CØ—‘÷0ó 0ð !ŸI™I×-Ñ-¨k¿;¹;ÈÓJ�–	ò r   Únew_markr-   Úreturnc                 óì   • / nSnU HD  nX@;  a  UR                  U5        M  X;  a  SnUR                  U 5        UR                  U5        MF     U(       a  [        U5        U$ UR                  U 5        U$ )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_marksÚreparent_pathsr.   s        r   Ú_add_mark_and_reparent_marksrA   N   s�   € ð" €IØ€NÛˆØÓØ×Ñ˜TÔ"ÙØÓ$Ø!ˆNà×Ñ˜XÔ&Ø×Ñ˜Öñ ö Ü& yÔ1ð Ðð 	×Ñ˜Ô"ØÐr   c                   ó^   ^ • \ rS rSrSrU 4S jrS rS	U 4S jjrS	U 4S jjrU 4S jr	Sr
U =r$ )
Ú_CustomSafeLoaderWithMarkséq   a›  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
`<parent>.<list-index>`.

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
}
c                 óL   >• [         TU ]  U5        [        [        5      U l        g r   )Úsuperr   r   ÚlistÚschemamarks_by_line)r   ÚstreamÚ	__class__s     €r   r   Ú#_CustomSafeLoaderWithMarks.__init__�   s    ø€ Ü‰Ñ˜Ô äœÓð 	Õ r   c                 óÞ  • UR                   R                  U R                  ;   aw  U R                  UR                   R                     S   nU R                  UR                   R                     SS   H  nX;   d  M
  X2;   d  M  UnM     X;   a  UR                  S-   $ [	        U R                  R                  5       SS9 H,  u  pEUS S S2    H  nX;   d  M
  UR                   S3s  s  $    M.     g)Nr   r3   r2   T)Úreverser+   Ú )r   r   rH   r   ÚsortedÚitems)r   ÚnodeÚmost_specific_markÚ	path_markÚ	_line_numÚschema_marksr.   s          r   Ú_get_nested_path_prefixÚ2_CustomSafeLoaderWithMarks._get_nested_path_prefix•   sì   € Ø�?‰?×Ñ 4×#;Ñ#;Ó;à!%×!9Ñ!9Ø—‘×$Ñ$ñ"àñ"Ðð "×5Ñ5°d·o±o×6JÑ6JÑKØ�ó�	ð Õ$¨Õ)HØ)2Ò&ñ	ð
 Ó)Ø)×.Ñ.°Ñ4Ð4Ü'-Ø×$Ñ$×*Ñ*Ó,°dô(
Ñ#ˆIð %¡T r TÔ*�Ø•<Ø"Ÿi™i˜[¨˜?Ô*ó +ñ(
ð r   c                 óJ  >• [         TU ]  XS9nU R                  U5      nUR                   Hs  u  pVU UR                   3nUR                  R
                  n[        XuR                  UR                  5      n	U R                  U   n
[        Xš5      nX°R                  U'   Mu     U$ )N©Údeep)
rF   Úconstruct_mappingrV   Úvaluer   r   r   r   rH   rA   )r   rQ   rZ   ÚmappingÚnested_path_prefixÚkey_nodeÚ
value_nodeÚnode_key_pathÚline_numr;   rU   r?   rJ   s               €r   r[   Ú,_CustomSafeLoaderWithMarks.construct_mappingª   s¨   ø€ Ü‘'Ñ+¨DÐ+Ð<ˆØ!×9Ñ9¸$Ó?ÐØ$(§J¤JÑ ˆHØ1Ð2°8·>±>Ð2BÐCˆMØ×*Ñ*×/Ñ/ˆHÜ&Ø×2Ñ2°J×4GÑ4GóˆHð  ×3Ñ3°HÑ=ˆLÜ4°XÓLˆIØ1:×$Ñ$ XÓ.ñ %/ð ˆr   c                 ó"  >• [         TU ]  USS9nU R                  U5      n[        UR                  5       GHT  u  pVUR
                  R                  nU U 3n[        X†R
                  UR                  5      n	XpR                  ;  a  U	/U R                  U'   Mc  XvR                  R                  :X  a*  U R                  U   n
[        Xš5      nX°R                  U'   M¦  [        XvR                  R                  5       H‹  nXÀR                  ;   d  M  U R                  U   n
[        Xš5      nXÇ:X  aJ  U
S   R                  U:w  a7  UR                  S[        UU
S   R
                  U
S   R                  5      5        X°R                  U'   M�     GMW     U$ )NTrY   r   r+   )rF   Úconstruct_sequencerV   Ú	enumerater\   r   r   r   r   rH   rA   Úranger   Úinsert)r   rQ   rZ   Úsequencer^   ÚindexÚsequence_itemrb   ra   r;   rU   r?   Ú
inner_linerJ   s                €r   re   Ú-_CustomSafeLoaderWithMarks.construct_sequence¸   s�  ø€ Ü‘7Ñ-¨d¸Ð-Ð>ˆØ!×9Ñ9¸$Ó?ÐÜ$-¨d¯j©j×$9Ñ ˆEØ$×/Ñ/×4Ñ4ˆHØ1Ð2°5°'Ð:ˆMÜ&Ø×7Ñ7¸×9OÑ9OóˆHð ×7Ñ7Ó7Ø6>°Z�×(Ñ(¨Ó2à×5Ñ5×:Ñ:Ó:Ø#'×#;Ñ#;¸HÑ#E�LÜ <Ø ó!�Ið :C×,Ñ,¨XÓ6ä&+Ø ×"8Ñ"8×"=Ñ"=ö'˜
ð &×)AÑ)AÕAØ+/×+CÑ+CÀJÑ+O˜LÜ(DØ (ó)˜Ið !+Ó 6Ø$0°¡O×$8Ñ$8¸MÓ$Ià )× 0Ñ 0Ø$%Ü$3Ø(5Ø(4°Q©×(BÑ(BØ(4°RÑ(8×(AÑ(Aó%&ô!"ð DM×4Ñ4°ZÓ@ô)'ñ! %:ðJ ˆr   c                 ó  >• [         TU ]  5       n[        U[        5      (       a`  [        [	        U R
                  R                  5       6  Vs/ s H(  nUR                  UR                  R                  S-   4PM*     sn5      US'   U$ s  snf )Nr3   Úschemamarks)
rF   Úget_single_dataÚ
isinstanceÚdictr   rH   Úvaluesr   r   r   )r   ÚdataÚvrJ   s      €r   rp   Ú*_CustomSafeLoaderWithMarks.get_single_dataâ   s�   ø€ Ü‰wÑ&Ó(ˆÜ�dœD×!Ñ!Ü"&ô # D×$<Ñ$<×$CÑ$CÓ$EÑFóâF˜ð —V‘V˜QŸ\™\×.Ñ.°Ñ2Ó3ÙFñó#ˆD�Ñð ˆùòs   Á/B)rH   )F)r!   r"   r#   r$   Ú__doc__r   rV   r[   re   rp   r(   Ú__classcell__)rJ   s   @r   rC   rC   q   s'   ø† ñõ:
ò÷*÷(÷T	ó 	r   rC   c                   ó   • \ rS rSrSrS rSrg)ÚNoAliasSafeDumperéî   z>A class which avoids constructing anchors/aliases on yaml dumpc                 ó   • g)NTr)   )r   rt   s     r   Úignore_aliasesÚ NoAliasSafeDumper.ignore_aliasesñ   s   € Ør   r)   N)r!   r"   r#   r$   rw   r}   r(   r)   r   r   rz   rz   î   s
   † ÙHõr   rz   zLoading yamlc                 ó�   • [         R                  " U [        S9n[        U[        5      (       d  0 nX4$ UR                  S5      nX4$ )ai  Perform YAML SafeLoad and track start and end marks during parse.

JSON schema errors come with an encoded object path such as:
    <key1>.<key2>.<list_item_index>

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


)ÚLoaderro   )r&   ÚloadrC   rq   rr   Úpop)ÚblobÚresultro   s      r   Úload_with_marksr…   õ   sK   € ô �YŠY�tÔ$>Ñ?€FÜ�fœd×#Ñ#Øˆð ÐÐð —j‘j Ó/ˆØÐÐr   zDumping yamlc           
      ó„   • [         R                  " U SSUUSU(       a  [        S9$ [         R                  R                  S9$ )z%Return data in nicely formatted yaml.Ú
é   F)Ú
line_breakÚindentÚexplicit_startÚexplicit_endÚdefault_flow_styleÚDumper)r&   Údumprz   ÚdumperÚ
SafeDumper)Úobjr‹   rŒ   Únoaliass       r   Údumpsr”     sF   € ô �9Š9ØØØØ%Ø!Ø Þ%,Ô!ñð ô 37·+±+×2HÑ2Hñð r   )TTF)ÚloggingÚcollectionsr   Ú	itertoolsr   Útypingr   r   r   r   r&   Ú	cloudinitr	   Ú	getLoggerr!   ÚLOGr   r/   r:   rA   Ú
SafeLoaderrC   r�   r‘   rz   Útimedr%   Úintr…   r”   r)   r   r   Ú<module>rŸ      s÷   ðó Ý #Ý ß )Ó )ã å !à×Ò˜Ó!€÷
ñ 
òDðK¨t°OÑ/Dô Kð Øð Ø&*¨?Ñ&;ð à	ˆ/Ñô ôFz §¡ô zôz˜Ÿ™×.Ñ.ô ð ×Ò�>Ó"ð˜U 3¨¨S°#¨X©Ð#6Ñ7ó ó #ðð* ×Ò�>Ó"ó
ó #ñ
r   