a Ž1P]¯/ã@sŒdZddlZddlZddlmZmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZmZe d¡Zdd„ZGd d „d ejƒZdS) 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+)cCs t |¡}|rt| d¡ƒSdS)zšReturns 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ú5/usr/lib/python3/dist-packages/MySQLdb/connections.pyÚ numeric_parts rcs¸eZdZdZejZ‡fdd„Zdd„Zddd„Z d d „Z d d „Z d d„Z dd„Z dd„Zeejdƒsldd„Z‡fdd„Zdd„Zdd„ZeZeZeZeZeZeZeZeZeZeZ‡Z S)Ú Connectionz MySQL Database Connection Objectcsªddlm}m}ddlm}m}ddlm}| ¡}d|vrJ|  d¡|d<d|vr`|  d¡|d<d |vrr|d } n|} i} |   ¡D]6\} } t | t ƒr°t | t ƒr°| d d …| | <q‚| | | <q‚| |d <|  d |j¡} | d d ¡}|sätsêd}nd}|  d|¡}|  dd ¡}|  dd¡|_| dd¡}tdd„t ¡ d¡d d…Dƒƒ}|dkrX||jO}|dkrl||jO}||d<|  dd¡}tt|ƒj|i|¤Ž| |_tdd„|   ¡Dƒƒ|_t|jt<tdd„| ¡ d¡d d…Dƒƒ|_ d|_!||ƒ‰d ‡fdd„ }|s| "¡}| #|¡|r(| $|¡|rl|j%|j&|j'|j(|j)|j*|j+fD]}||j,|<qNt-|j,|j.<||jt-<|j/|j0@|_1|j1r |d ur | 2|¡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 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)ÚproxyZdatabaseÚdbZpasswordZpasswdÚconvNÚ cursorclassÚcharsetÚTFÚ use_unicodeÚsql_modeZ binary_prefixÚ client_flagcSsg|] }t|ƒ‘qSr©r©Ú.0ÚnrrrÚ ›óz'Connection.__init__..Ú.é©ér)érÚ autocommitcSs$g|]\}}t|ƒtur||f‘qSr)Útyper)r*ÚkÚvrrrr,¨s  ÿcSsg|] }t|ƒ‘qSrr(r)rrrr,²r-Úasciicsˆ | ˆj¡¡S©N)Ústring_literalÚencodeÚencoding)ÚuZdummy©r rrÚunicode_literal·sz,Connection.__init__..unicode_literal)N)4ZMySQLdb.constantsrrZMySQLdb.convertersrrÚweakrefrÚcopyÚpopÚitemsÚ isinstancerÚlistÚdefault_cursorÚgetrÚ_binary_prefixÚtuplerZget_client_infoÚsplitZMULTI_STATEMENTSZ MULTI_RESULTSÚsuperrÚ__init__r"ÚdictÚencodersÚbytesZget_server_infoÚ_server_versionr;Úcharacter_set_nameÚset_character_setÚ set_sql_modeÚSTRINGZ VAR_STRINGZVARCHARZ TINY_BLOBZ MEDIUM_BLOBZ LONG_BLOBZBLOBZ converterrZJSONZserver_capabilitiesZ TRANSACTIONSZ_transactionalr3Zmessages)ÚselfÚargsÚkwargsrrrrrZkwargs2r!Zconv2r5r6r"r#r%r&r'Zclient_versionr3r>Út©Ú __class__r=rrK*stL       $      &   ÿ    zConnection.__init__cCs&t|ƒ}| ¡|kr"tj ||¡dSr8)ÚboolZget_autocommitrÚ connectionr3)rTZonrrrr3Ðs 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")rTr"rrrÚcursorÕszConnection.cursorcCs$t|tƒrt|ƒ}tj ||¡dSr8)rCÚ bytearrayrNrr[Úquery)rTr^rrrr^Þs zConnection.querycCs.t|ttfƒsJ‚| |¡}|jr*d|S|S)Ns_binary)rCrNr]r9rG)rTZbsÚxrrrÚ_bytes_literaläs  zConnection._bytes_literalcCsdd t|j|ƒ¡S)Ns(%s)ó,)ÚjoinÚmapÚliteral)rTrWrrrÚ_tuple_literalëszConnection._tuple_literalcCsªt|tƒr| | |j¡¡}nzt|tƒr4| |¡}ndt|tƒrZtrN| |¡}q˜| |¡}n>t|t t fƒrt|  |¡}n$|  ||j ¡}t|tƒr˜| |j¡}t|tƒs¦J‚|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. )rCrr9r:r;r]r`rNrrHrDreÚescaperM)rTÚorrrrrdîs         zConnection.literalcCs| d¡dS)ziExplicitly begin a connection. This method is not used when autocommit=False (default). sBEGINN)r^)rTrrrÚbeginszConnection.beginÚ warning_countcCs$| ¡}|rt| ¡dƒSdSdS)zpReturn the number of warnings generated from the last query. This is derived from the info() method.éÿÿÿÿrN)ÚinforrI)rTrkrrrriszConnection.warning_countcsx|dvrd}n|}| ¡|krnztt|ƒ |¡Wn:tyl|jdkrRtdƒ‚| d|¡| ¡Yn0||_ dS)z÷Set 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.)Zutf8mb4Zutf8mb3Úutf8r0z server is too old to set charsetz SET NAMES %sN) rPrJrrQÚAttributeErrorrOrr^Ú store_resultr;)rTr#Z py_charsetrXrrrQs   zConnection.set_character_setcCs,|jdkrtdƒ‚| d|¡| ¡dS)zNSet the connection sql_mode. See MySQL documentation for legal values.r0z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)rOrr^rn)rTr&rrrrR-s zConnection.set_sql_modecCs.|jdkrdS| d¡| ¡}| d¡}|S)zæReturn 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.r0rz SHOW WARNINGSr)rOr^rnZ fetch_row)rTÚrÚwarningsrrrÚ show_warnings5s   zConnection.show_warnings)N)!Ú__name__Ú __module__Ú __qualname__Ú__doc__rZCursorrErKr3r\r^r`rerdrhÚhasattrrr[rirQrRrqrrrr r r r r rrÚ __classcell__rrrXrr%s4 '    r)ruÚreÚsysZMySQLdbrrZMySQLdb.compatrrZMySQLdb._exceptionsrrrr r r r r rrÚcompilerrr[rrrrrÚs0