ó
Ì	g]c           @   sm   d  Z  d d l Z d d l m Z e j e ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 e e	 g Z
 d S(	   sP  The credentials classes are used to encapsulate all authentication
information for the :class:`~pika.connection.ConnectionParameters` class.

The :class:`~pika.credentials.PlainCredentials` class returns the properly
formatted username and password to the :class:`~pika.connection.Connection`.

To authenticate with Pika, create a :class:`~pika.credentials.PlainCredentials`
object passing in the username and password and pass it as the credentials
argument value to the :class:`~pika.connection.ConnectionParameters` object.

If you are using :class:`~pika.connection.URLParameters` you do not need a
credentials object, one will automatically be created for you.

If you are looking to implement SSL certificate style authentication, you would
extend the :class:`~pika.credentials.ExternalCredentials` class implementing
the required behavior.

iÿÿÿÿNi   (   t   as_bytest   PlainCredentialsc           B   sD   e  Z d  Z d Z e d „ Z d „  Z d „  Z d „  Z d „  Z	 RS(   s*  A credentials object for the default authentication methodology with
    RabbitMQ.

    If you do not pass in credentials to the ConnectionParameters object, it
    will create credentials for 'guest' with the password of 'guest'.

    If you pass True to erase_on_connect the credentials will not be stored
    in memory after the Connection attempt has been made.

    :param str username: The username to authenticate with
    :param str password: The password to authenticate with
    :param bool erase_on_connect: erase credentials on connect.

    t   PLAINc         C   s   | |  _  | |  _ | |  _ d S(   sö   Create a new instance of PlainCredentials

        :param str username: The username to authenticate with
        :param str password: The password to authenticate with
        :param bool erase_on_connect: erase credentials on connect.

        N(   t   usernamet   passwordt   erase_on_connect(   t   selfR   R   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   __init__*   s    		c         C   sG   t  | t ƒ rC |  j | j k oB |  j | j k oB |  j | j k St S(   N(   t
   isinstanceR   R   R   R   t   NotImplemented(   R   t   other(    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   __eq__6   s
    c         C   s$   |  j  | ƒ } | t k	 r  | St S(   N(   R   R	   (   R   R
   t   result(    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   __ne__=   s    c         C   sS   t  t j ƒ t  | j ƒ j ƒ  k r( d St j d t  |  j ƒ d t  |  j ƒ f S(   s¯   Validate that this type of authentication is supported

        :param spec.Connection.Start start: Connection.Start method
        :rtype: tuple(str|None, str|None)

        t    N(   NN(   R    R   t   TYPEt
   mechanismst   splitt   NoneR   R   (   R   t   start(    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   response_forC   s
    c         C   s/   |  j  r+ t j d ƒ d |  _ d |  _ n  d S(   s<   Called by Connection when it no longer needs the credentialss    Erasing stored credential valuesN(   R   t   LOGGERt   infoR   R   R   (   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   erase_credentialsQ   s    		(
   t   __name__t
   __module__t   __doc__R   t   FalseR   R   R   R   R   (    (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR      s   			t   ExternalCredentialsc           B   sA   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s†   The ExternalCredentials class allows the connection to use EXTERNAL
    authentication, generally with a client SSL certificate.

    t   EXTERNALc         C   s   t  |  _ d S(   s,   Create a new instance of ExternalCredentialsN(   R   R   (   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   `   s    c         C   s#   t  | t ƒ r |  j | j k St S(   N(   R   R   R   R	   (   R   R
   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   d   s    c         C   s$   |  j  | ƒ } | t k	 r  | St S(   N(   R   R	   (   R   R
   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   i   s    c         C   s5   t  t j ƒ t  | j ƒ j ƒ  k r( d St j d f S(   sµ   Validate that this type of authentication is supported

        :param spec.Connection.Start start: Connection.Start method
        :rtype: tuple(str or None, str or None)

        t    N(   NN(   R    R   R   R   R   R   (   R   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   o   s    c         C   s   t  j d ƒ d S(   s<   Called by Connection when it no longer needs the credentialss&   Not supported by this Credentials typeN(   R   t   debug(   R   (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   {   s    (	   R   R   R   R   R   R   R   R   R   (    (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyR   Y   s   				(   R   t   loggingt   compatR    t	   getLoggerR   R   t   objectR   R   t   VALID_TYPES(    (    (    s5   /srv/kernel/kteam-tools/dashboard/pika/credentials.pyt   <module>   s   @(