o
    [h$                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ dd	lm	Z	 G d
d de
Zdd Zdd Zdd Zdd Zdd ZdS )a  Provides the :class:`~sqlalchemy.engine.url.URL` class which encapsulates
information about a database connection specification.

The URL object is created automatically when
:func:`~sqlalchemy.engine.create_engine` is called with a string
argument; alternatively, the URL is a public-facing construct which can
be used directly and is also accepted directly by ``create_engine()``.
    N   )Dialect   )exc)util)plugins)registryc                   @   s   e Zd ZdZ						d!ddZd"ddZdd	 Zd
d Zdd Zdd Z	dd Z
edd Zejdd Zdd Zdd Zdd Zdd Zdd Zg fdd ZdS )#URLaX  
    Represent the components of a URL used to connect to a database.

    This object is suitable to be passed directly to a
    :func:`~sqlalchemy.create_engine` call.  The fields of the URL are parsed
    from a string by the :func:`.make_url` function.  The string
    format of the URL is an RFC-1738-style string.

    All initialization parameters are available as public attributes.

    :param drivername: the name of the database backend.
      This name will correspond to a module in sqlalchemy/databases
      or a third party plug-in.

    :param username: The user name.

    :param password: database password.

    :param host: The name of the host.

    :param port: The port number.

    :param database: The database name.

    :param query: A dictionary of options to be passed to the
      dialect and/or the DBAPI upon connect.

    Nc                 C   sF   || _ || _|| _|| _|d urt|| _nd | _|| _|pi | _d S N)
drivernameusernamepassword_originalhostintportdatabasequery)selfr   r   passwordr   r   r   r    r   |/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/sqlalchemy/engine/url.py__init__8   s   
zURL.__init__Tc                    s    j d } jd ur'|t j7 } jd ur#|d|rdnt j 7 }|d7 } jd ur>d jv r9|d j 7 }n| j7 } jd urL|dt j 7 } jd urX|d j 7 } jrtt	 j}|
  |dd fd	d
|D  7 }|S )Nz://:z***@z[%s]/?&c                 3   s>    | ]}t  j| D ]}d t |t |f V  qqdS )z%s=%sN)r   to_listr   
quote_plus).0kelementr   r   r   	<genexpr>b   s    z$URL.__to_string__.<locals>.<genexpr>)r   r   _rfc_1738_quoter   r   r   strr   r   listsortjoin)r   hide_passwordskeysr   r"   r   __to_string__M   s.   








zURL.__to_string__c                 C   s   | j ddS )NF)r)   r,   r"   r   r   r   __str__i      zURL.__str__c                 C   s   |   S r
   r-   r"   r   r   r   __repr__l   s   zURL.__repr__c                 C   s   t t| S r
   )hashr%   r"   r   r   r   __hash__o   r/   zURL.__hash__c                 C   s^   t |to.| j|jko.| j|jko.| j|jko.| j|jko.| j|jko.| j|jko.| j|jkS r
   )	
isinstancer	   r   r   r   r   r   r   r   r   otherr   r   r   __eq__r   s   







z
URL.__eq__c                 C   s
   | |k S r
   r   r4   r   r   r   __ne__~      
z
URL.__ne__c                 C   s   | j d u rd S t| j S r
   )r   r   	text_typer"   r   r   r   r      s   
zURL.passwordc                 C   s
   || _ d S r
   )r   )r   r   r   r   r   r      s   
c                 C   s    d| j vr| j S | j dd S )N+r   )r   splitr"   r   r   r   get_backend_name   s   
zURL.get_backend_namec                 C   s$   d| j vr
|  jS | j dd S )Nr:   r   )r   get_dialectZdriverr;   r"   r   r   r   get_driver_name   s   

zURL.get_driver_namec                    s8   t jdd}| dg 7 } fdd|D S )Npluginr   r   c                    s   g | ]
}t | qS r   )r   load)r   Zplugin_namekwargsr   r   r   
<listcomp>   s    z,URL._instantiate_plugins.<locals>.<listcomp>)r   r   r   get)r   rB   Zplugin_namesr   rA   r   _instantiate_plugins   s
   zURL._instantiate_pluginsc                 C   sV   d| j vr	| j }n| j dd}t|}t|dr)t|jtr)t|jt	r)|jS |S )zReturn the "entry point" dialect class.

        This is normally the dialect itself except in the case when the
        returned class implements the get_dialect_cls() method.

        r:   .dialect)
r   replacer   r@   hasattrr3   rG   type
issubclassr   )r   nameclsr   r   r   _get_entrypoint   s   



zURL._get_entrypointc                 C   s   |   }|| }|S )zfReturn the SQLAlchemy database dialect class corresponding
        to this URL's driver name.
        )rN   Zget_dialect_cls)r   
entrypointZdialect_clsr   r   r   r=      s   
zURL.get_dialectc                 K   sb   i }g d}|D ]&}|r| d}n||v r|| }n|}|dur.t| |dr.t| |||< q|S )a2  Translate url attributes into a dictionary of connection arguments.

        Returns attributes of this url (`host`, `database`, `username`,
        `password`, `port`) as a plain dictionary.  The attribute names are
        used as the keys by default.  Unset or false attributes are omitted
        from the final dictionary.

        :param \**kw: Optional, alternate key names for url attributes.

        :param names: Deprecated.  Same purpose as the keyword-based alternate
            names, but correlates the name to the original positionally.
        )r   r   r   r   r   r   NF)popgetattr)r   nameskwZ
translatedZattribute_namesZsnamerL   r   r   r   translate_connect_args   s   
zURL.translate_connect_args)NNNNNN)T)__name__
__module____qualname____doc__r   r,   r.   r0   r2   r6   r7   propertyr   setterr<   r>   rE   rN   r=   rT   r   r   r   r   r	      s2     



	r	   c                 C   s   t | tjr
t| S | S )zGiven a string or unicode instance, produce a new URL instance.

    The given string is parsed according to the RFC 1738 spec.  If an
    existing URL object is passed, just returns the object.
    )r3   r   string_types_parse_rfc1738_args)Zname_or_urlr   r   r   make_url   s   r]   c           
      C   sN  t dt j}|| }|d ur| }|d d ura|d dd}|d |d< t|dkr^i }t|d D ]%\}}tj	rC|
d}||v rXt|| ||< || | q7|||< q7nd }nd }||d< |d	 d urut|d	 |d	< |d
 d urt|d
 |d
< |d}|d}	|p|	|d< |d} t| fi |S td|  )Na  
            (?P<name>[\w\+]+)://
            (?:
                (?P<username>[^:/]*)
                (?::(?P<password>.*))?
            @)?
            (?:
                (?:
                    \[(?P<ipv6host>[^/]+)\] |
                    (?P<ipv4host>[^/:]+)
                )?
                (?::(?P<port>[^/]*))?
            )?
            (?:/(?P<database>.*))?
            r   r   r   r   r   asciir   r   r   ipv4hostipv6hostr   rL   z,Could not parse rfc1738 URL from string '%s')recompileXmatch	groupdictr;   lenr   	parse_qslZpy2kencoder   append_rfc_1738_unquoterP   r	   r   ArgumentError)
rL   patternm
componentstokensr   keyvaluer_   r`   r   r   r   r\      sF   


	


r\   c                 C   s   t ddd | S )Nz[:@/]c                 S   s   dt | d S )Nz%%%Xr   )ordgroup)rm   r   r   r   <lambda>(  s    z!_rfc_1738_quote.<locals>.<lambda>)ra   subtextr   r   r   r$   '  s   r$   c                 C   s
   t | S r
   )r   unquoterv   r   r   r   rj   +  r8   rj   c                 C   sF   t d| }|d ur!|dd\} }tt|}t| g|R  S d S )Nz(\w+)://(.*)r   r   )ra   rd   rs   dictr   rg   r	   )rL   rm   argsoptsr   r   r   _parse_keyvalue_args/  s   r|   )rX   ra   Z
interfacesr    r   r   Zdialectsr   r   objectr	   r]   r\   r$   rj   r|   r   r   r   r   <module>   s   	 D=