U Yzf_b@sdZddlmZmZmZddlZddlZddlZdZz ddl Z e e drRe j rRdZWn YnXddl m Z mZmZdd lmZdd lmZmZmZmZmZmZmZdd lmZdd lmZeZd Z dZ!dZ"e eGddde#Z$e eGddde#Z%dS)z*Module gathering all abstract base classes)ABCMetaabstractmethodabstractpropertyNF HAS_TLSv1_3T)make_abc BYTE_TYPES STRING_TYPES)MySQLConverterBase) ClientFlag CharacterSet CONN_ATTRS_DNDEFAULT_CONFIGURATIONOPENSSL_CS_NAMESTLS_CIPHER_SUITES TLS_VERSIONS)MySQLOptionsParser)errorszVThe '{list}' list must not contain repeated values, the value '{value}' is duplicated.zdThe given tls_version: '{}' is not recognized as a valid TLS protocol version (should be one of {}).zINo supported TLS protocol version found in the 'tls-versions' list '{}'. c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ e ddZ e ddZ e ddZe ddZeddZejddZe ddZddZdd Zd!d"Zd#d$Zd%d&Zed'd(Zd)d*Zd+d,Ze d-d.Zejd/d.Ze d0d1Zejd2d1Zed3d4Zdd6d7Z dd9d:Z!e d;d<Z"e"jd=d<Z"e d>d?Z#e#jd@d?Z#e dAdBZ$e$jdCdBZ$e dDdEZ%e%jdFdEZ%e dGdHZ&e dIdJZ'ddKdLZ(e dMdNZ)edOdPZ*edQdRZ+dSdTZ,edUdVZ-e-Z.dWdXZ/dd[d\Z0ed]d^Z1edd`daZ2edbdcZ3eddddeZ4edfdgZ5edhdiZ6ddjdkZ7ddldmZ8dndoZ9eddpdqZ:drdsZ;ddtduZdzd{Z?dd|d}Z@d~dZAddZBddZCddZDddZEdddZFddZGdddZHddZIddZJddZKddZLd5S)MySQLConnectionAbstractz7Abstract class for classes connecting to a MySQL servercKst|_d|_d|_d|_d|_d|_d|_i|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_i|_td|_d|_d |_d|_d|_td |_d|_d|_d|_d|_d|_d|_d|_ d|_!d|_"d|_#d|_$d|_%d|_&dS) Z Initialize-NFz 127.0.0.1i r ssl_disabledTconnect_timeout)'r get_default _client_flags _charset_id _sql_mode _time_zone _autocommit_server_version _handshake _conn_attrs_user _password _database_host_port _unix_socketZ _client_hostZ _client_port_sslr _ssl_disabledZ _force_ipv6 _use_unicode _get_warnings_raise_on_warningsZ_connection_timeoutZ _buffered_unread_resultZ_have_next_result_rawZ_in_transactionZ_prepared_statementsZ _ssl_active _auth_pluginZ_pool_config_version converter_converter_class _compress_consume_resultsselfkwargsr7q/private/var/folders/n9/53xbvtmd7sjg1q1l55xmpg58n4mgng/T/pip-unpacked-wheel-47tvuv7y/mysql/connector/abstracts.py__init__FsH   z MySQLConnectionAbstract.__init__cCs|SNr7r5r7r7r8 __enter__rsz!MySQLConnectionAbstract.__enter__cCs |dSr:closer5exc_type exc_value tracebackr7r7r8__exit__usz MySQLConnectionAbstract.__exit__cCs|S)zReturn self for weakref.proxy This method is used when the original object is needed when using weakref.proxy. r7r;r7r7r8 _get_selfxsz!MySQLConnectionAbstract._get_selfc Csd|krz.t|dtr(|dg|d<|d}|d=Wntk rTddg}YnXt|dtrr|dg|d<tt|ddd}|d=|j|}i}|D]}z||D]t\}}z<|dkrd}t|||ks||d |d kr|||<Wqtk r"|dkrtd |YqXqWqtk rBYqYqXq|D]P\}}||krNzt |d ||<Wn&t t fk r|d ||<YnXqN|S) z Read option files for connection parameters. Checks if connection arguments contain option file arguments, and then reads option files accordingly. option_files option_groupsclientZconnector_pythonF)Z keep_dashessocket unix_socketrUnsupported argument '{0}'r) isinstancestrKeyErrorrlistZ get_groups_as_dict_with_priorityitemsrAttributeErrorformateval NameError SyntaxError) r5configgroupsZ option_parserZconfig_from_fileZconfig_optionsgroupoptionvaluer7r7r8_read_option_filessV       z*MySQLConnectionAbstract._read_option_filesc Csbg}|jd}t|tr|dr,|dsszFMySQLConnectionAbstract._validate_tls_ciphersuites..zLtls_ciphersuites should be a list with one or more ciphersuites. Found: '{}' tls_versionsNT)reverser-TLSv1.3rNrYz>The value '{}' in tls_ciphersuites is not a valid cipher suitez;No valid cipher suite found in the 'tls_ciphersuites' list.:)r(rKr startswithendswithrPrQsplitstripupperappendrNsetgetrsortindexupdaterextendrDUPLICATED_IN_LIST_ERRORjoin) r5r[raZtls_cssZ_tls_csrcZ newer_tls_verZtranslated_namesZiani_cipher_suites_namesZossl_cipher_suites_namestls_vernameZtranslated_namer7r7r8_validate_tls_ciphersuitess            z2MySQLConnectionAbstract._validate_tls_ciphersuitescCsg}|jd}t|tr|dr,|ds.r)rz%MySQL Version '{0}' is not supported.) rKrdecoderecompilematchrrtuplerVrQ)r5Zserver_versionZ regex_verrversionr7r7r8_check_server_versionTs    z-MySQLConnectionAbstract._check_server_versioncCs|jS)zGet the MySQL version This method returns the MySQL server version as a tuple. If not previously connected, it will return None. Returns a tuple or None. )rr;r7r7r8get_server_versionpsz*MySQLConnectionAbstract.get_server_versionc Cs,z |jdWSttfk r&YdSXdS)zGet the original MySQL version information This method returns the original MySQL server as text. If not previously connected, it will return None. Returns a string or None. Zserver_version_originalN)r rrMr;r7r7r8get_server_infozs z'MySQLConnectionAbstract.get_server_infocCsdS)z'MySQL session has started a transactionNr7r;r7r7r8in_transactionsz&MySQLConnectionAbstract.in_transactioncCspt|tr|dkr||_nPt|ttfr`|D]0}|dkrN|jt|M_q,|j|O_q,n td|jS)aSet the client flags The flags-argument can be either an int or a list (or tuple) of ClientFlag-values. If it is an integer, it will set client_flags to flags as is. If flags is a list (or tuple), each flag will be set or unset when it's negative. set_client_flags([ClientFlag.FOUND_ROWS,-ClientFlag.LONG_FLAG]) Raises ProgrammingError when the flags argument is not a set or an integer bigger than 0. Returns self.client_flags rz+set_client_flags expect integer (>0) or set)rKrrrrNabsrProgrammingError)r5flagsflagr7r7r8rsz(MySQLConnectionAbstract.set_client_flagscCs|j|@dkrdSdS)zCheck if a client flag is setrTF)r)r5rr7r7r8isset_client_flagsz)MySQLConnectionAbstract.isset_client_flagcCs|ddS)zGet the current time zonezSELECT @@session.time_zoner info_queryr;r7r7r8 time_zonesz!MySQLConnectionAbstract.time_zonecCs|d|||_dS)zSet the time zonezSET @@session.time_zone = '{0}'N)rrQrrr7r7r8rscCs|ddS)zGet the SQL modezSELECT @@session.sql_moderrr;r7r7r8sql_modesz MySQLConnectionAbstract.sql_modecCs2t|ttfrd|}|d|||_dS)aSet the SQL mode This method sets the SQL Mode for the current connection. The value argument can be either a string with comma separate mode names, or a sequence of mode names. It is good practice to use the constants class SQLMode: from mysql.connector.constants import SQLMode cnx.sql_mode = [SQLMode.NO_ZERO_DATE, SQLMode.REAL_AS_FLOAT] r_zSET @@session.sql_mode = '{0}'N)rKrNrrvrrQrrr7r7r8rs  cCsdS)z%Send a query which only returns 1 rowNr7r5queryr7r7r8rsz"MySQLConnectionAbstract.info_queryNcCs4|dk r||_nd|_|dk r*||_nd|_dS)zSet login information for MySQL Set the username and/or password for the user connecting to the MySQL Server. Nr)rlr"r#)r5rrr7r7r8rs  z!MySQLConnectionAbstract.set_loginTcCs||_|jr|j|dS)zuToggle unicode mode Set whether we return string fields as unicode or not. Default is True. N)r*r0 set_unicoderr7r7r8rsz#MySQLConnectionAbstract.set_unicodecCs|dd}|dkrdSdS)z#Get whether autocommit is on or offzSELECT @@session.autocommitrrTFrrr7r7r8 autocommitsz"MySQLConnectionAbstract.autocommitcCs&|rdnd}|d|||_dS)zToggle autocommitONZOFFzSET @@session.autocommit = {0}N)rrQr)r5rYswitchr7r7r8rs cCs|jS)zGet whether this connection retrieves warnings automatically This method returns whether this connection retrieves warnings automatically. Returns True, or False when warnings are not retrieved. )r+r;r7r7r8rs z$MySQLConnectionAbstract.get_warningscCst|tstd||_dS)zSet whether warnings should be automatically retrieved The toggle-argument must be a boolean. When True, cursors for this connection will retrieve information about warnings (if any). Raises ValueError on error. Expected a boolean typeN)rKrrr+rr7r7r8rs cCs|jS)zGet whether this connection raises an error on warnings This method returns whether this connection will raise errors when MySQL reports warnings. Returns True or False. )r,r;r7r7r8rs z)MySQLConnectionAbstract.raise_on_warningscCs"t|tstd||_||_dS)aSet whether warnings raise an error The toggle-argument must be a boolean. When True, cursors for this connection will raise an error when MySQL reports warnings. Raising on warnings implies retrieving warnings automatically. In other words: warnings will be set to True. If set to False, warnings will be also set to False. Raises ValueError on error. rN)rKrrr,r+rr7r7r8rs cCs|jS)zGet whether there is an unread result This method is used by cursors to check whether another cursor still needs to retrieve its result set. Returns True, or False when there is no unread result. )r-r;r7r7r8 unread_result1s z%MySQLConnectionAbstract.unread_resultcCst|tstd||_dS)zSet whether there is an unread result This method is used by cursors to let other cursors know there is still a result set that needs to be retrieved. Raises ValueError on errors. rN)rKrrr-rr7r7r8r<s cCst|jdS)a+Returns the character set for current connection This property returns the character set name of the current connection. The server is queried when the connection is active. If not connected, the configured character set name is returned. Returns a string. rr get_inforr;r7r7r8rIs zMySQLConnectionAbstract.charsetcCs t|jd}|dkrdS|S)ayReturns the Python character set for current connection This property returns the character set name of the current connection. Note that, unlike property charset, this checks if the previously set character set is supported by Python and if not, it returns the equivalent character set that Python supports. Returns a string. r)Zutf8mb4binaryutf8r)r5encodingr7r7r8python_charsetUs z&MySQLConnectionAbstract.python_charsetcCs|rLt|tr"t|\|_}}qdt|trBt||\|_}}qdtdn|rdtj|d\|_}}|d||z| |Wnt k rYnX|j r|j |dS)aVSets the character set and collation for the current connection This method sets the character set and collation to be used for the current connection. The charset argument can be either the name of a character set as a string, or the numerical equivalent as defined in constants.CharacterSet. When the collation is not given, the default will be looked up and used. For example, the following will set the collation for the latin1 character set to latin1_general_ci: set_charset('latin1','latin1_general_ci') z0charset should be either integer, string or None)rzSET NAMES '{0}' COLLATE '{1}'N) rKrr rrrLr_execute_queryrQZset_character_set_namerPr0 set_charset)r5rr charset_nameZcollation_namer7r7r8set_charset_collationes.     z-MySQLConnectionAbstract.set_charset_collationcCst|jdS)aReturns the collation for current connection This property returns the collation name of the current connection. The server is queried when the connection is active. If not connected, the configured collation name is returned. Returns a string. )r rrr;r7r7r8rs z!MySQLConnectionAbstract.collationcCsdS)z>> cnx = mysql.connector.connect(..) >>> cnx.start_transaction(isolation_level='SERIALIZABLE') Raises ProgrammingError when a transaction is already in progress and when ValueError when isolation_level specifies an Unknown level. zTransaction already in progressre zREAD UNCOMMITTEDzREAD COMMITTEDzREPEATABLE READZ SERIALIZABLEzUnknown isolation level "{0}"z#SET TRANSACTION ISOLATION LEVEL {0}N)rz6MySQL server version {0} does not support this featurez READ ONLYz READ WRITEzSET TRANSACTION {0}zSTART TRANSACTIONz WITH CONSISTENT SNAPSHOT) rrrrlrrmrrQrrr)r5Zconsistent_snapshotZisolation_levelreadonlylevellevelsZ access_moderr7r7r8start_transactions>  z)MySQLConnectionAbstract.start_transactionc Cs|stdz |WnDtjtfk rb|jrFtdn||j|j |j |j YnX|sl|r| }|r| D]\}}|d||fq|r| D]\}}|d||fq|dS)aClears the current active session This method resets the session state, if the MySQL server is 5.7.3 or later active session will be reset without re-authenticating. For other server versions session will be reset by re-authenticating. It is possible to provide a sequence of variables and their values to be set after clearing the session. This is possible for both user defined variables and session variables. This method takes two arguments user_variables and session_variables which are dictionaries. Raises OperationalError if not connected, InternalError if there are unread results and InterfaceError on errors. zMySQL Connection not available.zZReset session is not supported with compression for MySQL server version 5.7.2 or earlier.zSET @`{0}` = %szSET SESSION `{0}` = %sN)rrZOperationalErrorcmd_reset_connectionrNotImplementedErrorr2cmd_change_userr"r#r$rrrOexecuterQr>)r5Zuser_variablesZsession_variablescurrrYr7r7r8 reset_session<s,    z%MySQLConnectionAbstract.reset_sessioncCs@|r4t|tr4t|jd}||_|||j|_ntddS)z Set the converter class to be used. This should be a class overloading methods and members of conversion.MySQLConverter. rrN) issubclassr r rrr1r*r0r)r5Z convclassrr7r7r8rds z+MySQLConnectionAbstract.set_converter_classcCsdS)z)Get all rows returned by the MySQL serverNr7)r5countrcolumnsrZ prep_stmtr7r7r8get_rowsqsz MySQLConnectionAbstract.get_rowscCstdS)zChange the current databaseNr)r5rr7r7r8 cmd_init_dbwsz#MySQLConnectionAbstract.cmd_init_dbcCstdS)z Send a query to the MySQL serverNr)r5rrrZ raw_as_stringr7r7r8r{sz!MySQLConnectionAbstract.cmd_querycCstdS)z/Send one or more statements to the MySQL serverNr)r5Z statementsr7r7r8cmd_query_itersz&MySQLConnectionAbstract.cmd_query_itercCstdS)z,Send the Refresh command to the MySQL serverNr)r5optionsr7r7r8 cmd_refreshsz#MySQLConnectionAbstract.cmd_refreshcCstdS)z,Close the current connection with the serverNrr;r7r7r8cmd_quitsz MySQLConnectionAbstract.cmd_quitcCstdS)zShut down the MySQL ServerNr)r5Z shutdown_typer7r7r8 cmd_shutdownsz$MySQLConnectionAbstract.cmd_shutdowncCstdS)z/Send the statistics command to the MySQL ServerNrr;r7r7r8cmd_statisticssz&MySQLConnectionAbstract.cmd_statisticscCstddS)akGet the process list of the MySQL Server This method is a placeholder to notify that the PROCESS_INFO command is not supported by raising the NotSupportedError. The command "SHOW PROCESSLIST" should be send using the cmd_query()-method or using the INFORMATION_SCHEMA database. Raises NotSupportedError exception z;Not implemented. Use SHOW PROCESSLIST or INFORMATION_SCHEMAN)rrr;r7r7r8cmd_process_infos z(MySQLConnectionAbstract.cmd_process_infocCstdS)zKill a MySQL processNr)r5Z mysql_pidr7r7r8cmd_process_killsz(MySQLConnectionAbstract.cmd_process_killcCstdS)zSend the DEBUG commandNrr;r7r7r8 cmd_debugsz!MySQLConnectionAbstract.cmd_debugcCstdS)zSend the PING commandNrr;r7r7r8cmd_pingsz MySQLConnectionAbstract.cmd_pingrrcCstdS)z!Change the current logged in userNr)r5rrrrr7r7r8rsz'MySQLConnectionAbstract.cmd_change_usercCstdS)zPrepare a MySQL statementNr)r5Z statementr7r7r8cmd_stmt_preparesz(MySQLConnectionAbstract.cmd_stmt_preparer7cCstdS)z"Execute a prepared MySQL statementNr)r5 statement_iddata parametersrr7r7r8cmd_stmt_executesz(MySQLConnectionAbstract.cmd_stmt_executecCstdS)z%Deallocate a prepared MySQL statementNrr5r r7r7r8cmd_stmt_closesz&MySQLConnectionAbstract.cmd_stmt_closecCstdS)zSend data for a columnNr)r5r Zparam_idrr7r7r8cmd_stmt_send_long_datasz/MySQLConnectionAbstract.cmd_stmt_send_long_datacCstdS)z3Reset data for prepared statement sent as long dataNrrr7r7r8cmd_stmt_resetsz&MySQLConnectionAbstract.cmd_stmt_resetcCstdS)z2Resets the session state without re-authenticatingNrr;r7r7r8rsz,MySQLConnectionAbstract.cmd_reset_connection)NN)T)NN)rr)Frr)NNNNNN)FNN)NN)NFNNN)FFF)N)rrrr)r7r7r)M__name__ __module__ __qualname____doc__r9r<rCrDrZryr}propertyr~rrrIrrsetterrrUrrrrrrrrrrrrrrrrrrrrrrrrrr>rrrrrrrrrrrrrrrrrrrrr r r rr rrrrrr7r7r7r8rAs,5R?       h                     ,            4 (       rc@seZdZdZddZddZddZed+d d Zed d Z ed,ddZ eddZ eddZ ed-ddZ eddZddZddZd.ddZd/d!d"Zed#d$Zed%d&Zed'd(Zd)d*ZdS)0MySQLCursorAbstractzAbstract cursor class Abstract class defining cursor class with method and members required by the Python Database API Specification v2.0. cCs"d|_d|_d|_d|_d|_dS)ZInitializationNr^r) _description _rowcount_last_insert_id _warningsZ arraysizer;r7r7r8r9s zMySQLCursorAbstract.__init__cCs|Sr:r7r;r7r7r8r<szMySQLCursorAbstract.__enter__cCs |dSr:r=r?r7r7r8rCszMySQLCursorAbstract.__exit__r7cCsdS)aCalls a stored procedure with the given arguments The arguments will be set during this session, meaning they will be called like ___arg where is an enumeration (+1) of the arguments. Coding Example: 1) Defining the Stored Routine in MySQL: CREATE PROCEDURE multiply(IN pFac1 INT, IN pFac2 INT, OUT pProd INT) BEGIN SET pProd := pFac1 * pFac2; END 2) Executing in Python: args = (5,5,0) # 0 is to hold pprod cursor.callproc('multiply', args) print(cursor.fetchone()) Does not return a value, but a result set will be available when the CALL-statement execute successfully. Raises exceptions when something is wrong. Nr7)r5Zprocnameargsr7r7r8callprocszMySQLCursorAbstract.callproccCsdS)zClose the cursor.Nr7r;r7r7r8r>szMySQLCursorAbstract.closeFcCsdS)aExecutes the given operation Executes the given operation substituting any markers with the given parameters. For example, getting all rows where id is 5: cursor.execute("SELECT * FROM t1 WHERE id = %s", (5,)) The multi argument should be set to True when executing multiple statements in one operation. If not set and multiple results are found, an InterfaceError will be raised. If warnings where generated, and connection.get_warnings is True, then self._warnings will be a list containing these warnings. Returns an iterator when multi is True, otherwise None. Nr7)r5 operationparamsZmultir7r7r8rszMySQLCursorAbstract.executecCsdS)aExecute the given operation multiple times The executemany() method will execute the operation iterating over the list of parameters in seq_params. Example: Inserting 3 new employees and their phone number data = [ ('Jane','555-001'), ('Joe', '555-001'), ('John', '555-003') ] stmt = "INSERT INTO employees (name, phone) VALUES ('%s','%s')" cursor.executemany(stmt, data) INSERT statements are optimized by batching the data, that is using the MySQL multiple rows syntax. Results are discarded. If they are needed, consider looping over data using the execute() method. Nr7)r5r"Z seq_paramsr7r7r8 executemanyszMySQLCursorAbstract.executemanycCsdS)zQReturns next row of a query result set Returns a tuple or None. Nr7r;r7r7r8fetchone,szMySQLCursorAbstract.fetchonercCsdS)a Returns the next set of rows of a query result, returning a list of tuples. When no more rows are available, it returns an empty list. The number of rows returned can be specified using the size argument, which defaults to one Nr7)r5sizer7r7r8 fetchmany4s zMySQLCursorAbstract.fetchmanycCsdS)zRReturns all rows of a query result set Returns a list of tuples. Nr7r;r7r7r8fetchall?szMySQLCursorAbstract.fetchallcCsdSzNot Implemented.Nr7r;r7r7r8nextsetGszMySQLCursorAbstract.nextsetcCsdSr)r7)r5sizesr7r7r8 setinputsizesKsz!MySQLCursorAbstract.setinputsizesNcCsdSr)r7)r5r&columnr7r7r8 setoutputsizeOsz!MySQLCursorAbstract.setoutputsizeTcCsdS)zReset the cursor to defaultNr7)r5freer7r7r8resetSszMySQLCursorAbstract.resetcCs|jS)aReturns description of columns in a result This property returns a list of tuples describing the columns in in a result set. A tuple is described as follows:: (column_name, type, None, None, None, None, null_ok, column_flags) # Addition to PEP-249 specs Returns a list of tuples. )rr;r7r7r8 descriptionWszMySQLCursorAbstract.descriptioncCs|jS)aReturns the number of rows produced or affected This property returns the number of rows produced by queries such as a SELECT, or affected rows when executing DML statements like INSERT or UPDATE. Note that for non-buffered cursors it is impossible to know the number of rows produced before having fetched them all. For those, the number of rows will be -1 right after execution, and incremented when fetching rows. Returns an integer. )rr;r7r7r8rowcountkszMySQLCursorAbstract.rowcountcCs|jS)aReturns the value generated for an AUTO_INCREMENT column Returns the value generated for an AUTO_INCREMENT column by the previous INSERT or UPDATE statement or None when there is no such value available. Returns a long value or None. )rr;r7r7r8 lastrowid|s zMySQLCursorAbstract.lastrowidcCs|jS)zReturns Warnings.)rr;r7r7r8 fetchwarningssz!MySQLCursorAbstract.fetchwarnings)r7)r7F)r)N)T)rrrrr9r<rCrr!r>rr$r%r'r(r*r,r.r0rr1r2r3r4r7r7r7r8rs:            r)&rabcrrrrrweakrefr{sslhasattrrZcatch23rrr conversionr constantsr r r rrrrZ optionfilesrrrWeakValueDictionaryZNAMED_TUPLE_CACHErurzr|objectrrr7r7r7r8sD $