관리-도구
편집 파일: safeyaml.cpython-39.opt-1.pyc
a ����'�Dgm(����������������������@���s����d�dl�Z�d�dlmZ�d�dlmZ�d�dlmZmZmZm Z �d�dl Z d�dlmZ�e�� e�ZG�dd��d�Zdd ��Zee�d �dd�Zeee�ee�d �dd�ZG�dd��de j�ZG�dd��de jj�Ze�d�e eeeef�f�d�dd��Ze�d�ddd��ZdS�)�����N)�defaultdict)�chain)�Any�Dict�List�Tuple)�performancec�������������������@���s2���e�Zd�Zeejejd�dd�Zdd��Zdd��ZdS�) �SchemaPathMarks��path� start_mark�end_markc�����������������C���s���||�_�||�_||�_d�S��Nr ���)�selfr���r���r �����r����6/usr/lib/python3.9/site-packages/cloudinit/safeyaml.py�__init__���s����zSchemaPathMarks.__init__c�����������������C���sp���|j�j|�j�jk�s |jj|�jjkr$dS�|j�j|�j�jkrH|j�j|�j�jk�rHdS�|jj|�jjkrl|jj|�jjkrldS�dS�)z;Return whether other start/end marks are within self marks.FT)r����liner ����column�r����otherr���r���r����__contains__���s ����������zSchemaPathMarks.__contains__c�����������������C���s@���|�j�j|j�jko>|�j�j|j�jko>|�jj|jjko>|�jj|jjkS�r���)r���r���r���r ���r���r���r���r����__eq__/���s�������zSchemaPathMarks.__eq__N) �__name__� __module__�__qualname__�str�yamlZMarkr���r���r���r���r���r���r���r ������s���r ���c�����������������C���s0���|d�d�d��D�]}|�|v�r|�|ks|��S�qd�S�)N���r���)Z child_mark�marks�markr���r���r����_find_closest_parent8���s���� r!���)� line_marksc�����������������C���s\���|�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 ����parentZpath_prefixZ _path_idxr���r���r����_reparent_schema_mark_children?���s���� �r)���)�new_markr����returnc�����������������C���sb���g�}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 ���r���r���r����_add_mark_and_reparent_marksN���s���� r.���c�����������������������sP���e�Zd�ZdZ��fdd�Zdd��Zd ��fdd� Zd��fd d � Z��fdd�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 `<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��������������������s���t����|��tt�|�_d�S�r���)�superr���r����list�schemamarks_by_line)r����stream�� __class__r���r���r�������s�����z#_CustomSafeLoaderWithMarks.__init__c�����������������C���s����|j�j|�jv�rb|�j|j�j�d�}|�j|j�j�dd���D�]}||v�r6||v�r6|}q6||v�rb|jd�S�t|�j���dd�D�]8\}}|d�d�d��D�] }||v�r�|j��d�����S�q�qtdS�)Nr���r$���r#���T)�reverser�����)r���r���r2���r����sorted�items)r����nodeZmost_specific_markZ path_markZ _line_num�schema_marksr ���r���r���r����_get_nested_path_prefix����s(������� �z2_CustomSafeLoaderWithMarks._get_nested_path_prefixFc��������������������sr���t���j||d�}|��|�}|jD�]L\}}|��|j���}|jj}t||j|j�} |�j|�} t | | �}||�j|<�q |S�)N��deep) r0����construct_mappingr<����valuer���r���r ���r ���r2���r.���)r���r:���r>����mapping�nested_path_prefixZkey_nodeZ value_node� node_key_path�line_numr*���r;���r-���r4���r���r���r?�������s���� � z,_CustomSafeLoaderWithMarks.construct_mappingc����������� ��� ������s��t���j|dd�}|��|�}t|j�D�]�\}}|jj}|��|���}t||j|j�} ||�j vrh| g|�j |<�q$||jjkr�|�j |�} t | | �}||�j |<�q$t||jj�D�]b}||�j v�r�|�j |�} t | | �}||kr�| d�j|kr�|� dt|| d�j| d�j���||�j |<�q�q$|S�)NTr=���r���r���)r0����construct_sequencer<���� enumerater@���r���r���r ���r ���r2���r.����ranger����insert) r���r:���r>���ZsequencerB����indexZ sequence_itemrD���rC���r*���r;���r-���Z inner_liner4���r���r���rE�������sL���� � �� �����z-_CustomSafeLoaderWithMarks.construct_sequencec��������������������s8���t������}t|t�r4tdd��t|�j�����D���|d<�|S�)Nc�����������������S���s���g�|�]}|j�|jjd��f�qS�)r$���)r���r���r���)�.0�vr���r���r���� <listcomp>����s����z>_CustomSafeLoaderWithMarks.get_single_data.<locals>.<listcomp>�schemamarks)r0����get_single_data� isinstance�dictr���r2����values�r����datar4���r���r���rN�������s���� ��z*_CustomSafeLoaderWithMarks.get_single_data)F)F) r���r���r����__doc__r���r<���r?���rE���rN���� __classcell__r���r���r4���r���r/���q���s���*r/���c�������������������@���s���e�Zd�ZdZdd��ZdS�)�NoAliasSafeDumperz>A class which avoids constructing anchors/aliases on yaml dumpc�����������������C���s���dS�)NTr���rR���r���r���r����ignore_aliases����s����z NoAliasSafeDumper.ignore_aliasesN)r���r���r���rT���rW���r���r���r���r���rV�������s���rV���zLoading yaml)r+���c�����������������C���s0���t�j|�td�}t|t�si�}n |�d�}||fS�)a���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 )�LoaderrM���)r����loadr/���rO���rP����pop)Zblob�resultrM���r���r���r����load_with_marks����s ���� r\���zDumping yamlTFc�������������� ���C���s$���t�j|�dd||d|rtnt�jjd�S�)z%Return data in nicely formatted yaml.� ����F)Z line_break�indent�explicit_start�explicit_endZdefault_flow_styleZDumper)r����dumprV����dumper� SafeDumper)�objr`���ra���Znoaliasr���r���r����dumps��s�����rf���)TTF)Zlogging�collectionsr���� itertoolsr����typingr���r���r���r���r���Z cloudinitr���Z getLoggerr���ZLOGr ���r!���r)���r.���Z SafeLoaderr/���rc���rd���rV���Ztimedr����intr\���rf���r���r���r���r����<module>���s$��� "�#}