U
    ŒPÓh9  ã                   @  sP   d dl mZ d dlmZ ddgZd dlmZmZ G dd„ dƒZG dd„ dƒZ	dS )	é    )Úannotations)ÚwrapsÚRestartGeneratorÚMethodReplacer)ÚCallableÚ	Generatorc                   @  s.   e Zd ZdZdddœdd„Zddœd	d
„ZdS )r   zÜ
    Wraps a generator callable which will be called whenever this class is iterated and its result returned. This is
    used to create an iterator which can start iteration over the given generator multiple times.
    zCallable[[], Generator]ÚNone)Ú
create_genÚreturnc                 C  s
   || _ d S ©N©r	   )Úselfr	   © r   úK/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/utils/decorators.pyÚ__init__   s    zRestartGenerator.__init__r   )r
   c                 C  s   |   ¡ S r   r   )r   r   r   r   Ú__iter__   s    zRestartGenerator.__iter__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   c                   @  s4   e Zd ZdZdZdddœdd„Zdd	„ Zd
d„ ZdS )r   z
    Base class for method decorators which can be used to replace methods pass to replace_method() with wrapped versions.
    Z__replacemethods__r   r   )Úmethr
   c                 C  s
   || _ d S r   )r   ©r   r   r   r   r   r   )   s    zMethodReplacer.__init__c                 C  s   |S )zl
        Return a new method to replace `meth` in the instantiated object, or `meth` to do nothing.
        r   r   r   r   r   Úreplace_method,   s    zMethodReplacer.replace_methodc                   sŠ   ˆ |ˆj f}t|ˆjƒsL|j‰tˆƒ‡‡fdd„ƒ}||_t|ˆj|gƒ n,t|ˆjƒ}t‡ fdd„|D ƒƒsx| |¡ t|ˆ ˆj	ƒ dS )aš  
        Add the (name,self.replace_method) pair to the list named by replace_list_name in `owner`, creating the list and
        replacing the constructor of `owner` if necessary. The replaced constructor will call the old one then do the
        replacing operation of substituting, for each (name,self.replace_method) pair, the named method with the returned
        value from self.replace_method.
        c                   sT   ˆ | f|ž|Ž t | ˆjƒD ]2\}}}t| |ƒrt | |ƒ}||ƒ}t| ||ƒ qd S r   )ÚgetattrÚreplace_list_nameÚ
isinstanceÚsetattr)Ú_selfÚargsÚkwargsÚmÚownerÚreplacerr   Znewmeth)Úoldinitr   r   r   Únewinit?   s    

z,MethodReplacer.__set_name__.<locals>.newinitc                 3  s   | ]}|d  ˆ kV  qdS )r   Nr   )Ú.0Únl)Únamer   r   Ú	<genexpr>O   s     z.MethodReplacer.__set_name__.<locals>.<genexpr>N)
r   Úhasattrr   r   r   r   r   ÚanyÚappendr   )r   r!   r'   Úentryr$   Únamelistr   )r'   r#   r   r   Ú__set_name__2   s    

zMethodReplacer.__set_name__N)r   r   r   r   r   r   r   r.   r   r   r   r   r   "   s
   N)
Ú
__future__r   Ú	functoolsr   Ú__all__Útypingr   r   r   r   r   r   r   r   Ú<module>   s
   