
;Pc           @   sU  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z
 d d l Z d d l m Z d d l Z d d l Z d d l Z e j j Z e j j 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 e a e e 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. e a/ d#   Z0 d S($   s-   
backend.py

Keyring Backend implementations
iN(   t   escape(   t
   propertiest   PasswordSetErrorc           B   s   e  Z d  Z RS(   s+   Raised when the password can't be set.
    (   t   __name__t
   __module__t   __doc__(    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s   t   KeyringBackendc           B   sM   e  Z d  Z e j Z e j d    Z e j d    Z e j 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 environment:
        -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_password.   s    c         C   s   t  d   d S(   s5   Set password for the username of the service
        t   reasonN(   R   (   R   R
   R   t   password(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   set_password4   s    (
   R   R   R   t   abct   ABCMetat   __metaclass__t   abstractmethodR   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__>   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   E   s    c         C   s   t  S(   s?   If this keyring is recommended on current environment.
        (   t   False(   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt
   _recommendJ   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   O   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   X   s
    
c         C   sC   y |  j  j | | |  Wn" t k
 r> } t | j   n Xd S(   s7   Override the set_password() in KeyringBackend.
        N(   R   t   password_setR   R   t   message(   R   R
   R   R   t   e(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   a   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 OS X Keychainc         C   s   d d l  m } | S(   s)   Return the handler: osx_keychain
        i(   t   osx_keychain(   t   backendsR!   (   R   R!   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   k   s    c         C   s   t  j d k S(   s-   Recommended for all OSX environment.
        t   darwin(   t   syst   platform(   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   q   s    (   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR    i   s   	t   GnomeKeyringc           B   s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   s   Gnome Keyringc         C   s\   y t  d  Wn t k
 r" d SXd t j k rT d t j k rT d t j k rT d Sd Sd  S(   Nt   gnomekeyringit   GNOME_KEYRING_CONTROLt   DISPLAYt   DBUS_SESSION_BUS_ADDRESSi   i    (   t
   __import__R   t   ost   environ(   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   }   s    c         C   sx   d d l  } y | j | |  } Wn) | j k
 r9 d S| j k
 rM d SXt |  d k sl t d   | d d S(   s5   Get password of the username for the service
        iNi   s(   no more than one entry should ever matchi    R   (   R'   t   find_network_password_synct   NoMatchErrorR	   t   CancelledErrort   lent   AssertionError(   R   R
   R   R'   t   items(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    c         C   sq   d d l  } y> | j |  j | j d | | f i | d 6| d 6| t  Wn  | j k
 rl t d   n Xd S(   s5   Set password for the username of the service
        iNs   Password for '%s' on '%s't   usert   domains   cancelled by user(   R'   t   item_create_synct   KEYRING_NAMEt   ITEM_NETWORK_PASSWORDt   TrueR0   R   (   R   R
   R   R   R'   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    N(   R   R   R   R	   R7   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR&   v   s
   		t   SecretServiceKeyringc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   Secret Service Keyringc         C   sh   y d d  l  } Wn t k
 r$ d SXy  | j   } | j d d  Wn | j j k
 r_ d SXd Sd  S(   Nis   org.freedesktop.secretss   /org/freedesktop/secretsi   (   t   dbusR   t
   SessionBust
   get_objectt
   exceptionst   DBusException(   R   R;   t   bus(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    	c         C   s   d d l  } | j   } | j d d  } | j | d  } | j i | d 6| d 6 \ } } | j d d	  \ }	 }
 | j |  \ } } | d
 k s t  | j | | |
  } xA | j	   D]3 \ } } d	 j
 g  | d D] } t |  ^ q  SWd S(   s5   Get password of the username for the service
        iNs   org.freedesktop.secretss   /org/freedesktop/secretss   org.freedesktop.Secret.ServiceR   R
   t   plaint    t   /i   (   R;   R<   R=   t	   Interfacet   SearchItemst   OpenSessiont   UnlockR2   t
   GetSecretst	   iteritemst   joint   strR	   (   R   R
   R   R;   R@   t   service_objt   service_ifacet   unlockedt   lockedt   _t   sessiont   no_longer_lockedt   promptt   secretst	   item_patht   secrett   x(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s    				+c         C   s   d d l  } | j   } | j d d  } | j | d  } | j d d  } | j | d  }	 i | d 6| d	 6}
 | j d
 d  \ } } t | t  r | j d  } n  | j | d | j	 |  d f  } i d | | f d 6|
 d 6} |	 j
 | | t  \ } } | d k st  d S(   s5   Set password for the username of the service
        iNs   org.freedesktop.secretss   /org/freedesktop/secretss   org.freedesktop.Secret.Services(   /org/freedesktop/secrets/aliases/defaults!   org.freedesktop.Secret.CollectionR
   R   RA   RB   s   utf-8s
   text/plains   %s @ %ss!   org.freedesktop.Secret.Item.Labels&   org.freedesktop.Secret.Item.AttributesRC   (   R;   R<   R=   RD   RF   t
   isinstancet   unicodet   encodet   Structt	   ByteArrayt
   CreateItemR9   R2   (   R   R
   R   R   R;   R@   RL   RM   t   collection_objt
   collectiont
   attributesRP   RQ   RV   R   t   itemRS   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR      s4    							

(   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR:      s   		c         C   s  |  d  k r+ | d  k r+ t d  k	 r+ t Sn  |  d  k rC t j }  n  | d  k rX t } n  d  } | j j   d  k r | 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(   R	   t   kwallett   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.    			(   Rd   (   Rf   t
   KDEKWalletc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   KDE KWalletc         C   s+   t  r d t j k r d St  r# d Sd Sd  S(   Nt   KDE_SESSION_UIDi   i    i(   t   kwallet_supportR,   R-   (   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   @Rb   i   N(   Rd   Re   Rl   Rw   t   keyDoesNotExistR	   t   readPasswordRY   (   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
        R{   N(   Rw   t   writePassword(   R   R
   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   5  s    	(   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyRx     s   		t   BasicFileKeyringc           B   s   e  Z d  Z e j d    Z e j d    Z e j	 d    Z
 e j	 d    Z d
 d  Z d   Z d   Z d   Z d	   Z RS(   s  
    BasicFileKeyring is a file-based implementation of keyring.

    This keyring stores the password directly in the file and provides methods
    which may be overridden by subclasses to support
    encryption and decryption. The encrypted payload is stored in base64
    format.
    c         C   s"   t  j j t j j j   |  j  S(   s   
        The path to the file where passwords are stored. This property
        may be overridden by the subclass or at the instance level.
        (   R,   t   pathRJ   t   keyringt   utilR%   t	   data_roott   filename(   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt	   file_pathE  s    c         C   s   d S(   s2   The filename used to store the passwords.
        N(    (   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   M  s    c         C   s   d S(   s   Encrypt the password.
        N(    (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   encryptS  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   decryptY  s    c         C   s   d S(   s6   Convert older keyrings to the current format.
        N(    (   R   t   keyring_password(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _migrate_  s    c         C   sS   t  j j t  j j d  |  j  } |  j } t j j j	 | |  d   |  _
 d  S(   Nt   ~c           S   s   d  S(   N(   R	   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   <lambda>i  s    (   R,   R   RJ   t
   expanduserR   R   R   R   t
   loc_compatt   relocate_filet   _relocate_file(   R   t   old_locationt   new_location(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   d  s    $	c         C   s   |  j    t |  } t |  } t j   } t j j |  j  r` |  j   | j	 |  j  n  yC | j
 | |  j   } t j |  } |  j |  j d  } Wn# t j t j f k
 r d } n X| S(   s)   Read the password from the file.
        s   utf-8N(   R   t   escape_for_init   ConfigParsert   RawConfigParserR,   R   t   existsR   R   t   readt   getRZ   t   base64t   decodestringR   t   decodet   NoOptionErrort   NoSectionErrorR	   (   R   R
   R   t   configt   password_base64R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   k  s    


c         C   s   |  j    t |  } t |  } |  j | j d   } t j   } t j j |  j	  rn | j
 |  j	  n  t j |  j   } | j |  s | j |  n  | j | | |  |  j   t |  j	 d  } | j |  d S(   s(   Write the password in the file.
        s   utf-8t   wN(   R   R   R   RZ   R   R   R,   R   R   R   R   R   t   encodestringR   t   has_sectiont   add_sectiont   sett   _ensure_file_patht   opent   write(   R   R
   R   R   R   R   R   t   config_file(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    

c         C   sc   t  j j |  j  } | r> t  j j |  r> t  j |  n  t  j | t j t j	 Bt j
 B d S(   s   ensure the storage path existsN(   R,   R   t   dirnameR   t   isdirt   makedirst   chmodt   statt   S_IWRITEt   S_IREADt   S_IEXEC(   R   t   storage_root(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    N(   R   R   R   R   t   NonDataPropertyR   R   t   abstractpropertyR   R   R   R   R	   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   ;  s   			t   UncryptedFileKeyringc           B   s/   e  Z d  Z d Z d   Z d   Z d   Z RS(   s   Uncrypted File Keyrings   keyring_pass.cfgc         C   s   | S(   s-   Directly return the password itself.
        (    (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   s   | S(   s,   Directly return encrypted password.
        (    (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     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     s    (   R   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s
   		t   CryptedFileKeyringc           B   s   e  Z d  Z d Z d Z d Z d   Z e j d    Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d d  Z d   Z d   Z RS(   s   PyCrypto File Keyringi    t   0s   crypted_pass.cfgc         C   sa   y= t  d  t  d  t  d  t s6 t d   n  d } Wn t t f k
 r\ d } n X| S(   s9   Applicable for all platforms, but not recommend"
        s   Crypto.Cipher.AESs   Crypto.Protocol.KDFs   Crypto.Randoms/   JSON implementation needed (install simplejson)i    i(   R+   t   jsonR2   R   (   R   t   status(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    




c         C   s*   |  j    r |  j   n
 |  j   |  j S(   N(   t   _check_filet   _unlockt
   _init_filet   keyring_key(   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    
c         C   sz   xs t  ru t j d  } t j d  } | | k rI t j j d  q n  d | j   k rq t j j d  q n  | SWd  S(   Ns,   Please set a password for your new keyring: s   Please confirm the password: s#   Error: Your passwords didn't match
RB   s'   Error: blank passwords aren't allowed.
(   R9   t   getpassR$   t   stderrR   t   strip(   R   R   t   confirm(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _get_new_password  s    		c         C   s&   |  j    |  _ |  j d d d  d S(   sP   
        Initialize a new password file and set the reference password.
        s   keyring-settings   password references   password reference valueN(   R   R   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   s   t  j j |  j  s t S|  j   t j   } | j |  j  y  | j	 t
 d  t
 d   Wn t j t j f k
 r t SXt S(   sS   
        Check if the file exists and has the expected password reference.
        s   keyring-settings   password reference(   R,   R   R   R   R   R   R   R   R   R   R   R   R   R9   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    
	c         C   sh   t  j  d  |  _ y( |  j d d  } | d k s9 t  Wn' t k
 rc |  j   t d   n Xd S(   sd   
        Unlock this keyring by getting the password for the keyring from the
        user.
        s-   Please enter password for encrypted keyring: s   keyring-settings   password references   password reference values   Incorrect PasswordN(   R   R   R   R2   t   _lockt
   ValueError(   R   t   ref_pw(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    
c         C   s
   |  `  d S(   s<   
        Remove the keyring key from this instance.
        N(   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    c         C   sW   d d d d  } d d l m } | | | d |  j } | j | |  j  | j |  S(   sK   
        Create the cipher object to encrypt or decrypt a payload.
        i   i  c            sJ  d d  l  } d d  l } d d l m } d d l m   m  d d l m } | j	 d d k rm d   }	 n	 d   }	 |	 |   }  | d  k r    f d	   } n  | d
  }
 d } x t |
  | k  rA| |  | | j d |   } } x: t | d  D]( } | |  |  } } | | |  } q W|
 | 7}
 | d } q W|
 |  S(   Ni(   t   b(   t   SHAt   HMAC(   t   strxori    i   c         S   s-   t  |  t  r |  j d  Sd j |   Sd  S(   Ns   latin-1RB   (   RX   RY   RZ   RJ   (   t   s(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   tobytes$  s    c         S   s=   t  |  t  r |  St  |  t  r/ |  j d  St |   Sd  S(   Ns   latin-1(   RX   t   bytesRK   RZ   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   *  s
    c            s    j  |  |    j   S(   N(   t   newt   digest(   t   pR   (   t   SHA1R   (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   5  s    RB   i   s   >I(   R$   t   structt   Crypto.Util.py3compatR   t   Crypto.HashR   R   t   Crypto.Util.strxorR   t   version_infoR	   R1   t   packt   xrange(   R   t   saltt   dkLent   countt   prfR$   R   R   R   R   R~   t   it   Ut	   previousUt   jt   t(    (   R   R   s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   PBKDF2  s*    		#
i(   t   AESR   N(   R	   t   Crypto.CipherR   t
   block_sizeR   t   MODE_CFB(   R   R   R   t   IVR   R   t   pw(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _create_cipher  s    &c   
      C   s   d d l  m } | |  j  } d d l m } | | j  } |  j |  j | |  } | j d |  } t d | d | d |  } x% | D] }	 | |	 j	 d  | |	 <q Wt
 j |  S(	   Ni(   t   get_random_bytes(   R   s   pw:R   R   R   R   (   t   Crypto.RandomR   R   R   R   R   R   R   t   dictRZ   R   t   dumps(
   R   R   R   R   R   R   t   cipherR   t   dataR~   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   E  s    c         C   s   t  j |  } x% | D] } | | j d  | | <q W|  j |  j | d | d  } | j | d  } | j d  s t  | d S(   NR   R   R   R   s   pw:i   (   R   t   loadsR   R   R   R   t
   startswithR2   (   R   R   R   R~   R   t	   plaintext(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   T  s    c         C   s   |  j  |  |  j |  d S(   s?   
        Convert older keyrings to the current format.
        N(   t"   _CryptedFileKeyring__convert_0_9_0t"   _CryptedFileKeyring__convert_0_9_1(   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   _  s    c         C   s  t  |  j   } t |  } Wd QXy, g  | D] } | j d  ^ q. \ } } Wn t k
 rd d SXd GH| |  j  } | |  j } | d k r t j d  } n  |  j | | |  }	 t	 j	 |	 j
 |   }
 t j   } y | j |
  Wn0 t j k
 rt j j d  t d   n X| |  _ t j |  j  |  j d d d	  x | j   D]x } xo | j |  D]^ } | j | |  j d
  } t j j j |  } t j j j |  } |  j | | |  qnWqXWd GHd S(   sN   
        Convert keyring from the 0.9.1 format to the current format.
        NR   s)   Keyring from 0.9.1 detected. Upgrading...s,   Please input your password for the keyring: s    Wrong password for the keyring.
s   Wrong passwords   keyring-settings   password references   password reference values   utf-8s   File upgraded successfully(   R   R   t   listR   t	   ExceptionR   R	   R   R   t   StringIOR   R   R   t   readfpt   ErrorR$   R   R   R   R   R,   t   removeR   t   sectionst   optionsR   R   R   R    t   unescape(   R   R   t   ft   encoded_linest   linet   headR   R   R   R   R   R   R
   R4   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   __convert_0_9_1f  s>    ,	c         C   s  d } d } y0 t  j   } | j |  j  | j | |  Wn t k
 rP d SXd GHd d l } | d k r t j d  } n  | j | |  } | j | |  | k r t	 j
 j d  t d   n  | |  _ | j | |  t |  j d	   } | j |  Wd QX|  j d d
 d  d d l m } | |  j t |  |  j |  j }	 x | j   D] }
 x | j |
  D] } | j |	 | j d | j  } | j |
 |  j d  } t j j j |
  }
 t j j j |  } | j |  } |  j |
 | |  quWq_Wd GHd S(   sb   
        Convert keyring from the 0.9.0 and earlier format to the current
        format.
        s   keyring-settings   crypted-passwordNs4   Keyring from 0.9.0 or earlier detected. Upgrading...is,   Please input your password for the keyring: s    Wrong password for the keyring.
s   Wrong passwordR   s   password references   password reference value(   R   t    R   s   File upgraded successfully(    R   R   R   R   R   R   t   cryptR	   R   R$   R   R   R   R   t   remove_optionR   R   R   R   R   R1   t   pad_charR   R   R   R   R   R   R   R    R   R   (   R   R   t   KEYRING_SETTINGt   CRYPTED_PASSWORDR   R  t   hashedR   R   R   R
   R4   R   t
   password_ct
   password_p(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   __convert_0_9_0  sJ    	N(   R   R   R   R   R  R   R   R   R   R   R   R   R   R   R   R   R   R   R	   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s"   				
				/			0t   Win32CryptoKeyringc           B   s8   e  Z d  Z d Z d   Z d   Z d   Z d   Z RS(   s   Win32 Cryptography Keyrings   wincrypto_pass.cfgc         C   sQ   t  t |   j   y d d l m } | |  _ Wn t k
 rL d  |  _ n Xd  S(   Ni(   t   win32_crypto(   t   superR  R   R"   R  t   crypt_handlerR   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@   Recommended 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  R   (   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     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   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR    s   				t   WinVaultKeyringc           B   se   e  Z d  Z d   Z d   Z e d    Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z RS(
   s  
    WinVaultKeyring stores encrypted passwords using the Windows Credential
    Manager.

    Requires pywin32

    This backend does some gymnastics to simulate multi-user support,
    which WinVault doesn't support natively. See
    https://bitbucket.org/kang/python-keyring-lib/issue/47/winvaultkeyring-only-ever-returns-last#comment-731977
    for details on the implementation, but here's the gist:

    Passwords are stored under the service name unless there is a collision
    (another password with the same service name but different user name),
    in which case the previous password is moved into a compound name:
    {username}@{service}
    c         C   sb   t  t |   j   y. d d  l } d d  l } | |  _ | |  _ Wn t k
 r] d  |  _ n Xd  S(   Ni(   R  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   s   d t    S(   Nu   %(username)s@%(service)s(   t   vars(   R   R
   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   _compound_name  s    c         C   se   |  j  |  } | s& | d | k rD |  j  |  j | |   } n  | sN d  S| d } | j d  S(   Nt   UserNamet   CredentialBlobs   utf-16(   t   _get_passwordR  R	   R   (   R   R
   R   t   rest   blob(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR     s    
c         C   sj   y% |  j  j d |  j  j d |  } Wn> |  j j k
 re } | j d k r_ | j d k r_ d  S  n X| S(   Nt   Typet
   TargetNamei  t   CredRead(   R  R#  t   CRED_TYPE_GENERICR  t   errort   winerrort   funcnameR	   (   R   t   targetR  R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR  $  s    c         C   sq   |  j  |  } | rT | d } |  j | |  } |  j | | | d j d   n  |  j | | t |   d  S(   NR  R  s   utf-16(   R  R  t   _set_passwordR   RY   (   R   R
   R   R   t   existing_pwt   existing_usernameR(  (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   0  s    
c         C   sP   t  d |  j j d | d | d | d d d |  j j  } |  j j | d  d  S(	   NR!  R"  R  R  t   Comments   Stored using python-keyringt   Persisti    (   R   R  R$  t   CRED_PERSIST_ENTERPRISEt	   CredWrite(   R   R(  R   R   t
   credential(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR)  :  s    c         C   sb   |  j  | |  } xI | | f D]; } |  j |  } | r | d | k r |  j |  q q Wd  S(   NR  (   R  R  t   _delete_password(   R   R
   R   t   compoundR(  R*  (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   delete_passwordC  s
    c         C   s#   |  j  j d |  j  j d |  d  S(   NR!  R"  (   R  t
   CredDeleteR$  (   R   R(  (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR1  J  s    (   R   R   R   R   R   t   staticmethodR  R   R  R   R)  R3  R1  (    (    (    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   s[   t  t |   j   y' d d l m } t d  | |  _ Wn t k
 rV d  |  _ n Xd  S(   Ni(   R  t   _winreg(	   R  R6  R   R"   R  R+   R  R   R	   (   R   R  (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   T  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 } t j |  }	 |  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    N(
   R7  R9  R:  R;  R   R   R  R   t   EnvironmentErrorR	   (   R   R
   R   R9  R:  R;  R~   t   hkeyR   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   l  s    

c         C   sp   |  j  j |  } t j |  } d d l m } m } m } m }	 | | d |  }
 | |
 | d |	 |  d S(   s+   Write the password to the registry
        i(   R9  t	   CreateKeyt
   SetValueExt   REG_SZs   Software\%s\Keyringi    N(	   R  R   R   R   R7  R9  R>  R?  R@  (   R   R
   R   R   R   R   R9  R>  R?  R@  R=  (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR   }  s
    "(   R   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR6  P  s
   	
		c          C   s   t  j d k r d  St j   \ }  } } } } y. t d  t d  |  | f d k r[ d SWn t k
 ro n Xy. t d  t d  |  | f d k r d
 SWn t k
 r n Xy t d  d SWn t k
 r n Xd  S(   Nt   ntR  R  i   i   R  s   keyring.backends.win32_cryptoR7  i    R8  R  (   i   i   (   i   i    (   R,   t   nameR	   R$   t   getwindowsversionR+   R   (   t   majort   minort   buildR%   t   text(    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyR    s.    




c        	   C   sO   t  d k rK t   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&   Rx   R   R   R  R6  R  R:   (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   get_all_keyring  s    (1   R   R   R,   R   R$   R   R   R   t   keyring.util.escapeR    R   R   t   keyring.utilR   t   keyring.util.platformt   keyring.util.loc_compatt   keyring.py25compatt
   py25compatR   R   R   R   t   objectR   R   R    R&   R:   R	   Rc   Rw   t   PyKDE4.kdeuiRd   t   PyQt4Rf   R   R   Rz   R9   Rx   R   R   R   R  R  R6  R  RH  RI  (    (    (    s3   /usr/lib/python2.7/dist-packages/keyring/backend.pyt   <module>   sP   /3E#
h $a:	