U e#.@sdZddlZddlmZddlmZmZmZmZddl m Z m Z ddl m Z mZmZmZddlmZdd lmZmZmZmZmZmZmZmZmZmZdd lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9d d Z:ddZ;ddZddZ?ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCg.Z@dS)Dz$MySQL X DevAPI Python implementationN) constants) STRING_TYPESurlparseunquote parse_qsl)XSession NodeSession)Schema CollectionTableView)DbDoc) ErrorWarningInterfaceError DatabaseErrorNotSupportedError DataErrorIntegrityErrorProgrammingErrorOperationalError InternalError)ColumnMetaDataRowResultBufferingResult RowResult SqlResult ColumnType) StatementFilterableStatement SqlStatement FindStatement AddStatementRemoveStatementModifyStatementSelectStatementInsertStatementDeleteStatementUpdateStatementCreateCollectionIndexStatementDropCollectionIndexStatementCreateViewStatementAlterViewStatement ColumnDefGeneratedColumnDef ForeignKeyDefExprcCstd}td}td}g}||rB|d}||}ntd|}|j|jdS|ri}| d}||}|r| d}t | d |d <td|}|jst d ||j|d <|j|d <| |q^d |iS)zParses a list of host, port pairs Args: address_list: String containing a list of routers or just router Returns: Returns a dict with parsed values of host, port and priority if specified. z^\[(?![^,]*\]).*]$z,(?![^\(\)]*\))zJ^\(address\s*=\s*(?P
.+)\s*,\s*priority\s*=\s*(?P\d+)\)$z[]z//{0})hostportraddresspriorityzInvalid address: {0}r3r4routers)recompilematchstripsplitrformathostnamer4popgroupintrappend)Z address_listZis_listZhst_listZpri_addrr7r:routerr5rDd/opt/hc_python/lib64/python3.8/site-packages/../../../lib/python3.8/site-packages/mysqlx/__init__.py_parse_address_list1s2          rFc CsTddi}d|drdnd|}|dd\}}|dddd \}}|d ddd \}}|d }||dd d kr|dkr|d d\}|d<|d}|r|rd|krtd||dd\|d<|d<|drt ||d<n$|dr tdn| t |t t |dD]"\}} t | dpFd||<q,|S)aParses the connection string and returns a dictionary with the connection settings. Args: uri: mysqlx URI scheme to connect to a MySQL server/farm. Returns: Returns a dict with parsed values of credentials and address of the MySQL server/farm. Zschemaz{0}{1}z mysqlx://z://r@N?/)rz():zMalformed URI '{0}'userpassword)rKz...socketz\.zWindows Pipe is not supported.T)r= startswithr< partitionrfindfindrsplitr;rrupdaterFdictritems) urisettingsschemetempuserinfor3Z query_strposoptvalrDrDrE_parse_connection_uri\s.      rccCsd|krB|drBzt|d|d<Wntk r@tdYnXd|kr|drzt|d|d<Wqtk rtdYqXnd|krd|d<dS)aValidates the settings to be passed to a Session object the port values are converted to int if specified or set to 33060 otherwise. The priority values for each router is converted to int if specified. Args: settings: dict containing connection settings. r6zInvalid priorityr4z Invalid portr3i$N)rA NameErrorr)r\rDrDrE_validate_settingss recOsi}|rBt|dtr$t|d}qPt|dtrP||dn|rP|||s\tdd|kr~|dD] }t|qnnt||S)aParses the connection string and returns a dictionary with the connection settings. Args: *args: Variable length argument list with the connection data used to connect to the database. It can be a dictionary or a connection string. **kwargs: Arbitrary keyword arguments with connection data used to connect to the database. Returns: mysqlx.XSession: XSession object. rzSettings not providedr7) isinstancerrcrYrXrgetre)argskwargsr\rCrDrDrE_get_connection_settingss  rjcOst||}t|S)aCreates a XSession instance using the provided connection data. Args: *args: Variable length argument list with the connection data used to connect to the database. It can be a dictionary or a connection string. **kwargs: Arbitrary keyword arguments with connection data used to connect to the database. Returns: mysqlx.XSession: XSession object. )rjrrhrir\rDrDrE get_sessions rlcOs"t||}d|krtdt|S)aCreates a NodeSession instance using the provided connection data. Args: *args: Variable length argument list with the connection data used to connect to the database. It can be a dictionary or a connection string. **kwargs: Arbitrary keyword arguments with connection data used to connect to the database. Returns: mysqlx.XSession: XSession object. r7z2NodeSession expects only one pair of host and port)rjrr rkrDrDrEget_node_sessions rmrr rr r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2)A__doc__r8rGrcompatrrrr connectionrr Zcrudr r r r ZdbdocrerrorsrrrrrrrrrrresultrrrrrrrZ statementr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2rFrcrerjrlrm__all__rDrDrDrEs|  0$T +&"