U
    ¯ªh1
  ã                   @   sô   d Z ddlZddlZddlZddlmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZmZ dd	lmZ dd
lmZ dd„ Zdd„ Z e eeeeeeeeeeeƒ eedƒ dddddddddg	Z!dS )aH  
This magical module will rewrite all public methods in the public interface
of the library so they can run the loop on their own if it's not already
running. This rewrite may not be desirable if the end user always uses the
methods they way they should be ran, but it's incredibly useful for quick
scripts and the runtime overhead is relatively low.

Some really common methods which are hardly used offer this ability by
default, such as ``.start()`` and ``.run_until_disconnected()`` (since
you may want to start, and then run until disconnected while using async
event handlers).
é    Né   )ÚeventsÚerrorsÚutilsÚ
connectionÚhelpers)Ú_TakeoutClient)ÚTelegramClient)ÚtypesÚ	functionsÚcustom)ÚDraftÚDialogÚMessageButtonÚForwardÚButtonÚMessageÚInlineResultÚConversation)Ú
ChatGetter)ÚSenderGetterc                    s<   t | |ƒ‰ t ˆ ¡‡ fdd„ƒ}t|dˆ ƒ t| ||ƒ d S )Nc                     s,   ˆ | |Ž}t  ¡ }| ¡ r|S | |¡S d S )N)r   Zget_running_loopZ
is_runningZrun_until_complete)ÚargsÚkwargsÚcoroZloop©Úmethod© ú1/tmp/pip-unpacked-wheel-c81u5j2r/telethon/sync.pyÚ	syncified    s
    
z _syncify_wrap.<locals>.syncifiedz	__tl.sync)ÚgetattrÚ	functoolsÚwrapsÚsetattr)ÚtÚmethod_namer   r   r   r   Ú_syncify_wrap   s
    
	r%   c                  G   sH   | D ]>}t |ƒD ]0}| d¡r&|dkrt t||ƒ¡rt||ƒ qqdS )zÉ
    Converts all the methods in the given types (class definitions)
    into synchronous, which return either the coroutine or the result
    based on whether ``asyncio's`` event loop is running.
    Ú_Ú__call__N)ÚdirÚ
startswithÚinspectÚiscoroutinefunctionr   r%   )r
   r#   Únamer   r   r   Úsyncify.   s
    	r-   Z_get_resultr	   r   r
   r   r   r   r   r   r   )"Ú__doc__Zasyncior    r*   Ú r   r   r   r   r   Zclient.accountr   Zclient.telegramclientr	   Útlr
   r   r   Z	tl.customr   r   r   r   r   r   r   r   Ztl.custom.chatgetterr   Ztl.custom.sendergetterr   r%   r-   Ú__all__r   r   r   r   Ú<module>   s>   (     ÿ
      ý