o  i@svddlmZddlmZddlmZddlmZddlm Z m Z ddl m Z m Z mZedZdd ZGd d d Zd S) ) annotations) namedtuple)Iterable) iskeyword)dedentindent)AnyCallableTypeVarTcCs|ot| S)zNReturns True if `name` is a valid Python variable name and also not a keyword.) isidentifierr)namer]/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/utils/component_store.py is_variablesrc@seZdZdZeddZd'd d Zd(ddZd)ddZe d*ddZ d+ddZ d,ddZ d-ddZ dd Zd.d"d#Zd.d$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) descriptionvaluer strrreturnNonecCs8i|_||_||_d|d|d|jpd|_dS)NComponent Store '':  ) componentsr r__doc__strip)selfr rrrr__init__8s&zComponentStore.__init__descrr cCs&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 csfdd}|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 rrrdecoJsz$ComponentStore.add_def..decor)rr r!r&rr%radd_defGszComponentStore.add_deftuple[str, ...]cC t|jS)z- Produces all factory names. )tuplerrrrrnamesPs zComponentStore.namesboolcCs ||jvS)z)Returns True if the given name is stored.)rrr rrr __contains__X zComponentStore.__contains__intcCr))z(Returns the number of stored components.)lenrr+rrr__len__\r0zComponentStore.__len__rccs&|jD] \}}||jfVqdS)zYields name/component pairs.N)ritemsr)rkvrrr__iter__`szComponentStore.__iter__cCsd|jd|jd}|jD]5\}}|d|d7}t|jdr=|jjr=tt|jj d d}|d|d7}q|d |j7}q|S) Nrrz Available components:z * :rrz  ) r rrr4hasattrrrrrlstriprstrip)rresultr5r6docrrr__str__eszComponentStore.__str__rcCs ||jvr |j|jS||S)/Returns the stored object under the given name.)rr__getattribute__r.rrr __getattr__rs   zComponentStore.__getattr__cCs&||jvr |j|jStd|d)r@z Component 'z ' not found)rrr"r.rrr __getitem__ys  zComponentStore.__getitem__N)r rrrrr)r rr!rrr rr )r rr!rrr )rr()r rrr-)rr1)rr)r rrr)__name__ __module__ __qualname__rrrr r#r'propertyr,r/r3r7r?rBrCrrrrrs         rN) __future__r collectionsrcollections.abcrkeywordrtextwraprrtypingrr r r rrrrrrs