o a@sdZddlZddlZddlZddlZddlmZddlZddl m Z m Z m Z ddl m Z eeZedZdZGdd d ejZGd d d ed ZGd ddZGdddeZddZe jddZdS)z Keyring implementation support N)Optional) credentialserrorsutil) propertiesprioritycs eZdZdZfddZZS)KeyringBackendMetazn A metaclass that's both an ABCMeta and a type that keeps a registry of all (non-abstract) types. cs@t|||t|dst|_|j}|js||dSdS)N_classes)super__init__hasattrsetr __abstractmethods__add)clsnamebasesdictclasses __class__1/usr/lib/python3/dist-packages/keyring/backend.pyr s zKeyringBackendMeta.__init__)__name__ __module__ __qualname____doc__r __classcell__rrrrr sr c @seZdZdZddZddZejeddZ edd Z ejed d Z d d Z e jdededeefddZe jdedededdfddZdededdfddZdedeedeejfddZddZdS)KeyringBackendz]The abstract base class of the keyring, every backend must implement this interface. cCs |dSN)set_properties_from_env)selfrrrr ,s zKeyringBackend.__init__cCdS)a Each backend class must supply a priority, a number (float or integer) indicating the priority of the backend relative to all other backends. The priority need not be static -- it may (and should) vary based attributes of the environment in which is runs (platform, available packages, etc.). A higher number indicates a higher priority. The priority should raise a RuntimeError with a message indicating the underlying cause if the backend is not suitable for the current environment. As a rule of thumb, a priority between zero but less than one is suitable, but a priority of one or greater is recommended. Nrrrrrr0szKeyringBackend.prioritycCs8t }|jWd| S1swY| Sr )rExceptionRaisedContextr)rexcrrrviable@s  zKeyringBackend.viablecCsttd|jS)z6 Return all subclasses deemed viable. r')filteroperator attrgetterr r$rrrget_viable_backendsGsz"KeyringBackend.get_viable_backendscCs.|jd\}}}|dd}d||jgS)zr The keyring name, suitable for display. The name is derived from module and class name. ._ )r rpartitionreplacejoinr)rparentsepmod_namerrrrNs zKeyringBackend.namecCst|}d|j|j|jS)Nz{}.{} (priority: {:g}))typeformatrrr)r" keyring_classrrr__str__Zs zKeyringBackend.__str__serviceusernamereturncCr#)z,Get password of the username for the serviceNrr"r9r:rrr get_password`zKeyringBackend.get_passwordpasswordNcC td)zSet password for the username of the service. If the backend cannot store passwords, raise PasswordSetError. reason)rPasswordSetErrorr"r9r:r?rrr set_passwordes zKeyringBackend.set_passwordcCr@)zDelete the password for the username of the service. If the backend cannot delete passwords, raise PasswordDeleteError. rA)rPasswordDeleteErrorr<rrrdelete_passwordqs zKeyringBackend.delete_passwordcCs,|dur|||}|durt||SdS)aGets the username and password for the service. Returns a Credential instance. The *username* argument is optional and may be omitted by the caller or ignored by the backend. Callers must use the returned username. N)r=rSimpleCredentialrCrrrget_credential|s   zKeyringBackend.get_credentialcCs<dd}tdt|tj}|D] \}}t|||qdS)z6For all KEYRING_PROPERTY_* env var, set that property.cSs(|\}}|d\}}}|o||fS)NKEYRING_PROPERTY_) partitionlower)itemkeyvalueprer3rrrrparsesz5KeyringBackend.set_properties_from_env..parseN)r(maposenvironitemssetattr)r"rPpropsrrNrrrr!s  z&KeyringBackend.set_properties_from_env)rrrrr rr ClassProperty classmethodr'r+rr8abcabstractmethodstrrr=rDrFr CredentialrHr!rrrrr's4       r) metaclassc@s,eZdZdZejddZejddZdS)Crypterz.Base class providing encryption and decryptioncCr#)zEncrypt the value.Nrr"rNrrrencryptr>zCrypter.encryptcCr#)zDecrypt the value.Nrr_rrrdecryptr>zCrypter.decryptN)rrrrrYrZr`rarrrrr^s  r^c@s eZdZdZddZddZdS) NullCrypterzA crypter that does nothingcC|Sr rr_rrrr`zNullCrypter.encryptcCrcr rr_rrrrardzNullCrypter.decryptN)rrrrr`rarrrrrbs rbc CsbtjddD](}ztd|j|}t|r|Wqty.td|dYqwdS)a Locate all setuptools entry points by the name 'keyring backends' and initialize them. Any third-party library may register an entry point by adding the following to their setup.cfg:: [options.entry_points] keyring.backends = plugin_name = mylib.mymodule:initialize_func `plugin_name` can be anything, and is only used to display the name of the plugin at initialization time. `initialize_func` is optional, but will be invoked if callable. zkeyring.backends)groupz Loading %szError initializing plugin r,N) metadata entry_pointslogdebugrloadcallable Exception exception)ep init_funcrrr _load_pluginss rpcCs$tt}tj|td}t|S)zc Return a list of all implemented keyrings that can be constructed without parameters. ) exceptions)rprr+rsuppress_exceptions TypeErrorlist)viable_classesringsrrrget_all_keyringsrw)rrRrYloggingr)typingrimportlib_metadatarfrrrr getLoggerrrhr* by_priority_limitABCMetar rr^rbrponcerwrrrrs&    u