B XG9@sdZddlZddlZddlmZddlmZmZddlm Z m Z m Z m Z m Z mZmZmZmZmZddlZesejdddkrdd ed DZd d Znd d ZddZedZddZGdddejZdS)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)unicodePY2) WarningErrorInterfaceError DataError DatabaseErrorOperationalErrorIntegrityError InternalErrorNotSupportedErrorProgrammingError)cCs(g|] }|dkrt|n t|dqS)i)chr).0irF/opt/alt/python37/lib64/python3.7/site-packages/MySQLdb/connections.py srcCs|dtS)Nlatin1)decode translate_surrogateescape_table)srrr_fast_surrogateescapesrcCs |ddS)Nasciisurrogateescape)r)rrrrrscCsV||f}|r|j|n |j|~~t|tr8||dk rJ||nt|dS)a* If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages. Then errorclass is raised with errorvalue as the value. You can override this with your own error handler by assigning it to the instance. N)messagesappend isinstance BaseException Exception) connectioncursorZ errorclassZ errorvalueerrorrrrdefaulterrorhandler s    r*z^(\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 N)re_numeric_partmatchintgroup)rmrrr numeric_part;s r1cseZdZdZejZdZfddZddZ dddZ d d Z d d Z d dZ ddZddZeejdspddZfddZddZddZeZeZeZeZeZeZeZeZeZe Z e!Z"Z#S) Connectionz MySQL Database Connection ObjectNcs.ddlm}m}ddlm}ddlm}|}d|krF|d|d<d|kr\|d|d<d |krn|d }n|}i} xB| D]6\} } t | t rt | t r| d d | | <q| | | <qW| |d <|d |j } |d d } | stsd}nd}|d|}|dd }|dd}|dd}tddtdd dD}|dkrV||jO}|dkrj||jO}||d<|dd}|dd |_tt|j||| |_tdd| D|_tdd|dd dD|_||fdd}fd d!}fd"d#}d$d%}|}||_}|}||_ }| sH|!} |"| |rb|#||r|j$|j%&d |f|j$|j'&d |f|j$|j(&d |f|j$|j)&d |f|rtr|n||jt*<||jt+<n ||jt*<||jt,<|j-|j.@|_/|j/r$|d k r$|0|g|_1d 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 str 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 strings. columns are returned as normal strings. 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. :param str charset: If supplied, the connection character set will be changed to this character set (MySQL-4.1 and newer). This implies use_unicode=True. :param str sql_mode: If supplied, the session SQL mode will be changed to this setting (MySQL-4.1 and newer). 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)proxyZdatabasedbZpasswordZpasswdconvN cursorclasscharsetTF use_unicodesql_mode binary_prefix client_flagcSsg|] }t|qSr)r1)rnrrrrsz'Connection.__init__...r)r+)r autocommitwaitercSs$g|]\}}t|tk r||fqSr)typer.)rkvrrrrscSsg|] }t|qSr)r1)rr@rrrrscsdfdd }|S)Ncs |S)N)string_literal)objdummy)r7rrrIszHConnection.__init__.._get_string_literal..string_literal)Nr)rI)r7rr_get_string_literalsz0Connection.__init__.._get_string_literalcs*trdfdd ndfdd S)Ncs|jS)N)rIencoder:)urK)r7unicode_literalrrrOszJConnection.__init__.._get_unicode_literal..unicode_literalcst|jS)N)rIstrrMr:)rNrK)r7rOrrrOs)N)N)rr)r7)rOr_get_unicode_literalsz1Connection.__init__.._get_unicode_literalcsdfdd }|S)Ncsd|S)Ns_binary)rI)rJrK)r7rr bytes_literalszFConnection.__init__.._get_bytes_literal..bytes_literal)Nr)rR)r7rr_get_bytes_literalsz/Connection.__init__.._get_bytes_literalcsfddS)Ncs |jS)N)rr:)r)string_decoderrrrTszHConnection.__init__.._get_string_decoder..string_decoderrrr)rTr_get_string_decoders z0Connection.__init__.._get_string_decoder)2ZMySQLdb.constantsr3r4ZMySQLdb.convertersr5weakrefr6copypopitemsr$r.listdefault_cursorrgettuple_mysqlZget_client_infosplitZMULTI_STATEMENTSZ MULTI_RESULTSrEsuperr2__init__r9dictencodersZget_server_info_server_versionrOrTcharacter_set_nameset_character_set set_sql_modeZ converterSTRINGr#Z VAR_STRINGZVARCHARZBLOBbytes bytearrayrZserver_capabilitiesZ TRANSACTIONSZ_transactionalrDr")selfargskwargsr3r4r5r6Zkwargs2r8Zconv2rGrHr9r:r<r=r>r?Zclient_versionrDrLrQrSrUrIrOrRrT) __class__)r7rraQsJ         $     &           zConnection.__init__cCs&t|}||kr"tj||dS)N)boolget_autocommitr^r'rD)rkonrrrrD s zConnection.autocommitcCs|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. )r9)rkr9rrrr(szConnection.cursorcCsPt|trt|}|jdk r>|||||ntj ||dS)N) r$rjrirEZ send_queryfilenoZread_query_resultr^r'query)rkrsrrrrss    zConnection.querycCs2ddlm}|dtd|r*|d|S)Nr)warnzRcontext interface will be changed. Use explicit conn.commit() or conn.rollback().rBEGIN)warningsrtDeprecationWarningrprsr()rkrtrrr __enter__&s   zConnection.__enter__cCs|r|n|dS)N)ZrollbackZcommit)rkexcvaluetbrrr__exit__.s zConnection.__exit__cCs,|||j}ts(t|ttfr(t|S|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. )escapercrr$rirjr)rkorrrrliteral4szConnection.literalcCs&ddlm}|dtd|ddS)zExplicitly begin a connection. Non-standard. DEPRECATED: Will be removed in 1.3. Use an SQL BEGIN statement instead.r)rtz2begin() is non-standard and will be removed in 1.4rruN)rvrtrwrs)rkrtrrrbeginFs zConnection.begin warning_countcCs$|}|rt|dSdSdS)zpReturn the number of warnings generated from the last query. This is derived from the info() method.rN)infor.r_)rkrrrrrQszConnection.warning_countcs|dkrd}n|}||krpytt||Wn<tk rn|jdkrTtd|d||YnX||j _ ||j _ ||_ 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.Zutf8mb4utf8)rBr+z server is too old to set charsetz SET NAMES %sN) rer`r2rfAttributeErrorrdr rs store_resultrTr:rOencoding)rkr:Z py_charset)rnrrrfZs  zConnection.set_character_setcCs,|jdkrtd|d||dS)zNSet the connection sql_mode. See MySQL documentation for legal values.)rBr+z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)rdr rsr)rkr=rrrrgos 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.)rBr+rz SHOW WARNINGSr)rdrsrZ fetch_row)rkrrvrrr show_warningsws    zConnection.show_warnings)N)$__name__ __module__ __qualname____doc__rZCursorr[rErarDr(rsrxr|rrhasattrr^r'rrfrgrrrrr rr r r rr r*Z errorhandler __classcell__rr)rnrr2Ks8 =     r2)rresysZMySQLdbrZMySQLdb.compatrrZ_mysql_exceptionsrrrrr r r r r rr^ version_inforangerrr*compiler,r1r'r2rrrrs 0