o a@sddlZddlZddlZddlmZddlmZddlmZddlm Z m Z m Z ddl m Z z ddlZddlmZWneyCYn eyKYnwd d ZGd d d eZGd ddeZdS)N)KeyringBackend)SimpleCredential)PasswordDeleteError)PasswordSetError InitError KeyringLocked) properties) DBusGMainLoopcCsBtttf}t| tjdWdS1swYdS)z/ Safely infer an app id from sys.argv. rN)AttributeError IndexError TypeError contextlibsuppresssysargv)allowedr:/usr/lib/python3/dist-packages/keyring/backends/kwallet.py _id_from_argvs  $rcs|eZdZdZep dZdZdZdZe j e ddZ fdd Z d d Zd d ZddZfddZddZddZZS) DBusKeyringz! KDE KWallet 5 via D-Bus zPython keyring libraryNzorg.kde.kwalletd5z/modules/kwalletd5c Csdtvr tdz tjtd}Wntjy%}zt|d}~ww||js7|j| vs7tddt dd dvrDd Sd S) Ndbuszpython-dbus not installedmainloopzCThe KWallet daemon is neither running nor activatable through D-BusKDEXDG_CURRENT_DESKTOP:gffffff@g@) globals RuntimeErrorr SessionBusr DBusExceptionget_dbus_messagename_has_ownerbus_namelist_activatable_namesosgetenvsplit)clsbusexcrrrpriority(s"   zDBusKeyring.prioritycstj|i|d|_dS)N)super__init__handle)selfargkw __class__rrr/<s zDBusKeyring.__init__c Csd}g}|j|j||jrd|j|j|d|j}|D]-}|d}|d}|dd\}}|j|j||||j}|dkrJ|j|j|||jq|j|j|d|j}|sf|j |j||jdSdSdS)NPythonz*@*r@*) iface hasFolderr0appidreadPasswordListitemsrsplit writePassword removeEntry removeFolder) r1service old_folder entry_listentrykeypasswordusernameretrrr_migrate@s.   zDBusKeyring._migratec Cs|jdkr|j|jrdStjtd}d}z||j|j}t |d|_|j |j ||j |_Wntj yH}ztd|d}~ww|jdkrPdS||dS)NrTrzorg.kde.KWalletzFailed to open keyring: %s.F)r0r:isOpenrr r get_objectr$ object_path Interfaceopen networkWalletr<r!rrK)r1rCr*wId remote_objerrr connectedYs"    zDBusKeyring.connectedcCsJ||s td|j|j|||jsdS|j|j|||j}t|S)z,Get password of the username for the serviceFailed to unlock the keyring!N)rUrr:hasEntryr0r< readPasswordstrr1rCrIrHrrr get_passwordls zDBusKeyring.get_passwordcsp|dur t||S||std|j|j||jD]}|j|j|||j}t t |t |SdS)aGets the first username and password for a service. Returns a Credential instance The username can be omitted, but if there is one, it will forward to get_password. Otherwise, it will return the first username and password combo that it finds. NrV) r.get_credentialrUrr: entryListr0r<rXrrYrZr4rrr\vs  zDBusKeyring.get_credentialcCs.||s td|j|j||||jdS)z,Set password for the username of the serviceCancelled by userN)rUrr:r@r0r<rZrrr set_passwords zDBusKeyring.set_passwordcCsJ||s td|j|j|||jstd|j|j|||jdS)z4Delete the password for the username of the service.r^zPassword not foundN)rUrr:rWr0r<rA)r1rCrIrrrdelete_passwords zDBusKeyring.delete_password)__name__ __module__ __qualname____doc__rr<walletr$rNr ClassProperty classmethodr,r/rKrUr[r\r_r` __classcell__rrr4rrs     rcs2eZdZdZdZdZejefddZ Z S)DBusKeyringKWallet4z! KDE KWallet 4 via D-Bus zorg.kde.kwalletdz/modules/kwalletdcs tjdS)Nr7)r.r,)r)r4rrr,s zDBusKeyringKWallet4.priority) rarbrcrdr$rNr rfrgr,rhrrr4rrisri)rr&rbackendr credentialsrerrorsrrrrutilr rdbus.mainloop.glibr ImportErrorr rrrirrrrs&       ~