Ë
    Ìiƒ  ã                  óŒ   — d dl mZ d dlmZ d dlmZmZ d dlZ	 dZ G d„ d«      Z	 G d„ d	«      Z
 G d
„ dej                  «      Zy)é    )Úannotations)ÚStringIO)ÚDictÚIteratorNÚ__parsing_context__c                  ó2   — e Zd ZdZdd„Zedd„«       Zdd„Zy)ÚParsingContextz_Container class for file slice information used to populate model metadata for certain objects.c                ó<   — || _         || _        || _        || _        y)z¾Initializer for the ParsingContext class.

        The contents are represented internally as a yaml.Node in order to allow for lazy serialization to
        string representations.
        N)Ú
start_lineÚend_lineÚfilenameÚ_content_node)Úselfr   r   r   Úcontent_nodes        úl/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt_semantic_interfaces/parsing/yaml_loader.pyÚ__init__zParsingContext.__init__   s!   € ð %ˆŒØ ˆŒØ ˆŒØ)ˆÕó    c                óB   — t        j                  | j                  ¬«      S )zÃSerialized contents associated with the file slice represented by this ParsingContext object.

        This should only be called when a string representation of the contents are needed.
        )Únode)ÚyamlÚ	serializer   ©r   s    r   ÚcontentzParsingContext.content   s   € ô �~‰~ 4×#5Ñ#5Ô6Ð6r   c                ó:   — d| j                   › d| j                  › �S )Nzline: z, filename: )r   r   r   s    r   Ú__str__zParsingContext.__str__#   s   € Ø˜Ÿ™Ð(¨°T·]±]°OÐDÐDr   N)
r   Úintr   r   r   Ústrr   z	yaml.NodeÚreturnÚNone)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   © r   r   r	   r	      s$   „ Ùió	*ð ò7ó ð7ôEr   r	   c                  ó4   — e Zd ZdZedd„«       Zedd„«       Zy)ÚYamlConfigLoaderzMHelper class for loading YAML config strings into an iterator of YAML output.c              #  ó¦   K  — t        |¬«      5 }| |_        t        j                  |t        ¬«      D ]  }|–— Œ 	 ddd«       y# 1 sw Y   yxY w­w)a6  Wraps the yaml.load_all method and returns the resulting iterator with parsing context added to output.

        This replaces any calls to yaml.load_all(loader=SafeLineLoaderWithAddedContext), which internally adds
        ParsingContext info. Note PyYAML reads the name property from the input stream IF that input stream is a file
        object, otherwise it replaces it with a constant. Therefore, we use as StringIO instance to pass the contents
        into PyYAML and set the value of the name property on the file object to the name parameter here.
        )Úinitial_value)ÚstreamÚLoaderN)r   Únamer   Úload_allÚSafeLineLoaderWithAddedContext)r,   Úcontentsr*   Údocuments       r   Úload_all_with_contextz&YamlConfigLoader.load_all_with_context*   sM   è ø€ ô  HÔ-ð 	°ØˆFŒKÜ ŸM™M°Ô@^Ô_ò �Ø“ñ÷	÷ 	ñ 	üs   ‚A�,A¼	AÁAÁ
Ac                óJ   — | j                  d«      xs | j                  d«      S )zAChecks if YAML file name ends with one of the supported suffixes.z.yamlz.yml)Úendswith)r   s    r   Úis_valid_yaml_file_endingz*YamlConfigLoader.is_valid_yaml_file_ending8   s%   € ð × Ñ  Ó)ÒF¨X×->Ñ->¸vÓ-FÐFr   N)r,   r   r/   r   r   r   )r   r   r   Úbool)r    r!   r"   r#   Ústaticmethodr1   r4   r%   r   r   r'   r'   '   s-   „ ÙWàòó ðð òGó ñGr   r'   c                  ó&   ‡ — e Zd ZdZddˆ fd„Zˆ xZS )r.   z›Adds special field __parsing_context__ to all mappings.

    Credit: https://stackoverflow.com/questions/13319067/parsing-yaml-return-with-line-number
    c                óÚ   •— t         t        | �  ||¬«      }t        |j                  j
                  dz   |j                  j
                  |j                  j                  |«      |t        <   |S )aá  Override of the construct_mapping method in the PyYAML SafeLoader class.

        This override exists in order to populate the parsing context object with file location
        and raw YAML content information, which will be used to populate the Metadata model construct
        for nodes which request it. The file identifier (node.start_mark.name) is derived from the
        name property on the file-like object passed in as the stream parameter of the load_all call.
        The line numbers are part of the start and end mark properties.

        The content_node is a PyYAML node. We do not serialize it inside the loader because it's a full
        serialization pass on whatever contents this particular mapping node might contain, which could
        be the entire model collection. Rather, we store the node and serialize it on-demand later.

        Note: PyYAML uses metaclasses quite heavily so construct_mapping is in fact defined in the
        SafeConstructor class.
        )Údeepé   )	Úsuperr.   Úconstruct_mappingr	   Ú
start_markÚlineÚend_markr,   ÚPARSING_CONTEXT_KEY)r   r   r9   ÚmappingÚ	__class__s       €r   r<   z0SafeLineLoaderWithAddedContext.construct_mappingH   sb   ø€ ô  Ô6¸ÑOÐPTÐ[_ÐOÓ`ˆÜ'5Ø�O‰O× Ñ  1Ñ$ d§m¡m×&8Ñ&8¸$¿/¹/×:NÑ:NÐPTó(
ˆÔ#Ñ$ð ˆr   )F)r   zyaml.MappingNoder9   r5   r   r   )r    r!   r"   r#   r<   Ú__classcell__)rB   s   @r   r.   r.   >   s   ø„ ñ÷ò r   r.   )Ú
__future__r   Úior   Útypingr   r   r   r@   r	   r'   Ú
SafeLoaderr.   r%   r   r   ú<module>rH      sE   ðÝ "å ß !ã ðTà+Ð ÷Eñ E÷4Gñ Gô. T§_¡_õ r   