U Ph@snddlmZddlmZddlmZddlmZmZddl m Z m Z m Z m Z e dZddZGd d d Zd S) ) annotations) namedtuple) iskeyword)dedentindent)AnyCallableIterableTypeVarTcCs|ot| S)zNReturns True if `name` is a valid Python variable name and also not a keyword.) isidentifierr)namerP/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/utils/component_store.py is_variablesrc@seZdZdZeddZddddddZddd d d d d Zddd dddZe ddddZ dddddZ ddddZ ddddZ dd Zdd!dd"d#Zdd!dd$d%Zd&S)'ComponentStorea Represents a storage object for other objects (specifically functions) keyed to a name with a description. These objects act as global named places for storing components for objects parameterised by component names. Typically this is functions although other objects can be added. Printing a component store will produce a list of members along with their docstring information if present. Example: .. code-block:: python TestStore = ComponentStore("Test Store", "A test store for demo purposes") @TestStore.add_def("my_func_name", "Some description of your function") def _my_func(a, b): '''A description of your function here.''' return a * b print(TestStore) # will print out name, description, and 'my_func_name' with the docstring func = TestStore["my_func_name"] result = func(7, 6) _Component) descriptionvaluestrNone)r rreturncCs8i|_||_||_d|d|d|jp(d|_dS)NComponent Store '':  ) componentsr r__doc__strip)selfr rrrr__init__7szComponentStore.__init__r )r descrrcCs&t|std||||j|<|S)zGStore the object `value` under the name `name` with description `desc`.z1Name of component must be valid Python identifier)r ValueErrorrr)rr r!rrrradd>szComponentStore.addr)r r!rcsfdd}|S)z]Returns a decorator which stores the decorated function under `name` with description `desc`.cs|S)z'Decorator to add a function to a store.)r#)funcr!r rrrdecoIsz$ComponentStore.add_def..decor)rr r!r&rr%radd_defFszComponentStore.add_defztuple[str, ...])rcCs t|jS)z- Produces all factory names. )tuplerrrrrnamesOszComponentStore.namesbool)r rcCs ||jkS)z)Returns True if the given name is stored.)rrr rrr __contains__WszComponentStore.__contains__intcCs t|jS)z(Returns the number of stored components.)lenrr)rrr__len__[szComponentStore.__len__r ccs$|jD]\}}||jfVq dS)zYields name/component pairs.N)ritemsr)rkvrrr__iter___szComponentStore.__iter__cCsd|jd|jd}|jD]j\}}|d|d7}t|jdrz|jjrztt|jj d d}|d|d7}q |d |j7}q |S) Nrrz Available components:z * :rrz  ) r rrr1hasattrrrrrlstriprstrip)rresultr2r3docrrr__str__dszComponentStore.__str__rcCs$||jkr|j|jS||SdS)/Returns the stored object under the given name.N)rr__getattribute__r,rrr __getattr__qs  zComponentStore.__getattr__cCs*||jkr|j|jStd|ddS)r=z Component 'z ' not foundN)rrr"r,rrr __getitem__xs  zComponentStore.__getitem__N)__name__ __module__ __qualname__rrrr r#r'propertyr*r-r0r4r<r?r@rrrrrs   rN) __future__r collectionsrkeywordrtextwraprrtypingrrr r r rrrrrr s