U á€C^žã@sÈddlmZddlmZddlZzddlmZWnek rLddlZYnXej ddkrbe Z ne Z e  ¡Zeƒadd„ZGdd„deƒZd d „Zd d „Zd d„Zdd„Zdd„ZGdd„deƒZdS)é)Úunicode_literals)Ú OrderedDictNécOs.| dd¡}t|Žr"td |¡ƒ‚t||d�S)zãCreate a new registry. *namespace (str): The namespace, e.g. "spacy" or "spacy", "architectures". RETURNS (Tuple[Callable]): The setter (decorator to register functions) and getter (to retrieve functions). Ú entry_pointsFzNamespace already exists: {})r)ÚgetÚ check_existsÚ RegistryErrorÚformatÚRegistry)Ú namespaceÚkwargsr©r ú0/tmp/pip-install-6_kvzl1k/catalogue/catalogue.pyÚcreates rc@sPeZdZddd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z ddd„Z dS)r FcCs||_d |¡|_||_dS)zÎInitialize a new registry. namespace (Tuple[str]): The namespace. entry_points (bool): Whether to also check for entry points. RETURNS (Registry): The newly created object. Ú_N)r ÚjoinÚentry_point_namespacer)Úselfr rr r rÚ__init__&s zRegistry.__init__cCs0tt|jƒ|gƒ}|jo"| |¡}|p.|tkS)z–Check whether a name is in the registry. name (str): The name to check. RETURNS (bool): Whether the name is in the registry. )ÚtupleÚlistr rÚget_entry_pointÚREGISTRY)rÚnamer Zhas_entry_pointr r rÚ __contains__1szRegistry.__contains__cKs|j|f|ŽS)aRegister a function for a given namespace. Same as Registry.register. name (str): The name to register under the namespace. func (Any): Optional function to register (if not used as decorator). RETURNS (Callable): The decorator. )Úregister)rrr r r rÚ__call__;szRegistry.__call__c s,‡‡fdd„}| d¡}|dk r(||ƒS|S)zëRegister a function for a given namespace. name (str): The name to register under the namespace. func (Any): Optional function to register (if not used as decorator). RETURNS (Callable): The decorator. csttˆjƒˆg|ƒ|S©N)Ú_setrr )Úfunc©rrr rÚdo_registrationLsz*Registry.register..do_registrationrN)r)rrr r!rr r rrDs  zRegistry.registercCst|jr| |¡}|r|St|jƒ|g}t|Žsld}d |j¡}d t| ¡ ¡ƒ¡pXd}t |  |||¡ƒ‚t |ƒS)z…Get the registered function for a given name. name (str): The name. RETURNS (Any): The registered function. z4Cant't find '{}' in registry {}. Available names: {}z -> z, Únone) rrrr rrÚsortedÚget_allÚkeysrr Ú_get)rrZfrom_entry_pointr ÚerrZcurrent_namespaceÚ availabler r rrUs  z Registry.getcsttƒ}ˆjr| ˆ ¡¡t ¡D]L\‰}tˆjƒtˆƒdkr"t‡‡fdd„t tˆjƒƒDƒƒr"||ˆd<q"|S)zªGet a all functions for a given namespace. namespace (Tuple[str]): The namespace to get. RETURNS (Dict[str, Any]): The functions, keyed by name. éc3s |]}ˆj|ˆ|kVqdSr©r ©Ú.0Úi©r%rr rÚ rsz#Registry.get_all..éÿÿÿÿ) rrÚupdateÚget_entry_pointsrÚitemsÚlenr ÚallÚrange)rÚresultÚvaluer r.rr$gs$ ÿzRegistry.get_allcCs*i}t |jg¡D]}| ¡||j<q|S)zŒGet registered entry points from other packages for this namespace. RETURNS (Dict[str, Any]): Entry points, keyed by name. )ÚAVAILABLE_ENTRY_POINTSrrÚloadr)rr7Ú entry_pointr r rr2xszRegistry.get_entry_pointsNcCs.t |jg¡D]}|j|kr| ¡Sq|S)a;Check if registered entry point is available for a given name in the namespace and load it. Otherwise, return the default value. name (str): Name of entry point to load. default (Any): The default value to return. RETURNS (Any): The loaded entry point or the default value. )r9rrrr:)rrÚdefaultr;r r rr‚s zRegistry.get_entry_point)F)N) Ú__name__Ú __module__Ú __qualname__rrrrrr$r2rr r r rr %s    r cGs|tkS)zyCheck if a namespace exists. *namespace (str): The namespace. RETURNS (bool): Whether the namespace exists. )rr*r r rr�srcCsNtdd„|Dƒƒs$d}t| |¡ƒ‚t|ƒ}|tkrFd |¡}t|ƒ‚t|S)zGet the value for a given namespace. namespace (Tuple[str]): The namespace. RETURNS: The value for the namespace. css|]}t|tƒVqdSr)Ú isinstanceÚ basestring_)r,rr r rr/ sz_get..z9Invalid namespace. Expected tuple of strings, but got: {}ú(Can't get namespace {} (not in registry))r5Ú ValueErrorr rrr)r r'r r rr&™s r&csTtƒ}t ¡D]@\‰}tˆƒtˆƒkrt‡‡fdd„ttˆƒƒDƒƒr||ˆ<q|S)aGet all matches for a given namespace, e.g. ("a", "b", "c") and ("a", "b") for namespace ("a", "b"). namespace (Tuple[str]): The namespace. RETURNS (Dict[Tuple[str], Any]): All entries for the namespace, keyed by their full namespaces. c3s|]}ˆ|ˆ|kVqdSrr r+©r%r r rr/µsz_get_all..)rrr3r4r5r6)r r7r8r rDrÚ_get_allªs  ÿ rEcCs|tt|ƒ<dS)zzSet a value for a given namespace. namespace (Tuple[str]): The namespace. func (Callable): The value to set. N)rr)r rr r rr¼srcCs4t|ƒ}|tkr"d |¡}t|ƒ‚t|}t|=|S)zvRemove a value for a given namespace. namespace (Tuple[str]): The namespace. RETURNS: The removed value. rB)rrr r)r r'Úremovedr r rÚ_removeÆs rGc@s eZdZdS)rN)r=r>r?r r r rrÖsr)Ú __future__rÚ collectionsrÚsysÚimportlib.metadataÚmetadataZimportlib_metadataÚ ImportErrorÚ version_infoÚ basestringrAÚstrrr9rrÚobjectr rr&rErrGrCrr r r rÚs&   k