o
    FDis                     @   s   U 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 dZe
je
je
jhZee ed< e	je	jhZee ed< h d	Zee ed
< G dd deZdedeeef fddZdS )    N)Any)ParseResultparse_qsunquoteurlparse)ClickhouseSchemeCompressionAlgorithm)asboolz://_COMPRESSION_ALGORITHMS_SUPPORTED_SCHEMES>   connect_timeoutsend_receive_timeoutsync_request_timeout	_TIMEOUTSc                   @   s   e Zd ZdS )DSNErrorN)__name__
__module____qualname__ r   r   O/var/www/Datamplify/venv/lib/python3.10/site-packages/asynch/proto/utils/dsn.pyr      s    r   dsnreturnc                 C   s   |  t\}}}|sd|  }t||tvr#d|dt }t||s.d|  }t|i }i }t| |d}|jrBt|j|d< |jrLt|j|d< |jrVt|j|d< |j	r^|j	|d	< |j
d
dd}|rl||d< |jtjkrvd|d< t|j D ]z\}	}
|
sq}|
d }
|	dkr|
 }
|
tv r|
||	< q}t|
||	< q}|	dkrt|
||	< q}|	dkr|
||	< q}|	tv rt|
||	< q}|	dkrt|
||	< q}|	dkrt|
||	< q}|	dkrtt|
||	< q}|	dv r|
||	< q}|	dkr|
|d< q}|
||	< q}|r||d< |S )a  Return the client configuration from the given URL.

    The following URL schemes are supported:
    - clickhouse:// - creates a normal TCP socket
    - clickhouses:// - creates an SSL wrapped TCP socket

    Examples::
    - clickhouse://[user:password]@localhost:9000/default
    - clickhouses://[user:password]@localhost:9440/default

    :param dsn str: the DSN string

    :raises DSNError: when parsing fails under the strict mode

    :return: the dictionary of DSN string components
    :rtype: dict[str, Any]
    z!no valid scheme separator in the zthe scheme z is not in z)nothing to parse after the scheme in the )schemeuserpasswordhostport/    databaseTsecurer   compressionclient_namecompress_block_sizeverifyssl_version)ca_certsciphers	alt_hostssettings)	partition_SCHEME_SEPARATORr   r   r   usernamer   r   hostnamer   pathreplacer   r   clickhousesr   queryitemslowerr
   r	   r   floatintgetattrssl)r   r   seprestmsgr*   kwargsurlr/   namevaluer   r   r   	parse_dsn   sn   







r@   )r8   typingr   urllib.parser   r   r   r   asynch.proto.models.enumsr   r   asynch.proto.utils.compatr	   r,   lz4lz4hczstdr
   setstr__annotations__
clickhouser1   r   r   	Exceptionr   dictr@   r   r   r   r   <module>   s   
 