o
    w!guG                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZ erHd dlmZ d d	lmZmZmZmZmZmZ ed
ZdddZG dd dZG dd dZG dd dZG dd dZG dd deeeeZ dS )    )annotationsN)suppress)TYPE_CHECKINGAnyTypeVar)Kind)AliasResolutionErrorBuiltinModuleErrorCyclicAliasError)merge_stubs)Sequence)Alias	AttributeClassFunctionModuleObject_ObjTypekeystr | Sequence[str]returnSequence[str]c                 C  s:   t | tr| std| d}nt| }|std|S )NzEmpty strings are not supported.zEmpty tuples are not supported)
isinstancestr
ValueErrorsplitlist)r   parts r   P/mnt/skqttb/ctump_chatbot/chatbot/lib/python3.10/site-packages/_griffe/mixins.py
_get_parts   s   
r!   c                   @  $   e Zd ZdZdddZddd	Zd
S )GetMembersMixinzMixin class to share methods for accessing members.

    Methods:
        get_member: Get a member with its name or path.
        __getitem__: Same as `get_member`, with the item syntax `[]`.
    r   r   r   r   c                 C  s<   t |}t|dkr| j|d  S | j|d  |dd  S )a  Get a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Members will be looked up in both declared members and inherited ones,
        triggering computation of the latter.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> foo = griffe_object["foo"]
            >>> bar = griffe_object["path.to.bar"]
            >>> qux = griffe_object[("path", "to", "qux")]
           r   N)r!   lenall_membersselfr   r   r   r   r    __getitem__*   s   zGetMembersMixin.__getitem__c                 C  s>   t |}t|dkr| j|d  S | j|d  |dd S )a  Get a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Members will be looked up in declared members only, not inherited ones.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> foo = griffe_object["foo"]
            >>> bar = griffe_object["path.to.bar"]
            >>> bar = griffe_object[("path", "to", "bar")]
        r$   r   N)r!   r%   members
get_memberr'   r   r   r    r+   @   s   zGetMembersMixin.get_memberN)r   r   r   r   )__name__
__module____qualname____doc__r)   r+   r   r   r   r    r#   "   s    
r#   c                   @  r"   )DelMembersMixinzMixin class to share methods for deleting members.

    Methods:
        del_member: Delete a member with its name or path.
        __delitem__: Same as `del_member`, with the item syntax `[]`.
    r   r   r   Nonec                 C  sd   t |}t|dkr$|d }z| j|= W dS  ty#   | j|= Y dS w | j|d  |dd = dS )a  Delete a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Members will be looked up in both declared members and inherited ones,
        triggering computation of the latter.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> del griffe_object["foo"]
            >>> del griffe_object["path.to.bar"]
            >>> del griffe_object[("path", "to", "qux")]
        r$   r   N)r!   r%   r*   KeyErrorinherited_membersr&   r(   r   r   namer   r   r    __delitem__a   s   zDelMembersMixin.__delitem__c                 C  sH   t |}t|dkr|d }| j|= dS | j|d  |dd  dS )a  Delete a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Members will be looked up in declared members only, not inherited ones.

        Parameters:
            key: The name or path of the member.

        Examples:
            >>> griffe_object.del_member("foo")
            >>> griffe_object.del_member("path.to.bar")
            >>> griffe_object.del_member(("path", "to", "qux"))
        r$   r   N)r!   r%   r*   
del_memberr4   r   r   r    r7   |   s
    zDelMembersMixin.del_memberN)r   r   r   r1   )r,   r-   r.   r/   r6   r7   r   r   r   r    r0   Y   s    
r0   c                   @  s$   e Zd ZdZddd	Zdd
dZdS )SetMembersMixinzMixin class to share methods for setting members.

    Methods:
        set_member: Set a member with its name or path.
        __setitem__: Same as `set_member`, with the item syntax `[]`.
    r   r   valueObject | Aliasr   r1   c                 C  s^   t |}t|dkr |d }|| j|< | jr| |_dS | |_dS || j|d  |dd < dS )a  Set a member with its name or path.

        This method is part of the consumer API:
        do not use when producing Griffe trees!

        Parameters:
            key: The name or path of the member.
            value: The member.

        Examples:
            >>> griffe_object["foo"] = foo
            >>> griffe_object["path.to.bar"] = bar
            >>> griffe_object[("path", "to", "qux")] = qux
        r$   r   N)r!   r%   r*   is_collection_modules_collectionparent)r(   r   r9   r   r5   r   r   r    __setitem__   s   


zSetMembersMixin.__setitem__c              	   C  s<  t |}t|dkr|d }|| jv r{| j| }|js{|jr\|js\|js\ttt	t
* |jrM|j|jkrMtt t||}W d   n1 sHw   Y  W d   n1 sWw   Y  |j D ]}tt	 ||_W d   n1 suw   Y  qa|| j|< | jr| |_dS | |_dS | j|d  |dd | dS )a  Set a member with its name or path.

        This method is part of the producer API:
        you can use it safely while building Griffe trees
        (for example in Griffe extensions).

        Parameters:
            key: The name or path of the member.
            value: The member.

        Examples:
            >>> griffe_object.set_member("foo", foo)
            >>> griffe_object.set_member("path.to.bar", bar)
            >>> griffe_object.set_member(("path", "to", "qux"), qux)
        r$   r   N)r!   r%   r*   is_alias	is_moduleis_namespace_packageis_namespace_subpackager   r   r
   r	   filepathr   r   aliasesvaluestargetr;   r<   r=   
set_member)r(   r   r9   r   r5   memberaliasr   r   r    rG      s0   






"zSetMembersMixin.set_memberN)r   r   r9   r:   r   r1   )r,   r-   r.   r/   r>   rG   r   r   r   r    r8      s    
r8   c                   @  s.   e Zd ZdZdddd
dZedddZdS )SerializationMixinzMixin class to share methods for de/serializing objects.

    Methods:
        as_json: Return this object's data as a JSON string.
        from_json: Create an instance of this class from a JSON string.
    F)fullrK   boolkwargsr   r   r   c                K  s$   ddl m} tj| f||d|S )a  Return this object's data as a JSON string.

        Parameters:
            full: Whether to return full info, or just base info.
            **kwargs: Additional serialization options passed to encoder.

        Returns:
            A JSON string.
        r   )JSONEncoder)clsrK   )_griffe.encodersrN   jsondumps)r(   rK   rM   rN   r   r   r    as_json   s   
zSerializationMixin.as_jsonrO   type[_ObjType]json_stringr   c                 K  sF   ddl m} |d| tj|fi |}t|| s!td|  |S )a  Create an instance of this class from a JSON string.

        Parameters:
            json_string: JSON to decode into Object.
            **kwargs: Additional options passed to decoder.

        Returns:
            An Object instance.

        Raises:
            TypeError: When the json_string does not represent and object
                of the class from which this classmethod has been called.
        r   )json_decoderobject_hookz$provided JSON object is not of type )rP   rV   
setdefaultrQ   loadsr   	TypeError)rO   rU   rM   rV   objr   r   r    	from_json   s   
zSerializationMixin.from_jsonN)rK   rL   rM   r   r   r   )rO   rT   rU   r   rM   r   r   r   )r,   r-   r.   r/   rS   classmethodr\   r   r   r   r    rJ      s
    rJ   c                   @  s   e Zd ZdZed$ddZed%ddZed&d
dZed'ddZed(ddZ	ed)ddZ
ed)ddZed)ddZed)ddZed)ddZed)ddZed)dd Zed)d!d"Zd#S )*ObjectAliasMixina  Mixin class to share methods that appear both in objects and aliases, unchanged.

    Attributes:
        all_members: All members (declared and inherited).
        modules: The module members.
        classes: The class members.
        functions: The function members.
        attributes: The attribute members.
        is_private: Whether this object/alias is private (starts with `_`) but not special.
        is_class_private: Whether this object/alias is class-private (starts with `__` and is a class member).
        is_special: Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`).
        is_imported: Whether this object/alias was imported from another module.
        is_exported: Whether this object/alias is exported (listed in `__all__`).
        is_wildcard_exposed: Whether this object/alias is exposed to wildcard imports.
        is_public: Whether this object is considered public.
        is_deprecated: Whether this object is deprecated.
    r   dict[str, Object | Alias]c                 C  s   | j ri | j| jS | jS )zAll members (declared and inherited).

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        )is_classr3   r*   r(   r   r   r    r&   $  s   zObjectAliasMixin.all_membersdict[str, Module]c                 C     dd | j  D S )z~The module members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  "   i | ]\}}|j tju r||qS r   )kindr   MODULE.0r5   rH   r   r   r    
<dictcomp>6     " z,ObjectAliasMixin.modules.<locals>.<dictcomp>r&   itemsra   r   r   r    modules/     zObjectAliasMixin.modulesdict[str, Class]c                 C  rc   )z}The class members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  rd   r   )re   r   CLASSrg   r   r   r    ri   ?  rj   z,ObjectAliasMixin.classes.<locals>.<dictcomp>rk   ra   r   r   r    classes8  rn   zObjectAliasMixin.classesdict[str, Function]c                 C  rc   )zThe function members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  rd   r   )re   r   FUNCTIONrg   r   r   r    ri   H  rj   z.ObjectAliasMixin.functions.<locals>.<dictcomp>rk   ra   r   r   r    	functionsA  rn   zObjectAliasMixin.functionsdict[str, Attribute]c                 C  rc   )zThe attribute members.

        This method is part of the consumer API:
        do not use when producing Griffe trees!
        c                 S  rd   r   )re   r   	ATTRIBUTErg   r   r   r    ri   Q  rj   z/ObjectAliasMixin.attributes.<locals>.<dictcomp>rk   ra   r   r   r    
attributesJ  rn   zObjectAliasMixin.attributesrL   c                 C  s   | j do	| j S )zGWhether this object/alias is private (starts with `_`) but not special._)r5   
startswith
is_specialra   r   r   r    
is_privateS     zObjectAliasMixin.is_privatec                 C  s   | j do| j dS )z[Whether this object/alias is special ("dunder" attribute/method, starts and end with `__`).__)r5   ry   endswithra   r   r   r    rz   X  s   zObjectAliasMixin.is_specialc                 C  s(   | j o| j jo| jdo| jd S )zTWhether this object/alias is class-private (starts with `__` and is a class member).r}   )r=   r`   r5   ry   r~   ra   r   r   r    is_class_private]  s   (z!ObjectAliasMixin.is_class_privatec                 C  s   | j o	| j| j jv S )z;Whether this object/alias was imported from another module.)r=   r5   importsra   r   r   r    is_importedb  r|   zObjectAliasMixin.is_importedc                 C  s"   | j jot| j jo| j| j jv S )z<Whether this object/alias is exported (listed in `__all__`).)r=   r@   rL   exportsr5   ra   r   r   r    is_exportedg  s   "zObjectAliasMixin.is_exportedc                 C  sP   | j r| jjs	dS | jjdur| j| jjv S | jdrdS | jp'| j p'| jS )a  Whether this object/alias is exposed to wildcard imports.

        To be exposed to wildcard imports, an object/alias must:

        - be available at runtime
        - have a module as parent
        - be listed in `__all__` if `__all__` is defined
        - or not be private (having a name starting with an underscore)

        Special case for Griffe trees: a submodule is only exposed if its parent imports it.

        Returns:
            True or False.
        FNrx   )runtimer=   r@   r   r5   ry   r?   r   ra   r   r   r    is_wildcard_exposedl  s   z$ObjectAliasMixin.is_wildcard_exposedc                 C  sl   | j dur| j S | js| jr| jdsdS | jr*| jjr*t| jjr*| j| jjv S | jr/dS | j	r4dS dS )a  Whether this object is considered public.

        In modules, developers can mark objects as public thanks to the `__all__` variable.
        In classes however, there is no convention or standard to do so.

        Therefore, to decide whether an object is public, we follow this algorithm:

        - If the object's `public` attribute is set (boolean), return its value.
        - If the object is listed in its parent's (a module) `__all__` attribute, it is public.
        - If the parent (module) defines `__all__` and the object is not listed in, it is private.
        - If the object has a private name, it is private.
        - If the object was imported from another module, it is private.
        - Otherwise, the object is public.
        Nrx   TF)
publicr?   r@   r5   ry   r=   rL   r   r{   r   ra   r   r   r    	is_public  s   
zObjectAliasMixin.is_publicc                 C  s
   t | jS )z"Whether this object is deprecated.)rL   
deprecatedra   r   r   r    is_deprecated  s   
zObjectAliasMixin.is_deprecatedN)r   r_   )r   rb   )r   ro   )r   rr   )r   ru   )r   rL   )r,   r-   r.   r/   propertyr&   rm   rq   rt   rw   r{   rz   r   r   r   r   r   r   r   r   r   r    r^     s8    
,r^   )r   r   r   r   )!
__future__r   rQ   
contextlibr   typingr   r   r   _griffe.enumerationsr   _griffe.exceptionsr   r	   r
   _griffe.mergerr   collections.abcr   _griffe.modelsr   r   r   r   r   r   r   r!   r#   r0   r8   rJ   r^   r   r   r   r    <module>   s"    
7<N.