
9Nc           @   s@  d  Z  d d l Z d d l Z d d l Z d d l m Z y d d l m Z m	 Z	 Wn0 e
 k
 r d e f d     YZ d   Z	 n Xy d d l Z Wn e
 k
 r n Xd Z d	 Z d
 Z d Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d a d d d  Z y$ d d l m Z d d l m Z Wn e
 k
 re Z  n Xe! Z  d e f d     YZ" d e f d     YZ# d e# f d     YZ$ d e# f d      YZ% d! e# f d"     YZ& d# e f d$     YZ' d% e f d&     YZ( d'   Z) d a* d(   Z+ d S()   s1   
backend.py

Created by Kang Zhang on 2009-07-09
iN(   t   escape(   t   ABCMetat   abstractmethodR   c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s   c         C   s   |  S(   N(    (   t   funcobj(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    s   keyring-settings   crypted-passwordi    t   0t   PasswordSetErrorc           B   s   e  Z d  Z RS(   s+   Raised when the password can't be set.
    (   R   R   t   __doc__(    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   !   s   t   KeyringBackendc           B   sA   e  Z d  Z e Z e d    Z e d    Z e d    Z RS(   s]   The abstract base class of the keyring, every backend must implement
    this interface.
    c         C   s   d S(   s   Return if this keyring supports current enviroment.
        -1: not applicable
         0: suitable
         1: recommended
        i(    (   t   self(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt	   supported+   s    c         C   s   d S(   s5   Get password of the username for the service
        N(   t   None(   R
   t   servicet   username(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   get_password4   s    c         C   s   t     d S(   s5   Set password for the username of the service
        N(   R   (   R
   R   R   t   password(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   set_password:   s    (	   R   R   R   R   t   __metaclass__R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR	   %   s
   	t   _ExtensionKeyringc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sX   _ExtensionKeyring is a adaptor class for the platform related keyring
    backends.
    c         C   s4   y |  j    |  _ Wn t k
 r/ d  |  _ n Xd  S(   N(   t   _init_backendt   keyring_implt   ImportErrorR   (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   __init__D   s    c         C   s   d S(   s2   Return the keyring implementation handler
        N(   R   (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   K   s    c         C   s   t  S(   s>   If this keyring is recommanded on current enviroment.
        (   t   False(   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt
   _recommendP   s    c         C   s'   |  j  d k r d S|  j   r# d Sd S(   s4   Override the supported() in KeyringBackend.
        ii   i    N(   R   R   R   (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   U   s
    c         C   s7   y |  j  j | |  } Wn t k
 r2 d } n X| S(   s7   Override the get_password() in KeyringBackend.
        N(   R   t   password_gett   OSErrorR   (   R
   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   ^   s
    
c         C   s;   y |  j  j | | |  Wn t k
 r6 t    n Xd S(   s6   Overide the set_password() in KeyringBackend.
        N(   R   t   password_setR   R   (   R
   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   g   s    (	   R   R   R   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   @   s   							t   OSXKeychainc           B   s    e  Z d  Z d   Z d   Z RS(   s   Mac OSX Keychainc         C   s   d d l  } | S(   s)   Return the handler: osx_keychain
        iN(   t   osx_keychain(   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   q   s    c         C   s   t  j d k S(   s*   Recommend for all OSX enviroment.
        t   darwin(   t   syst   platform(   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   w   s    (   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   o   s   	t   GnomeKeyringc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Gnome Keyringc         C   s^   y d d  l  } Wn t k
 r$ d SXd t j k rV d t j k rV d t j k rV d Sd Sd  S(   Nit   GNOME_KEYRING_CONTROLt   DISPLAYt   DBUS_SESSION_BUS_ADDRESSi   i    (   t   gnomekeyringR   t   ost   environ(   R
   R&   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    c         C   si   y t  j | |  } Wn) t  j k
 r- d St  j k
 rA d SXt |  d k s] t d  | d d S(   s5   Get password of the username for the service
        i   s(   no more than one entry should ever matchi    R   N(   R&   t   find_network_password_synct   NoMatchErrorR   t   CancelledErrort   lent   AssertionError(   R
   R   R   t   items(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    c      
   C   sM   y) t  j d | | d d d d d | 	 Wn t  j k
 rH t    n Xd S(   s5   Set password for the username of the service
        i    N(   R&   t   set_network_password_syncR   R+   R   (   R
   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s
    (   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR"   |   s   		c         C   s   t  d  k	 r t  S|  d  k r( t j }  n  | d  k r= t } n  d  } | j j   d  k rj | j g   } n  zp | j   } |  j	 |  j
   | j   |  j  a  t  d  k	 r t  j d  s t  j d  n  t  j d  t  SWd  | r | j   n  Xd  S(   Nt   Python(   t   kwalletR   t   KWallett   Wallett   QtGuit   qAppt   instancet   QApplicationt   QWidgett
   openWallett   NetworkWallett   winIdt   Synchronoust	   hasFoldert   createFoldert	   setFoldert   exit(   t   kwallet_modulet	   qt_modulet   appt   window(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   open_kwallet   s,    			(   R2   (   R4   t
   KDEKWalletc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   KDE KWalletc         C   s.   t  r t j j d  r d St  r& d Sd Sd  S(   Nt   KDE_SESSION_UIDi   i    i(   t   kwallet_supportR'   R(   t   has_key(   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s
    c         C   s\   | d | } t  j j   } t   } | j | d |  r? d S| j |  d } t |  S(   s5   Get password of the username for the service
        t   @R0   i   N(   R2   R3   R:   RE   t   keyDoesNotExistR   t   readPasswordt   unicode(   R
   R   R   t   keyt   networkt   wallett   result(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    	c         C   s%   t    } | j | d | |  d S(   s5   Set password for the username of the service
        RJ   N(   RE   t   writePassword(   R
   R   R   R   RP   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    	(   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRF      s   		t   BasicFileKeyringc           B   sV   e  Z d  Z d   Z e d    Z e d    Z e d    Z d   Z d   Z	 RS(   s   BasicFileKeyring is a filebased implementation of keyring.

    It stores the password directly in the file, and supports the
    encryption and decryption. The encrypted password is stroed in base64
    format.
    c         C   s.   t  j j t  j j d  |  j    |  _ d  S(   Nt   ~(   R'   t   patht   joint
   expandusert   filenamet	   file_path(   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    c         C   s   d S(   s9   Return the filename used to store the passwords.
        N(    (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRX      s    c         C   s   d S(   s   Encrypt the password.
        N(    (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   encrypt   s    c         C   s   d S(   s   Decrypt the password.
        N(    (   R
   t   password_encrypted(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   decrypt  s    c         C   s   t  |  } t  |  } t j   } t j j |  j  rL | j |  j  n  y4 | j | |  } | j	 d  } |  j
 |  } Wn# t j t j f k
 r d } n X| S(   s)   Read the password from the file.
        t   base64N(   t   escape_for_init   ConfigParsert   RawConfigParserR'   RU   t   existsRY   t   readt   gett   decodeR\   t   NoOptionErrort   NoSectionErrorR   (   R
   R   R   t   configt   password_base64R[   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    
c         C   s   t  |  } t  |  } |  j |  } t j   } t j j |  j  r[ | j |  j  n  | j	 d  } | j
 |  s | j |  n  | j | | |  t |  j d  } | j |  d S(   s(   Write the password in the file.
        R]   t   wN(   R^   RZ   R_   R`   R'   RU   Ra   RY   Rb   t   encodet   has_sectiont   add_sectiont   sett   opent   write(   R
   R   R   R   R[   Rg   Rh   t   config_file(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   !  s    (
   R   R   R   R   R   RX   RZ   R\   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRS      s   		t   UncryptedFileKeyringc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   Uncrypted File Keyringc         C   s   d S(   s\   Return the filename of the password file. It should be
        "keyring_pass.cfg" .
        s   keyring_pass.cfg(    (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRX   9  s    c         C   s   | S(   s-   Directly return the password itself.
        (    (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRZ   ?  s    c         C   s   | S(   s,   Directly return encrypted password.
        (    (   R
   R[   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR\   D  s    c         C   s   d S(   s<   Applicable for all platforms, but do not recommend.
        i    (    (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   I  s    (   R   R   R   RX   RZ   R\   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRq   7  s
   			t   CryptedFileKeyringc           B   s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s   PyCrypto File Keyringc         C   s    t  t |   j   d  |  _ d  S(   N(   t   superRr   R   R   t   crypted_password(   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   P  s    c         C   s   d S(   s3   Return the filename for the password file.
        s   crypted_pass.cfg(    (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRX   T  s    c         C   s8   y d d l  m } d } Wn t k
 r3 d } n X| S(   s9   Applicable for all platforms, but not recommend"
        i(   t   AESi    (   t   Crypto.CipherRu   R   (   R
   Ru   t   status(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   Y  s    

c         C   sL  d GHd } x | sf d d l } | j   } | j d  } | | k rf t j j d  d } q qf n  d | j   k r t j j d  d } q n  t |  t k r t j j d  d } q n  Pq d d l } | j | |  |  _	 t
 j   } | j t  | j t t |  j	  t |  j d	  } | j |  | rH| j   n  d S(
   s9   Init the password file, set the password for it.
        s*   Please set a password for your new keyringiNs   Password (again): s"   Error: Your passwords didn't math
t    s'   Error: blank passwords aren't allowed.
s)   Error: password can't be longer than 32.
Ri   (   R   t   getpassR    t   stderrRo   t   stripR,   t   _BLOCK_SIZEt   cryptRt   R_   R`   Rl   t   _KEYRING_SETTINGRm   t   _CRYPTED_PASSWORDRn   RY   t   close(   R
   R   Ry   t	   password2R}   Rg   Rp   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt
   _init_filec  s:    	c         C   s   t  j j |  j  r t j   } | j |  j  y, | j t t	  |  _
 |  j
 j   d k SWq t j t j f k
 r| q Xn  t S(   s;   Check if the password file has been init properly.
        Rx   (   R'   RU   Ra   RY   R_   R`   Rb   Rc   R~   R   Rt   R{   Rf   Re   R   (   R
   Rg   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _check_file  s    	c         C   s%   d d l  } | j  | |  |  j k S(   s5   Return if the password can open the keyring.
        iN(   R}   Rt   (   R
   R   R}   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _auth  s    c         C   s   |  j    s |  j   n  d GHd d l } | j   } |  j |  sd t j j d  t d   n  d d l m	 } | t
 t |  t
 t } | j | | j  S(   s=   Init the crypter(using the password of the keyring).
        s*   Please input your password for the keyringiNs    Wrong password for the keyring.
s   Wrong password(   Ru   (   R   R   Ry   R   R    Rz   Ro   t
   ValueErrorRv   Ru   R|   R,   t   _PADDINGt   newt   MODE_CFB(   R
   Ry   R   Ru   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _init_crypter  s    c         C   s   |  j    } | j |  S(   s6   Encrypt the given password using the pycryto.
        (   R   RZ   (   R
   R   t   crypter(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRZ     s    c         C   s   |  j    } | j |  S(   s6   Decrypt the given password using the pycryto.
        (   R   R\   (   R
   R[   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR\     s    (   R   R   R   R   RX   R   R   R   R   R   RZ   R\   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRr   N  s   			
	*				t   Win32CryptoKeyringc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   Win32 Cryptography Keyringc         C   sM   t  t |   j   y d d  l } | |  _ Wn t k
 rH d  |  _ n Xd  S(   Ni(   Rs   R   R   t   win32_cryptot   crypt_handlerR   R   (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   s   d S(   s<   Return the filename for the password storages file.
        s   wincrypto_pass.cfg(    (   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRX     s    c         C   s1   t    } | d k r d S| d k r) d Sd Sd S(   s>   Recommend when other Windows backends are unavailable
        it   filei   i    N(   t   select_windows_backendR   (   R
   t   recommended(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    	c         C   s   |  j  j |  S(   s1   Encrypt the password using the CryptAPI.
        (   R   RZ   (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRZ     s    c         C   s   |  j  j |  S(   s1   Decrypt the password using the CryptAPI.
        (   R   R\   (   R
   R[   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR\     s    (   R   R   R   R   RX   R   RZ   R\   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s   					t   WinVaultKeyringc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   sb   t  t |   j   y. d d  l } d d  l } | |  _ | |  _ Wn t k
 r] d  |  _ n Xd  S(   Ni(   Rs   R   R   t
   pywintypest	   win32credR   R   (   R
   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    	c         C   s1   t    } | d k r d S| d k r) d Sd Sd S(   s6   Default Windows backend, when it is available
        it   credi   i    N(   R   R   (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    	c         C   si   y) |  j  j d |  j  j d |  d } Wn0 |  j j k
 r[ } | d  d k rU d  S  n X| j d  S(	   Nt   Typet
   TargetNamet   CredentialBlobi   i  t   CredReadt   utf16(   i  s   CredRead(   R   R   t   CRED_TYPE_GENERICR   t   errorR   Rd   (   R
   R   R   t   blobt   e(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   sV   t  d |  j j d | d | d t |  d d d |  j j  } |  j j | d  d  S(	   NR   R   t   UserNameR   t   Comments   Stored using python-keyringt   Persisti    (   t   dictR   R   RM   t   CRED_PERSIST_ENTERPRISEt	   CredWrite(   R
   R   R   R   t
   credential(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   	  s    (   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s   				
t   Win32CryptoRegistryc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   Win32CryptoRegistry is a keyring which use Windows CryptAPI to encrypt
    the user's passwords and store them under registry keys
    c         C   sY   t  t |   j   y% d d  l } d d  l } | |  _ Wn t k
 rT d  |  _ n Xd  S(   Ni(   Rs   R   R   R   t   _winregR   R   R   (   R
   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   s1   t    } | d k r d S| d k r) d Sd Sd S(   s   Return if this keyring supports current enviroment.
        -1: not applicable
         0: suitable
         1: recommended
        it   regi   i    N(   R   R   (   R
   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   !  s    	c         C   s   d d l  m } m } m } yQ d | } | | |  } | | |  d } | j d  }	 |  j j |	  }
 Wn t k
 r d }
 n X|
 S(   s5   Get password of the username for the service
        i(   t   HKEY_CURRENT_USERt   OpenKeyt   QueryValueExs   Software\%s\Keyringi    R]   N(	   R   R   R   R   Rd   R   R\   t   EnvironmentErrorR   (   R
   R   R   R   R   R   RN   t   hkeyRh   R[   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   /  s    

c         C   sp   |  j  j |  } | j d  } d d l m } m } m } m }	 | | d |  }
 | |
 | d |	 |  d S(   s+   Write the password to the registry
        R]   i(   R   t	   CreateKeyt
   SetValueExt   REG_SZs   Software\%s\Keyringi    N(   R   RZ   Rj   R   R   R   R   R   (   R
   R   R   R   R[   Rh   R   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   A  s
    "(   R   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s
   	
		c    	      C   s   t  j d k r d  St j   \ }  } } } } y2 d d  l } d d  l } |  | f d	 k r_ d SWn t k
 rs n Xy2 d d  l } d d  l	 } |  | f d
 k r d SWn t k
 r n Xy d d  l } d SWn t k
 r n Xd  S(   Nt   ntii   i   R   i    R   R   (   i   i   (   i   i    (
   R'   t   nameR   R    t   getwindowsversionR   R   R   R   R   (	   t   majort   minort   buildR!   t   textR   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   N  s*    c           C   sI   t  d k rE t   t   t   t   t   t   t   t	   g a  n  t  S(   s/   Return the list of all keyrings in the lib
    N(
   t   _all_keyringR   R   R"   RF   Rr   Rq   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   get_all_keyringj  s    (,   R   R'   R    R_   t   keyring.util.escapeR    R^   t   abcR   R   R   t   typeR&   R~   R   R|   R   t	   ExceptionR   t   objectR	   R   R   R"   R   R1   RE   t   PyKDE4.kdeuiR2   t   PyQt4R4   R   RH   t   TrueRF   RS   Rq   Rr   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   <module>   sP   /( 
Iv&);	