o a_@s:dZddlZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z eeZdaddZd ejfd d Zd d Zdeded ejefddZdededed dfddZdeded dfddZdedejed ejejfddZddZd)ddZd)ddZdd Z d!d"Z!d#d$Z"d%d&Z#d'd(Z$dS)*z1 Core API functions and initialization routines. N)backend credentials) platform_)failcCst|tjs td|adS)zSet current keyring backend.z1The keyring must be an instance of KeyringBackendN) isinstancerKeyringBackend TypeError_keyring_backend)keyringr ./usr/lib/python3/dist-packages/keyring/core.py set_keyrings rreturncCstdurtttjtS)zGet current keyring backend.N)r init_backendtypingcastrrr r r r get_keyringsrcCst}zt|Wn tyYnwtj|d}tj|r+d|}t|t |d}| dWddS1sAwYdS)z4 Configure the null keyring as the default. keyringrc.cfgzRefusing to overwrite wz7[backend] default-keyring=keyring.backends.null.KeyringN) platform config_rootosmakedirsOSErrorpathjoinexists RuntimeErroropenwrite)rootfilenamemsgfiler r r disable$s     "r% service_nameusernamecCt||S)z(Get password from the specified service.)r get_passwordr&r'r r r r)5sr)passwordcCst|||dS)z3Set password for the user in the specified service.N)r set_password)r&r'r+r r r r,:sr,cCst||dS)z:Delete the password for the user in the specified service.N)rdelete_passwordr*r r r r-?sr-cCr()z+Get a Credential for the specified service.)rget_credentialr*r r r r.Dsr.cCs |jdkS)Nr)priority)rr r r recommendedKs r0cCstt|dS)z" Load a detected backend. N)r_detect_backendlimitr r r rOsrcCs0|t_tptptt|tttj dS)z Return a keyring specified in the config file or infer the best available. Limit, if supplied, should be a callable taking a backend and returning True if that backend should be included for consideration. )defaultkey) r_limitload_env load_configmaxfilterget_all_keyringrKeyring by_priorityr2r r r r1Vs  r1cCs,|d\}}}t|tj|}t||S)a Load the keyring class indicated by name. These popular names are tested to ensure their presence. >>> popular_names = [ ... 'keyring.backends.Windows.WinVaultKeyring', ... 'keyring.backends.macOS.Keyring', ... 'keyring.backends.kwallet.DBusKeyring', ... 'keyring.backends.SecretService.Keyring', ... ] >>> list(map(_load_keyring_class, popular_names)) [...] .) rpartition __import__sysmodulesgetattr) keyring_name module_namesep class_namemoduler r r _load_keyring_classls  rIcCst|}|j|S)z Load the specified keyring by name (a fully-qualified name to the keyring, such as 'keyring.backends.file.PlaintextKeyring') )rIr/)rDclass_r r r load_keyringsrKcCs&zttjdWStyYdSw)z6Load a keyring configured in the environment variable.PYTHON_KEYRING_BACKENDN)rKrenvironKeyErrorr r r r r7s  r7c Csd}tjt|}tj|sdSt}||t |z| dr/| dd }nt ddWt|Stj tfyTtd}|dd|YdSw)z8Load a keyring using the config file in the config root.rNrzdefault-keyringr z/Keyring config file contains incorrect values. zConfig file: %s)rrrrrr configparserRawConfigParserread_load_keyring_path has_sectiongetstrip NoOptionError ImportErrorlogging getLoggerwarningrK)r" keyring_cfgconfigrDloggerr r r r8s,      r8c CsBz|dd}tjd|WdStjtjfy YdSw)z)load the keyring-path option (if present)rz keyring-pathrN)rTrUrArinsertrOrVNoSectionError)r\rr r r rRs rR)N)%__doc__rOrrArXrrrutilrrbackendsrrY__name__logr rrrr%strOptionalr)r,r- Credentialr.r0rr1rIrKr7r8rRr r r r s@