
    +h.                         d Z ddlZddlmZmZ ddlmZmZmZm	Z	m
Z
mZmZmZmZmZ ddddd	d
Z ej"                  d      Zd Z G d dej(                        Zy)a  
This module implements connections for MySQLdb. Presently there is
only one class: Connection. Others are unlikely. However, you might
want to make your own subclasses. In most cases, you will probably
override Connection.default_cursor with a non-standard Cursor class.
    N   )cursors_mysql)
WarningErrorInterfaceError	DataErrorDatabaseErrorOperationalErrorIntegrityErrorInternalErrorNotSupportedErrorProgrammingErrorutf8cp1252koi8_rkoi8_u)utf8mb4utf8mb3latin1koi8rkoi8uz^(\d+)c                 f    t         j                  |       }|rt        |j                  d            S y)zReturns the leading numeric part of a string.

    >>> numeric_part("20-alpha")
    20
    >>> numeric_part("foo")
    >>> numeric_part("16b")
    16
    r   N)re_numeric_partmatchintgroup)sms     F/var/www/html/venv/lib/python3.12/site-packages/MySQLdb/connections.pynumeric_partr!   #   s,     	a A1771:    c                        e Zd ZdZej
                  Z fdZd Zd Z	d Z
ddZd Zd Zd	 Zd
 Zd Zd fd	Zd Zd ZeZeZeZeZeZeZeZeZeZeZ xZS )
Connectionz MySQL Database Connection Objectc                 R   ddl m}m} ddlm}m} |j                         }d|v r|j                  d      |d<   d|v r|j                  d      |d<   d|v r|d   }n|}i }	|j                         D ]3  \  }
}t        |
t              rt        |t              r	|d	d	 |	|
<   /||	|
<   5 |	|d<   |j                  d
| j                        }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      }|j                  dd      | _        |j                  dd      }||j                  z  }|j                  dd      }|r||j                   z  }||d<   |j                  dd      }t#        | H  |i | || _        |j                         D 
ci c]  \  }
}t)        |
      t        us|
| c}}
| _        t-        | j/                         j1                  d      d	d D cg c]  }t3        |       c}      | _        d| _        |s| j9                         }| j;                  ||       |r| j=                  |       |r|j>                  |j@                  |jB                  |jD                  |jF                  |jH                  |jJ                  fD ]  }|| jL                  |<    tN        | jL                  |jP                  <   | jR                  |jT                  z  | _+        | jV                  r|| jY                  |       g | _-        y	c c}}
w c c}w )a  
        Create a connection to the database. It is strongly recommended
        that you only use keyword parameters. Consult the MySQL C API
        documentation for more information.

        :param str host:        host to connect
        :param str user:        user to connect as
        :param str password:    password to use
        :param str passwd:      alias of password (deprecated)
        :param str database:    database to use
        :param str db:          alias of database (deprecated)
        :param int port:        TCP/IP port to connect to
        :param str unix_socket: location of unix_socket to use
        :param dict conv:       conversion dictionary, see MySQLdb.converters
        :param int connect_timeout:
            number of seconds to wait before the connection attempt fails.

        :param bool compress:   if set, compression is enabled
        :param str named_pipe:  if set, a named pipe is used to connect (Windows only)
        :param str init_command:
            command which is run once the connection is created

        :param str read_default_file:
            file from which default client values are read

        :param str read_default_group:
            configuration group to use from the default file

        :param type cursorclass:
            class object, used to create cursors (keyword only)

        :param bool use_unicode:
            If True, text-like columns are returned as unicode objects
            using the connection's character set. Otherwise, text-like
            columns are returned as bytes. Unicode objects will always
            be encoded to the connection's character set regardless of
            this setting.
            Default to True.

        :param str charset:
            If supplied, the connection character set will be changed
            to this character set.

        :param str collation:
            If ``charset`` and ``collation`` are both supplied, the
            character set and collation for the current connection
            will be set.

            If omitted, empty string, or None, the default collation
            for the ``charset`` is implied.

        :param str auth_plugin:
            If supplied, the connection default authentication plugin will be
            changed to this value. Example values:
            `mysql_native_password` or `caching_sha2_password`

        :param str sql_mode:
            If supplied, the session SQL mode will be changed to this
            setting.
            For more details and legal values, see the MySQL documentation.

        :param int client_flag:
            flags to use or 0 (see MySQL docs or constants/CLIENTS.py)

        :param bool multi_statements:
            If True, enable multi statements for clients >= 4.1.
            Defaults to True.

        :param str ssl_mode:
            specify the security settings for connection to the server;
            see the MySQL documentation for more details
            (mysql_option(), MYSQL_OPT_SSL_MODE).
            Only one of 'DISABLED', 'PREFERRED', 'REQUIRED',
            'VERIFY_CA', 'VERIFY_IDENTITY' can be specified.

        :param dict ssl:
            dictionary or mapping contains SSL connection parameters;
            see the MySQL documentation for more details
            (mysql_ssl_set()).  If this is set, and the client does not
            support SSL, NotSupportedError will be raised.

        :param bool local_infile:
            enables LOAD LOCAL INFILE; zero disables

        :param bool autocommit:
            If False (default), autocommit is disabled.
            If True, autocommit is enabled.
            If None, autocommit isn't set and server default is used.

        :param bool binary_prefix:
            If set, the '_binary' prefix will be used for raw byte query
            arguments (e.g. Binary). This is disabled by default.

        There are a number of undocumented, non-standard methods. See the
        documentation for the MySQL C API for some hints on what they do.
        r   )CLIENT
FIELD_TYPE)conversions_bytes_or_strdbdatabasepasswdpasswordconvNcursorclasscharset 	collationuse_unicodeTsql_modebinary_prefixFclient_flagmulti_statements
autocommit.   ascii).MySQLdb.constantsr&   r'   MySQLdb.convertersr(   r)   copypopitems
isinstancer   listdefault_cursorget_binary_prefixMULTI_RESULTSMULTI_STATEMENTSsuper__init__r/   typeencoderstupleget_server_infosplitr!   _server_versionencodingcharacter_set_nameset_character_setset_sql_modeSTRING
VAR_STRINGVARCHAR	TINY_BLOBMEDIUM_BLOB	LONG_BLOBBLOB	converterstrJSONserver_capabilitiesTRANSACTIONS_transactionalr8   messages)selfargskwargsr&   r'   r(   r)   kwargs2r.   conv2kvr/   r0   r2   r3   r4   r6   r7   r8   nt	__class__s                         r    rI   zConnection.__init__8   s   B 	9A++-7?")++d"3GJw")++h"7GJV&>DDJJL 	DAq!S!jD&9Q4aa		
  kk-1D1DE++i,KKR0	kk-6;;z2.%kk/5Ajj2v+++";;'94@6222K!, [[u5
$*'*&*.**,M$!Q$q':LAM$&*&:&:&<&B&B3&G&KL\!_L 
  --/Gw	2h'!!%%""$$&&$$ 	2 %2q!	2 /2DNN:??+"669L9LL%
+E N Ms   *LL;L$c                     | S N rb   s    r    	__enter__zConnection.__enter__   s    r"   c                 $    | j                          y rm   )close)rb   exc_type	exc_value	tracebacks       r    __exit__zConnection.__exit__   s    

r"   c                     t        |      }| j                         |k7  r!t        j                  j	                  | |       y y rm   )boolget_autocommitr   
connectionr8   )rb   ons     r    r8   zConnection.autocommit   s7    "X B&((r2 'r"   c                 .     |xs | j                   |       S )z
        Create a cursor on which queries may be performed. The
        optional cursorclass parameter is used to create the
        Cursor. By default, self.cursorclass=cursors.Cursor is
        used.
        )r/   )rb   r/   s     r    cursorzConnection.cursor   s     0/t//66r"   c                 z    t        |t              rt        |      }t        j                  j                  | |       y rm   )rA   	bytearraybytesr   rz   query)rb   r   s     r    r   zConnection.query   s+    eY'%LEe,r"   c                 z    t        |t        t        f      sJ | j                  |      }| j                  rd|z   S |S )Ns   _binary)rA   r   r   string_literalrE   )rb   bsxs      r    _bytes_literalzConnection._bytes_literal  s?    "ui0111#>!r"   c                 R    ddj                  t        | j                  |            z  S )Ns   (%s)   ,)joinmapliteral)rb   rj   s     r    _tuple_literalzConnection._tuple_literal  s!    $))Ca$89::r"   c                    t        |t              r+| j                  |j                  | j                              }nt        |t
              r| j                  |      }nt        |t              r| j                  |      }not        |t        t        f      r| j                  |      }nG| j                  || j                        }t        |t              r|j                  | j                        }t        |t              sJ |S )a  If o is a single object, returns an SQL literal as a string.
        If o is a non-string sequence, the items of the sequence are
        converted and returned as a sequence.

        Non-standard. For internal use; do not use this in your
        applications.
        )rA   r\   r   encoderP   r   r   r   rL   rB   r   escaperK   )rb   or   s      r    r   zConnection.literal  s     a##AHHT]]$;<A9%##A&A5!##A&AE4=)##A&AAt}}-A!S!HHT]]+!U###r"   c                 &    | j                  d       y)ziExplicitly begin a connection.

        This method is not used when autocommit=False (default).
        s   BEGINN)r   ro   s    r    beginzConnection.begin"  s    
 	

8r"   c                     t         |   |       t        j                  ||      | _        |r(| j                  d| d|        | j                          yy)z,Set the connection character set to charset.z
SET NAMES z	 COLLATE N)rH   rR   _charset_to_encodingrD   rP   r   store_result)rb   r0   r2   rk   s      r    rR   zConnection.set_character_set)  sQ    !'*,00'BJJG9Ii[AB r"   c                     | j                   dk  rt        d      | j                  d|z         | j                          y)zNSet the connection sql_mode. See MySQL documentation for
        legal values.   r   z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)rO   r   r   r   )rb   r4   s     r    rS   zConnection.set_sql_mode1  s<     &(#$GHH

.9:r"   c                     | j                   dk  ry| j                  d       | j                         }|j                  d      }|S )zReturn detailed information about warnings as a
        sequence of tuples of (Level, Code, Message). This
        is only supported in MySQL-4.1 and up. If your server
        is an earlier version, an empty sequence is returned.r   rn   zSHOW WARNINGSr   )rO   r   r   	fetch_row)rb   rwarningss      r    show_warningszConnection.show_warnings9  sA    
 &(

?#;;q>r"   rm   )__name__
__module____qualname____doc__r   CursorrC   rI   rp   rv   r8   r}   r   r   r   r   r   rR   rS   r   r   r   r   r
   r	   r   r   r   r   r   __classcell__)rk   s   @r    r$   r$   3   s    *^^Nm^3
7-;. 
 GE#N!MI'#N!M')r"   r$   )r   rer1   r   r   _exceptionsr   r   r   r	   r
   r   r   r   r   r   r   compiler   r!   rz   r$   rn   r"   r    <module>r      se    
      "**Y' [*"" [*r"   