B
    ]b
                 @  s`   d dl mZ d dlZd dlmZmZ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DictIterableOptionallazy_importstrzDict[str, Any]r   )namesource	namespacereturnc             C  sV   d}x,|| dkr0|d7 }|t |k stdqW 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   1lib/python3.7/site-packages/websockets/imports.pyimport_name
   s    r   zOptional[Dict[str, str]]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 y |  }W n tk
r,   Y nX t| |S d k	sFt y|  }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)Z
__future__r   r   typingr   r   r   r   __all__r   r   r   r   r   r   <module>   s    