3
Šãde+  ã               @   sL   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 G dd„ deƒZ
d	S )
z!Base Authentication Plugin class.é    )ÚABC)ÚOptionalÚUnioné   )Úerrors)Ú
StrOrBytesc               @   sp   e Zd ZU dZdZedZedee	 ee
 ee ee eddœdd„Ze	dœd	d
„Zdee	 e	dœdd„ZdS )ÚBaseAuthPluginaÊ  Base class for authentication pluginsF


    Classes inheriting from BaseAuthPlugin should implement the method
    prepare_password(). When instantiating, auth_data argument is
    required. The username, password and database are optional. The
    ssl_enabled argument can be used to tell the plugin whether SSL is
    active or not.

    The method auth_response() method is used to retrieve the password
    which was prepared by prepare_password().
    FÚ N)Ú	auth_dataÚusernameÚpasswordÚdatabaseÚssl_enabledÚreturnc             C   s:   || _ t|ttfƒr|jdƒn|| _|| _|| _|| _dS )ZInitializationÚutf8N)	Z
_auth_dataÚ
isinstanceÚbytesÚ	bytearrayÚdecodeZ	_usernameÚ	_passwordZ	_databaseÚ_ssl_enabled)Úselfr
   r   r   r   r   © r   úW/var/www/agendate/envp3/lib/python3.6/site-packages/mysql/connector/plugins/__init__.pyÚ__init__7   s    	zBaseAuthPlugin.__init__)r   c             C   s,   | j s
dS | j }t|tƒr$|jdƒ}|d S )znPrepare and return password as as clear text.

        Returns:
            bytes: Prepared password.
        ó    r   )r   r   ÚstrÚencode)r   r   r   r   r   Úprepare_passwordJ   s    

zBaseAuthPlugin.prepare_password)r
   r   c             C   s(   | j r | j r tj| j› d�ƒ‚| jƒ S )zÃReturn the prepared password to send to MySQL.

        Raises:
            InterfaceError: When SSL is required by not enabled.

        Returns:
            str: The prepared password.
        z requires SSL)Úrequires_sslr   r   ZInterfaceErrorÚplugin_namer   )r   r
   r   r   r   Úauth_responseY   s    zBaseAuthPlugin.auth_response)NNNF)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úintr    r   r   r   r   Úboolr   r   r!   r   r   r   r   r   &   s   
   r   N)r%   Úabcr   Útypingr   r   r	   r   Útypesr   r   r   r   r   r   Ú<module>   s
   