U
    g
                     @  sX   d dl mZ d dlZd dlmZmZ dgZdddddd	d
ZddddddddZdS )    )annotationsN)AnyIterablelazy_importstrzdict[str, Any]r   )namesource	namespacereturnc                 C  sR   d}|| dkr.|d7 }|t |k stdqt||d |d| g|}t|| S )aN  
    Import ``name`` from ``source`` in ``namespace``.

    There are two use cases:

    - ``name`` is an object defined in ``source``;
    - ``name`` is a submodule of ``source``.

    Neither :func:`__import__` nor :func:`~importlib.import_module` does
    exactly this. :func:`__import__` is closer to the intended behavior.

    r   .   z%importing from parent isn't supportedN)lenAssertionError
__import__getattr)r   r   r	   levelmodule r   6/tmp/pip-unpacked-wheel-dx_q7dq3/websockets/imports.pyimport_name
   s    r   zdict[str, str] | NoneNone)r	   aliasesdeprecated_aliasesr
   c                   s    dkri  dkri t t  t @ r@td@ rPtd@ r`tdd ddd fdd}|d	< d
dfdd}|d< dS )a  
    Provide lazy, module-level imports.

    Typical use::

        __getattr__, __dir__ = lazy_import(
            globals(),
            aliases={
                "<name>": "<source module>",
                ...
            },
            deprecated_aliases={
                ...,
            }
        )

    This function defines ``__getattr__`` and ``__dir__`` per :pep:`562`.

    Nznamespace conflict__name__r   r   )r   r
   c                   s    d k	st z |  }W n tk
r,   Y nX t| |S d k	sFt z|  }W n tk
rf   Y n*X tj d|  dtdd t| |S tdd| d S )Nr   z is deprecated   )
stacklevelzmodule z has no attribute )r   KeyErrorr   warningswarnDeprecationWarningAttributeError)r   r   )r   r   r	   packager   r   __getattr__F   s$    z lazy_import.<locals>.__getattr__r"   zIterable[str])r
   c                     s   t  B B S )N)sortedr   )aliases_setdeprecated_aliases_setnamespace_setr   r   __dir__`   s    zlazy_import.<locals>.__dir__r'   )setr   )r	   r   r   r"   r'   r   )r   r$   r   r%   r	   r&   r!   r   r      s    )NN)	
__future__r   r   typingr   r   __all__r   r   r   r   r   r   <module>   s     