3
ct]0                 @   s   d Z ddlZddlZddlmZm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 ejdZdd ZG d	d
 d
ejZdS )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)unicodePY2)
WarningErrorInterfaceError	DataErrorDatabaseErrorOperationalErrorIntegrityErrorInternalErrorNotSupportedErrorProgrammingErrorz^(\d+)c             C   s    t j| }|rt|jdS dS )zReturns the leading numeric part of a string.

    >>> numeric_part("20-alpha")
    20
    >>> numeric_part("foo")
    >>> numeric_part("16b")
    16
       N)re_numeric_partmatchintgroup)sm r   S/var/www/html/enquirykeeper_venv/lib/python3.6/site-packages/MySQLdb/connections.pynumeric_part   s    

r   c                   s   e Zd ZdZejZ fddZdd ZdddZ	d	d
 Z
dd Zdd Zdd Zdd Zeejdsldd Z fddZdd Zdd ZeZeZeZeZeZeZeZeZeZeZ  Z S )
Connectionz MySQL Database Connection Objectc                s  ddl m}m} ddlm}m} ddlm} |j }d|krJ|j	d|d< d|kr`|j	d|d< d	|krr|d	 }	n|}	i }
xB|	j
 D ]6\}}t|trt|tr|d
d
 |
|< q||
|< qW |
|d	< |j	d| j}|jdd}|st rd}nd}|j	d|}|j	dd}|j	dd| _|jdd}tdd tj jdd
d D }|d!kr^||jO }|d"krr||jO }||d< |j	dd}tt| j|| || _tdd |	j
 D | _t| jt< tdd | j jdd
d D | _ d| _!||  d# fdd 	}|s| j" }| j#| |r*| j$| |rrx4|j%|j&|j'|j(|j)|j*|j+fD ]}|| j,|< qRW t-| j,|j.< || jt-< | j/|j0@ | _1| j1r|d
k	r| j2| g | _3d
S )$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, for backward compatibility
        :param str database:    database to use
        :param str db:          alias of database, for backward compatibility
        :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 False on Python 2 and True on Python 3
            so that you can always get python `str` object by default.

        :param str charset:
            If supplied, the connection character set will be changed
            to this character set.
            On Python 2, this option changes default value of `use_unicode`
            option from False to True.

        :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 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)proxyZdatabasedbpasswordpasswdconvNcursorclasscharset TFuse_unicodesql_modeZbinary_prefixclient_flagc             S   s   g | ]}t |qS r   )r   ).0nr   r   r   
<listcomp>   s    z'Connection.__init__.<locals>.<listcomp>.      r      
autocommitc             S   s$   g | ]\}}t |tk	r||fqS r   )typer   )r*   kvr   r   r   r,      s    c             S   s   g | ]}t |qS r   )r   )r*   r+   r   r   r   r,      s    asciic                s    j | j jS )N)string_literalencodeencoding)udummy)r    r   r   unicode_literal   s    z,Connection.__init__.<locals>.unicode_literal)r/   r   )r0   r   )N)4ZMySQLdb.constantsr   r   ZMySQLdb.convertersr   r   weakrefr   copypopitems
isinstancer   listdefault_cursorgetr   _binary_prefixtupler   Zget_client_infosplitZMULTI_STATEMENTSZMULTI_RESULTSsuperr   __init__r$   dictencodersbytesZget_server_info_server_versionr8   character_set_nameset_character_setset_sql_modeSTRINGZ
VAR_STRINGZVARCHARZ	TINY_BLOBZMEDIUM_BLOBZ	LONG_BLOBZBLOB	converterr   ZJSONZserver_capabilitiesZTRANSACTIONSZ_transactionalr1   messages)selfargskwargsr   r   r   r   r   Zkwargs2r#   Zconv2r3   r4   r$   r%   r'   r(   r)   Zclient_versionr1   r;   t)	__class__)r    r   rH   *   sr    Q

$




&




zConnection.__init__c             C   s&   t |}| j |kr"tjj| | d S )N)boolZget_autocommitr   
connectionr1   )rS   onr   r   r   r1      s    zConnection.autocommitNc             C   s   |p| 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$   )rS   r$   r   r   r   cursor   s    zConnection.cursorc             C   s$   t |trt|}tjj| | d S )N)r@   	bytearrayrK   r   rY   query)rS   r]   r   r   r   r]      s    
zConnection.queryc             C   s.   t |ttfst| j|}| jr*d| S |S )Ns   _binary)r@   rK   r\   AssertionErrorr6   rD   )rS   bsxr   r   r   _bytes_literal   s
    
zConnection._bytes_literalc             C   s   ddj t| j| S )Ns   (%s)   ,)joinmapliteral)rS   rV   r   r   r   _tuple_literal   s    zConnection._tuple_literalc             C   s   t |tr| j|j| j}nzt |tr4| j|}ndt |trZtrN| j|}q| j|}n>t |t	t
frt| j|}n$| j|| j}t |tr|j| j}t |tst|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.
        )r@   r   r6   r7   r8   r\   ra   rK   r   rE   rA   rf   escaperJ   r^   )rS   or   r   r   r   re      s    



zConnection.literalc             C   s   | j d dS )ziExplicitly begin a connection.

        This method is not used when autocommit=False (default).
        s   BEGINN)r]   )rS   r   r   r   begin  s    zConnection.beginwarning_countc             C   s$   | j  }|rt|j d S dS dS )zpReturn the number of warnings generated from the
            last query. This is derived from the info() method.r   r   N)infor   rF   )rS   rl   r   r   r   rj     s    zConnection.warning_countc                sz   |d	krd}n|}| j  |krpytt| j| W n< tk
rn   | jd
k rTtd| jd|  | j  Y nX || _	dS )zSet the connection character set to charset. The character
        set can only be changed in MySQL-4.1 and newer. If you try
        to change the character set from the current value in an
        older version, NotSupportedError will be raised.utf8mb4utf8mb3utf8r/   r   z server is too old to set charsetzSET NAMES %sN)rm   rn   )r/   r   )
rM   rG   r   rN   AttributeErrorrL   r   r]   store_resultr8   )rS   r%   Z
py_charset)rW   r   r   rN     s    
zConnection.set_character_setc             C   s,   | j dk rtd| jd|  | j  dS )zNSet the connection sql_mode. See MySQL documentation for
        legal values.r/   r   z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)r/   r   )rL   r   r]   rq   )rS   r(   r   r   r   rO   2  s    
zConnection.set_sql_modec             C   s.   | j dk rf S | 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/   r   zSHOW WARNINGSr   )r/   r   )rL   r]   rq   Z	fetch_row)rS   rwarningsr   r   r   show_warnings:  s    
 

zConnection.show_warnings)N)!__name__
__module____qualname____doc__r   ZCursorrB   rH   r1   r[   r]   ra   rf   re   ri   hasattrr   rY   rj   rN   rO   rt   r   r   r   r
   r	   r   r   r   r   r   __classcell__r   r   )rW   r   r   %   s4    ,
		r   )rx   resysZMySQLdbr   r   ZMySQLdb.compatr   r   ZMySQLdb._exceptionsr   r   r   r	   r
   r   r   r   r   r   compiler   r   rY   r   r   r   r   r   <module>   s   0
