ó
©9Nc           @   s    d  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 m Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z e ƒ  d S(   s.   
core.py

Created by Kang Zhang on 2009-07-09
iÿÿÿÿN(   t   logger(   t   backendc         C   s+   t  |  t j ƒ r |  a n t d ƒ ‚ d S(   s!   Set current keyring backend.
    s0   The keyring must be a subclass of KeyringBackendN(   t
   isinstanceR   t   KeyringBackendt   _keyring_backendt	   TypeError(   t   keyring(    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   set_keyring   s    	c           C   s   t  S(   s!   Get current keyring backend.
    (   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   get_keyring   s    c         C   s   t  j |  | ƒ S(   s,   Get password from the specified service
    (   R   t   get_password(   t   service_namet   username(    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyR	      s    c         C   s   t  j |  | | ƒ d S(   s6   Set password for the user in the spcified service
    N(   R   t   set_password(   R
   R   t   password(    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyR       s    c          C   sL   t  ƒ  }  |  d k r> t j ƒ  } | j d „  ƒ | d }  n  t |  ƒ d S(   s‹   first try to load the keyring in the config file, if it has not
    been decleared, assign a defult keyring according to the platform.
    c         S   s   | j  ƒ  |  j  ƒ  S(   N(   t	   supported(   t   xt   y(    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   <lambda>1   s    i    N(   t   load_configt   NoneR   t   get_all_keyringt   sortR   (   R   t   keyrings(    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   init_backend%   s    	c            sŠ   ‡  f d †  ‰  y e  j | | j d ƒ  } Wn* e k
 rY ˆ  | e  j |  g ƒ } n X| j d ƒ d j ƒ  } d | d e ƒ  Ue S(   s“   Load the specified keyring name from the specified path

    `keyring_path` can be None and it will not interfer with the loading
    process.
    c   
         sÅ   |  j  d ƒ } t j | d | ƒ } | \ } } } t j | d | | | ƒ } | rc | j ƒ  n  t | ƒ d k rÁ d j | d ƒ } | }	 y | | j }	 Wn t k
 r³ | SXˆ  | |	 ƒ S| S(   s1   Load the specified module from the disk.
        t   .i    i   (	   t   splitt   impt   find_modulet   load_modulet   closet   lent   joint   __path__t   AttributeError(
   t   namet   patht	   path_listt   module_infot   module_filet   pathnamet   descriptiont   modulet   sub_namet   sub_path(   R   (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyR   ?   s     R   iÿÿÿÿs   keyring_temp = module.s   () (	   t   syst   modulest   rfindt   KeyErrorR#   R   t   stript   localst   keyring_temp(   t   keyring_patht   keyring_nameR)   t   keyring_class(    (   R   s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   load_keyring8   s    c          C   sy  d }  t j j t j ƒ  d ƒ t j j t j j d ƒ d ƒ g } d } x* | D]" } | } t j j | ƒ rO PqO qO Wt j j | ƒ rut j ƒ  } | j	 | ƒ y4 | j
 d ƒ rÍ | j d d ƒ j ƒ  } n d } Wn t j k
 rð d } n XyO | j
 d ƒ r| j d d ƒ j ƒ  } n t j d d ƒ ‚ t | | ƒ }  Wqut j t f k
 rqt j d d | ƒ quXn  |  S(	   sˆ   load a keyring using the config file, the config file can be
    in the current working directory, or in the user's home directory.
    s   keyringrc.cfgt   ~R   s   keyring-paths   default-keyrings.   Keyring Config file does not write correctly.
s   Config file: %sN(   R   t   osR#   R   t   getcwdt
   expandusert   existst   ConfigParsert   RawConfigParsert   readt   has_sectiont   getR0   t   NoOptionErrorR6   t   ImportErrorR    t   warning(   R   t   keyring_cfg_listt   keyring_cfgR#   t   configR3   R4   (    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyR   d   s4    $

	(   t   __doc__R8   R<   R   R,   R   R    R   R   R   R	   R   R   R6   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/keyring/core.pyt   <module>   s   						,	+