B Ÿ@` ã@s"Gdd„deƒZGdd„dƒZdS)c@sXeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dS)ÚFactoryzÄ Class that provides a generic constructor mechanism. Adapted from code developed by Andres Tuells and submitted to the ActiveState Programmer Network http://aspn.activestate.com cCsg|_i|_dS)z Constructor N)ÚKeysÚ constructors)Úself©rú9/tmp/pip-unpacked-wheel-bvjqrktv/pyutilib/misc/factory.pyÚ__init__szFactory.__init__cOsL|j|g|_|g}| |¡d|}t||Ž|j|<t||t||ŽƒdS)z Register a constructor Z construct_N)rÚextendÚ_FunctorrÚsetattr)rÚ methodNameÚ constructorÚargsÚkargsÚ_argsZmnamerrrÚregisters  zFactory.registercCs.yt|t|ƒƒ}Wntk r&dSX|ƒS)z: Use the string name to create an object. N)ÚgetattrÚstrÚAttributeError)rÚnameÚmethodrrrÚ construct#s zFactory.constructcCs | |¡S)z: Use the string name to create an object. )r)rrrrrÚ__call__-szFactory.__call__cCst||ƒ|j |¡dS)z Unregister a constructor N)ÚdelattrrÚremove)rr rrrÚ unregister3s zFactory.unregistercCs|jS)zS Returns the list of names that can are registered in this factory )r)rrrrÚkeys8sz Factory.keyscCs t|jƒS)z< Returns the number of names in the factory )Úlenr)rrrrÚ__len__>szFactory.__len__cCs |j ¡S)z* Returns an iterator for the factory keys )rÚ__iter__)rrrrrDszFactory.__iter__cCs |j|S)z/ Allows an index into the list of factory keys )r)rÚindexrrrÚ __getitem__HszFactory.__getitem__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrrrrrrr rrrrr s  rc@s eZdZdZdd„Zdd„ZdS)r zA A class that wraps a function to act like the function. cOs(t|dƒstdƒ‚||_||_||_dS)z Constructor rz!function should be a callable objN)ÚhasattrÚAssertionErrorÚ _functionrÚ_kargs)rÚfunctionr rrrrrRs z_Functor.__init__cOs4t|jƒ}| |¡|j ¡}| |¡|j||ŽS)z Call function )Úlistrrr(ÚcopyÚupdater')rr rrr(rrrrZs     z_Functor.__call__N)r!r"r#r$rrrrrrr Msr N)Úobjectrr rrrrÚ sB