a
    ’éi…  ã                   @   s¬   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlmZmZ ddlmZ erldd	lmZ d
ZG dd„ deƒZeddd�dee
e ee dœdd„ƒZdS )z!Base Authentication Plugin class.é    N)ÚABCÚabstractmethod)Ú	lru_cache)ÚTYPE_CHECKINGÚAnyÚOptionalÚTypeé   )ÚNotSupportedErrorÚProgrammingError)Úlogger)ÚMySQLSocketzmysql.connector.pluginsc                   @   sª   e Zd ZdZdeeeddœdd„Zeedœdd	„ƒZee	edœd
d„ƒƒZ
ee	edœdd„ƒƒZe	eeee dœdd„ƒZdeeedœdd„Ze	deeedœdd„ƒZdS )ÚMySQLAuthPluginzAuthorization plugin interface.FN)ÚusernameÚpasswordÚssl_enabledÚreturnc                 C   s.   |du rdn|| _ |du rdn|| _|| _dS )zConstructor.NÚ )Z	_usernameZ	_passwordÚ_ssl_enabled)Úselfr   r   r   © r   úP/home/Claro/venv/lib/python3.9/site-packages/mysql/connector/plugins/__init__.pyÚ__init__1   s    zMySQLAuthPlugin.__init__)r   c                 C   s   | j S )z&Signals whether or not SSL is enabled.)r   ©r   r   r   r   r   <   s    zMySQLAuthPlugin.ssl_enabledc                 C   s   dS )z'Signals whether or not SSL is required.Nr   r   r   r   r   Úrequires_sslA   s    zMySQLAuthPlugin.requires_sslc                 C   s   dS )zPlugin official name.Nr   r   r   r   r   ÚnameF   s    zMySQLAuthPlugin.name)Ú	auth_dataÚkwargsr   c                 K   s   dS )aˆ  Make the client's authorization response.

        Args:
            auth_data: Authorization data.
            kwargs: Custom configuration to be passed to the auth plugin
                    when invoked. The parameters defined here will override the ones
                    defined in the auth plugin itself.

        Returns:
            packet: Client's authorization response.
        Nr   )r   r   r   r   r   r   Úauth_responseK   s    zMySQLAuthPlugin.auth_responser   )Úsockr   r   r   c                 K   s   t ‚dS )a1  Handles server's `auth more data` response.

        Args:
            sock: Pointer to the socket connection.
            auth_data: Authentication method data (from a packet representing
                       an `auth more data` response).
            kwargs: Custom configuration to be passed to the auth plugin
                    when invoked. The parameters defined here will override the ones
                    defined in the auth plugin itself.

        Returns:
            packet: Last server's response after back-and-forth communication.
        N)ÚNotImplementedError©r   r   r   r   r   r   r   Úauth_more_responseY   s    z"MySQLAuthPlugin.auth_more_responsec                 K   s   dS )a?  Handles server's `auth switch request` response.

        Args:
            sock: Pointer to the socket connection.
            auth_data: Plugin provided data (extracted from a packet
                       representing an `auth switch request` response).
            kwargs: Custom configuration to be passed to the auth plugin
                    when invoked. The parameters defined here will override the ones
                    defined in the auth plugin itself.

        Returns:
            packet: Last server's response after back-and-forth communication.
        Nr   r!   r   r   r   Úauth_switch_responsek   s    z$MySQLAuthPlugin.auth_switch_response)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚboolr   Úpropertyr   r   r   r   Úbytesr   r   r   r"   r#   r   r   r   r   r   .   s2    üûþþr   é
   F)ÚmaxsizeÚtyped)Úplugin_nameÚauth_plugin_classr   c              
   C   sÖ   t }| rÂzVt d|¡ t d| ¡ t d| › �|¡}|rBt||ƒsH|j}t d|¡ t||ƒW S  tyŽ } zt 	d|¡ W Y d}~n<d}~0  t
yÀ } ztd|› �ƒ|‚W Y d}~n
d}~0 0 td| › d	�ƒ‚dS )
aÂ  Return authentication class based on plugin name

    This function returns the class for the authentication plugin plugin_name.
    The returned class is a subclass of BaseAuthPlugin.

    Args:
        plugin_name (str): Authentication plugin name.
        auth_plugin_class (str): Authentication plugin class name.

    Raises:
        NotSupportedError: When plugin_name is not supported.

    Returns:
        Subclass of `MySQLAuthPlugin`.
    zpackage: %szplugin_name: %sÚ.zAUTHENTICATION_PLUGIN_CLASS: %sz"Requested Module was not found: %sNzInvalid module name: zAuthentication plugin 'z' is not supported)ÚDEFAULT_PLUGINS_PKGr   ÚinfoÚ	importlibÚimport_moduleÚhasattrZAUTHENTICATION_PLUGIN_CLASSÚgetattrÚModuleNotFoundErrorÚwarningÚ
ValueErrorr   r
   )r/   r0   ÚpackageZplugin_moduleÚerrr   r   r   Úget_auth_plugin~   s     &r=   )N)r'   r4   Úabcr   r   Ú	functoolsr   Útypingr   r   r   r   Úerrorsr
   r   r   Únetworkr   r2   r   r(   r=   r   r   r   r   Ú<module>   s"   P
 þý