U wf_^1@sdZddlZddlmZmZddlmZmZmZm Z m Z m Z m Z m Z mZmZddddd d Zed Zd d ZGdddejZdS)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) WarningErrorInterfaceError DataError DatabaseErrorOperationalErrorIntegrityError InternalErrorNotSupportedErrorProgrammingErrorutf8cp1252koi8_rkoi8_u)Zutf8mb4Zutf8mb3latin1Zkoi8rZkoi8uz^(\d+)cCs t|}|rt|dSdS)zReturns the leading numeric part of a string. >>> numeric_part("20-alpha") 20 >>> numeric_part("foo") >>> numeric_part("16b") 16 rN)re_numeric_partmatchintgroup)smrk/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-exc8n9q4/MySQLdb/connections.py numeric_part#s rcseZdZdZejZfddZddZddZ dd Z d d d Z d dZ ddZ ddZddZddZeejds|ddZfddZddZddZeZeZeZeZeZeZeZeZe Z e!Z!Z"S)! Connectionz MySQL Database Connection Objectcsddlm}m}ddlm}m}ddlm}|}d|krJ| d|d<d|kr`| d|d<d |krr|d } n|} i} | D]6\} } t | t rt | t r| d d | | <q| | | <q| |d <| d |j} |d d }| dd}| dd }| dd|_|dd}tddtdd dD}|dkrF||jO}|dkrZ||jO}||d<| dd}tj||| |_dd| D|_t|jt<tdd|dd dD|_d|_||d!fdd }|s|}| ||r |!||rN|j"|j#|j$|j%|j&|j'|j(fD]}||j)|<q0t*|j)|j+<||jt*<|j,|j-@|_.|j.r|d k r|/|g|_0d S)"aQ 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 True. :param str charset: If supplied, the connection character set will be changed to this character set. :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 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)proxyZdatabasedbpasswordpasswdconvN cursorclasscharset use_unicodeTsql_modeZ binary_prefixF client_flagcSsg|] }t|qSrr.0nrrr sz'Connection.__init__...r)r autocommitcSs"i|]\}}t|tk r||qSr)typer)r/kvrrr s z'Connection.__init__..cSsg|] }t|qSrr-r.rrrr1sasciics|jSN)string_literalencodeencoding)udummyr#rrunicode_literalsz,Connection.__init__..unicode_literal)N)1ZMySQLdb.constantsrrZMySQLdb.convertersr r!weakrefr"copypopitems isinstancerlistdefault_cursorget_binary_prefixtuplerZget_client_infosplitZMULTI_STATEMENTSZ MULTI_RESULTSsuper__init__r'encodersbytesZget_server_info_server_versionr@character_set_nameset_character_set set_sql_modeSTRINGZ VAR_STRINGZVARCHARZ TINY_BLOBZ MEDIUM_BLOBZ LONG_BLOBZBLOB converterstrZJSONZserver_capabilitiesZ TRANSACTIONSZ_transactionalr7messages)selfargskwargsrrr r!r"Zkwargs2r&Zconv2r9r:r'r(r*r+r,client_versionr7rDt __class__rCrrQ8sU                    zConnection.__init__cCs|Sr=rr\rrr __enter__szConnection.__enter__cCs |dSr=)close)r\exc_type exc_value tracebackrrr__exit__szConnection.__exit__cCs&t|}||kr"tj||dSr=)boolZget_autocommitr connectionr7)r\onrrrr7s zConnection.autocommitNcCs|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')r\r'rrrcursorszConnection.cursorcCs$t|trt|}tj||dSr=)rI bytearrayrSrrkquery)r\rorrrros zConnection.querycCs.t|ttfst||}|jr*d|S|S)Ns_binary)rIrSrnAssertionErrorr>rM)r\bsxrrr_bytes_literals  zConnection._bytes_literalcCsddt|j|S)Ns(%s),)joinmapliteral)r\r`rrr_tuple_literal szConnection._tuple_literalcCst|tr|||j}njt|tr4||}nTt|trJ||}n>t|tt frd| |}n$| ||j }t|tr||j}t|tst |S)aIf 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. )rIrZr>r?r@rnrsrSrNrJrxescaperRrp)r\orrrrrws        zConnection.literalcCs|ddS)ziExplicitly begin a connection. This method is not used when autocommit=False (default). sBEGINN)rorcrrrbegin&szConnection.begin warning_countcCs$|}|rt|dSdSdS)zpReturn the number of warnings generated from the last query. This is derived from the info() method.rN)inforrO)r\r~rrrr|/szConnection.warning_countcspt||}||krfzt|Wn<tk rd|jdkrJtd|d|| YnX||_ dS)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.r4z server is too old to set charsetz SET NAMES %sN) _charset_to_encodingrLrUrPrVAttributeErrorrTr ro store_resultr@)r\r(Z py_charsetrarrrV8s   zConnection.set_character_setcCs,|jdkrtd|d||dS)zNSet the connection sql_mode. See MySQL documentation for legal values.r4z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)rTr ror)r\r+rrrrWHs zConnection.set_sql_modecCs.|jdkrdS|d|}|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.r4rz SHOW WARNINGSr)rTrorZ fetch_row)r\rwarningsrrr show_warningsPs    zConnection.show_warnings)N)#__name__ __module__ __qualname____doc__rCursorrKrQrdrir7rmrorsrxrwr{hasattrrrkr|rVrWrrrrr rr r r rr __classcell__rrrarr3s8 4    r)rrer)rr _exceptionsrrrrr r r r r rrcompilerrrkrrrrrs0