o znh$@sdZddlZddlmZddlmZddlmZddlmZdd lm Z Gd d d e Z d d Z ddZ ddZddZddZdS)aProvides 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@seZdZdZ      d!ddZd"ddZdd Zd d Zd d ZddZ ddZ e ddZ e j ddZ ddZddZddZddZddZgfdd ZdS)#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. NcCsF||_||_||_||_|durt||_nd|_||_|pi|_dSN) drivernameusernamepassword_originalhostintportdatabasequery)selfr r passwordrrrrr@/usr/local/lib/python3.10/dist-packages/sqlalchemy/engine/url.py__init__8s  z URL.__init__Tcsjd}jdur'|tj7}jdur#|d|rdntj7}|d7}jdur>djvr9|dj7}n|j7}jdurL|dtj7}jdurX|dj7}jrtt j}| |dd fd d |D7}|S) Nz://:z***@z[%s]/?&c3s2|]}tj|D] }d||fVq qdS)z%s=%sN)rto_listr).0kelementrrr bs z$URL.__to_string__..) r r _rfc_1738_quoterrrstrrrlistsortjoin)r hide_passwordskeysrr!r __to_string__Ms.          zURL.__to_string__cCs |jddS)NF)r(r+r!rrr__str__i z URL.__str__cCs|Sr r,r!rrr__repr__lsz URL.__repr__cCs tt|Sr )hashr$r!rrr__hash__or.z URL.__hash__cCs^t|to.|j|jko.|j|jko.|j|jko.|j|jko.|j|jko.|j|jko.|j|jkSr ) isinstancer r r rrrrrrotherrrr__eq__rs        z URL.__eq__cCs ||k Sr rr3rrr__ne__~ z URL.__ne__cCs|jdurdSt|jSr )r r text_typer!rrrrs  z URL.passwordcCs ||_dSr )r )rrrrrrs cCs d|jvr|jS|jddS)N+r)r splitr!rrrget_backend_names zURL.get_backend_namecCs$d|jvr |jS|jddS)Nr9r)r get_dialectdriverr:r!rrrget_driver_names  zURL.get_driver_namecs8tjdd}|dg7}fdd|DS)Npluginrrcsg|] }t|qSr)rload)r plugin_namekwargsrrr sz,URL._instantiate_plugins..)rrrget)rrC plugin_namesrrBr_instantiate_pluginss  zURL._instantiate_pluginscCsVd|jvr |j}n|jdd}t|}t|dr)t|jtr)t|jt r)|jS|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. r9.dialect) r replacerr@hasattrr2rItype issubclassr)rnameclsrrr_get_entrypoints    zURL._get_entrypointcCs|}||}|S)zfReturn the SQLAlchemy database dialect class corresponding to this URL's driver name. )rPget_dialect_cls)r entrypoint dialect_clsrrrr<s zURL.get_dialectcKsbi}gd}|D]&}|r|d}n ||vr||}n|}|dur.t||dr.t||||<q|S)a2Translate 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. )rrr rrrNF)popgetattr)rnameskw translatedattribute_namessnamerNrrrtranslate_connect_argss  zURL.translate_connect_args)NNNNNN)T)__name__ __module__ __qualname____doc__rr+r-r/r1r5r6propertyrsetterr;r>rGrPr<r[rrrrr s2      r cCst|tjr 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. )r2r string_types_parse_rfc1738_args) name_or_urlrrrmake_urls rec CsNtdtj}||}|dur|}|ddura|ddd}|d|d<t|dkr^i}t|dD]%\}}tj rC| d}||vrXt ||||<|| |q7|||<q7nd}nd}||d<|d durut |d |d <|d durt |d |d <|d }|d } |p| |d <|d}t|fi|Std|)Na (?P[\w\+]+):// (?: (?P[^:/]*) (?::(?P.*))? @)? (?: (?: \[(?P[^/]+)\] | (?P[^/:]+) )? (?::(?P[^/]*))? )? (?:/(?P.*))? rrrrrasciirr ripv4hostipv6hostrrNz,Could not parse rfc1738 URL from string '%s')recompileXmatch groupdictr:lenr parse_qslpy2kencoderappend_rfc_1738_unquoterTr r ArgumentError) rNpatternm componentstokensrkeyvaluergrhrrrrcsF             rccCstddd|S)Nz[:@/]cSsdt|dS)Nz%%%Xr)ordgroup)rvrrr(sz!_rfc_1738_quote..)risubtextrrrr#'sr#cCs t|Sr )runquoterrrrrs+r7rscCsFtd|}|dur!|dd\}}tt|}t|g|RSdS)Nz (\w+)://(.*)rr)rirlr|dictrror )rNrvargsoptsrrr_parse_keyvalue_args/s r)r_ri interfacesrrrdialectsrrobjectr rercr#rsrrrrrs     D =