
    Dh#                     <   d Z ddlZddlmZ ddlmZmZmZmZ ddl	m
Z
mZ ddlmZmZmZmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZmZ dd
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 d Z:d Z;d Z<d Z=d Z>d Z?g dZ@y)z$MySQL X DevAPI Python implementation    N   )	constants)STRING_TYPESurlparseunquote	parse_qsl)XSessionNodeSession)Schema
CollectionTableView)DbDoc)
ErrorWarningInterfaceErrorDatabaseErrorNotSupportedError	DataErrorIntegrityErrorProgrammingErrorOperationalErrorInternalError)ColumnMetaDataRowResultBufferingResult	RowResult	SqlResult
ColumnType)	StatementFilterableStatementSqlStatementFindStatementAddStatementRemoveStatementModifyStatementSelectStatementInsertStatementDeleteStatementUpdateStatementCreateCollectionIndexStatementDropCollectionIndexStatementCreateViewStatementAlterViewStatement	ColumnDefGeneratedColumnDefForeignKeyDefExprc                 "   t        j                  d      }t        j                  d      }t        j                  d      }g }|j                  |       r#| j                  d      } |j	                  |       } n3t        dj                  |             }|j                  |j                  dS | ri }| j                  d      j                         }|j                  |      }|r<|j                  d      j                         }t        |j                  d	            |d	<   t        dj                  |            }|j                  st        d
j                  |            |j                  |d<   |j                  |d<   |j                  |       | rd|iS )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<address>.+)\s*,\s*priority\s*=\s*(?P<priority>\d+)\)$z[]z//{0})hostportr   addresspriorityzInvalid address: {0}r5   r6   routers)recompilematchstripsplitr   formathostnamer6   popgroupintr   append)address_listis_listhst_listpri_addrr9   r<   routerr7   s           O/var/www/html/civilisation/venv/lib/python3.12/site-packages/mysqlx/__init__.py_parse_address_listrK   1   sW    zz/0Gzz,-HzzghHG}}\"#))$/~~l356NNJJ
 	

 ""1%++-w'kk),224G!$U[[%<!=F:01~~ !7!>!>w!GHHvvv   !!    c                 R   ddi}dj                  | j                  d      rdnd|       } | j                  dd      \  }}|j                  d      ddd	   \  }}|j                  d
      ddd	   \  }}|j	                  d      }||d j                  d      du r|dkD  r|j                  dd      \  }|d<   |j                  d      }|r|rd|vrt        dj                  |             |j                  dd      \  |d<   |d<   |j                  d      rt        |      |d<   n6|j                  d      rt        d      |j                  t        |             t        t        |d            j                         D ]&  \  }}	t        |	j                  d            xs d||<   ( |S )a  Parses 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.
    schema z{0}{1}z	mysqlx://z://r   @N   ?/)r   z():zMalformed URI '{0}'userpassword)rS   z...socketz\.zWindows Pipe is not supported.T)r?   
startswithr>   	partitionrfindfindrsplitr=   r   r   updaterK   dictr   items)
urisettingsschemetempuserinfor5   	query_strposoptvals
             rJ   _parse_connection_urirl   \   s    "~H
//{ ;"*C1C99UA&LFD^^C(1-NHdnnS)#A#.OD)
**S/CCDzsr!cAg#';;sA#6 hx ::dDx3h#6299#>??-5^^C-C*HVhz*'($T]		=>>+D129d34::< 9S		$08D9OrL   c                     d| v r| d   r	 t        | d         | d<   d| v r| d   r	 t        | d         | d<   yd| v rd| d<   yy# t        $ r t        d      w xY w# t        $ r t        d      w xY w)a  Validates 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.
    r8   zInvalid priorityr6   zInvalid portr5   i$  N)rC   	NameErrorr   )rd   s    rJ   _validate_settingsro      s     X(:"6	5#&x
';#<HZ  hv.	1"8F#34HV 
8	  
  	5 !344	5  	1 00	1s   A A AA0c                  F   i }| rJt        | d   t              rt        | d         }n;t        | d   t              r(|j	                  | d          n|r|j	                  |       |st        d      d|v r#|j                  d      D ]  }t        |        |S t        |       |S )a  Parses 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.
    r   zSettings not providedr9   )
isinstancer   rl   ra   r`   r   getro   )argskwargsrd   rI   s       rJ   _get_connection_settingsru      s     Hd1g|,,T!W5HQ&OODG$	455Hll9- 	'Fv&	'
 O 	8$OrL   c                  .    t        | i |}t        |      S )a  Creates 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.
    )ru   r	   rs   rt   rd   s      rJ   get_sessionrx      s     (88HHrL   c                  L    t        | i |}d|v rt        d      t        |      S )a  Creates 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.
    r9   z2NodeSession expects only one pair of host and port)ru   r   r
   rw   s      rJ   get_node_sessionrz      s2     (88HHQRRx  rL   ).r	   r
   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   )A__doc__r:   rO   r   compatr   r   r   r   
connectionr	   r
   crudr   r   r   r   dbdocr   errorsr   r   r   r   r   r   r   r   r   r   resultr   r   r   r   r   r   r    	statementr!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   rK   rl   ro   ru   rx   rz   __all__ rL   rJ   <module>r      s   0 + 	  > > - 1 1 H H H, , ,A A A A A A)"V$L!. D"!(rL   