U ŒPÓh9 ã@sPddlmZddlmZddgZddlmZmZGdd„dƒZGdd„dƒZ dS) é)Ú annotations)ÚwrapsÚRestartGeneratorÚMethodReplacer)ÚCallableÚ Generatorc@s.eZdZdZdddœdd„Zddœd d „Zd S) rzÜ 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. zCallable[[], Generator]ÚNone)Ú create_genÚreturncCs ||_dS©N©r )Úselfr ©rúK/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/utils/decorators.pyÚ__init__szRestartGenerator.__init__r)r cCs| ¡Sr r )r rrrÚ__iter__szRestartGenerator.__iter__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrsc@s4eZdZdZdZdddœdd„Zdd „Zd d „Zd S) rz Base class for method decorators which can be used to replace methods pass to replace_method() with wrapped versions. Z__replacemethods__rr)Úmethr cCs ||_dSr )r©r rrrrr)szMethodReplacer.__init__cCs|S)zl Return a new method to replace `meth` in the instantiated object, or `meth` to do nothing. rrrrrÚreplace_method,szMethodReplacer.replace_methodcsŠˆ|ˆjf}t|ˆjƒsL|j‰tˆƒ‡‡fdd„ƒ}||_t|ˆj|gƒn,t|ˆjƒ}t‡fdd„|Dƒƒsx| |¡t|ˆˆj ƒdS)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. csTˆ|f|ž|Žt|ˆjƒD]2\}}}t||ƒrt||ƒ}||ƒ}t|||ƒqdSr )ÚgetattrÚreplace_list_nameÚ isinstanceÚsetattr)Ú_selfÚargsÚkwargsÚmÚownerÚreplacerrZnewmeth)Úoldinitr rrÚnewinit?s   z,MethodReplacer.__set_name__..newinitc3s|]}|dˆkVqdS)rNr)Ú.0Únl)ÚnamerrÚ Osz.MethodReplacer.__set_name__..N) rÚhasattrrrrrrÚanyÚappendr)r r!r'Úentryr$Únamelistr)r'r#r rÚ __set_name__2s     zMethodReplacer.__set_name__N)rrrrrrrr.rrrrr"s N) Ú __future__rÚ functoolsrÚ__all__ÚtypingrrrrrrrrÚ s