B 4]$@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@seZdZdZd!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||_||_||_||_|dk r,t||_nd|_||_|p>i|_dS)N) drivernameusernamepassword_originalhostintportdatabasequery)selfr r passwordr rrrrH/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/engine/url.py__init__8s  z URL.__init__Tcsjd}jdk rN|tj7}jdk rF|d|r8dntj7}|d7}jdk r|djkrr|dj7}n |j7}jdk r|dtj7}jdk r|dj7}jrt j}| |dd fd d |D7}|S) Nz://:z***@z[%s]/?&c3s0|](}tj|D]}d||fVqqdS)z%s=%sN)rto_listr).0kZelement)rrr csz$URL.__to_string__..) r r _rfc_1738_quoterr rstrrrlistsortjoin)r hide_passwordskeysr)rr __to_string__Ms,          zURL.__to_string__cCs |jddS)NF)r%)r()rrrr__str__isz URL.__str__cCs|S)N)r()rrrr__repr__lsz URL.__repr__cCs tt|S)N)hashr!)rrrr__hash__osz URL.__hash__cCs^t|to\|j|jko\|j|jko\|j|jko\|j|jko\|j|jko\|j|jko\|j|jkS)N) isinstancer r r rr rrr)rotherrrr__eq__rs       z URL.__eq__cCs ||k S)Nr)rr.rrr__ne__~sz URL.__ne__cCs|jdkrdSt|jSdS)N)r rZ text_type)rrrrrs z URL.passwordcCs ||_dS)N)r )rrrrrrscCs$d|jkr|jS|jddSdS)N+r)r split)rrrrget_backend_names zURL.get_backend_namecCs(d|jkr|jS|jddSdS)Nr1r)r get_dialectZdriverr2)rrrrget_driver_names  zURL.get_driver_namecs8tjdd}|dg7}fdd|DS)NZpluginrrcsg|]}t|qSr)rload)rZ plugin_name)kwargsrrr sz,URL._instantiate_plugins..)rrrget)rr7Z plugin_namesr)r7rr_instantiate_pluginss zURL._instantiate_pluginscCsZd|jkr|j}n|jdd}t|}t|drRt|jtrRt|jt rR|jS|SdS)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. r1.dialectN) r replacerr6hasattrr-r<type issubclassr)rnameclsrrr_get_entrypoints     zURL._get_entrypointcCs|}||}|S)zfReturn the SQLAlchemy database dialect class corresponding to this URL's driver name. )rCZget_dialect_cls)rZ entrypointZ dialect_clsrrrr4s zURL.get_dialectcKsli}dddddg}xT|D]L}|r,|d}n||kr>||}n|}|dk rt||drt||||<qW|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. r rr rrrNF)popgetattr)rnameskwZ translatedZattribute_namesZsnamerArrrtranslate_connect_argss   zURL.translate_connect_args)NNNNNN)T)__name__ __module__ __qualname____doc__rr(r)r*r,r/r0propertyrsetterr3r5r:rCr4rHrrrrr s*    r cCst|tjrt|S|SdS)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. N)r-rZ string_types_parse_rfc1738_args)Z name_or_urlrrrmake_urls rPc CsXtdtj}||}|dk rF|}|ddk r|ddd}|d|d<t|dkri}xbt|dD]J\}}tj r| d}||krt ||||<|| |qr|||<qrWqd}nd}||d<|d dk rt |d |d <|d dk rt |d |d <|d }|d } |p*| |d <|d}t|f|Std|dS)Na (?P[\w\+]+):// (?: (?P[^:/]*) (?::(?P.*))? @)? (?: (?: \[(?P[^/]+)\] | (?P[^/:]+) )? (?::(?P[^/]*))? )? (?:/(?P.*))? rrrrrasciirr ripv4hostipv6hostr rAz,Could not parse rfc1738 URL from string '%s')recompileXmatch groupdictr2lenr parse_qslZpy2kencoderappend_rfc_1738_unquoterDr rZ ArgumentError) rApatternmZ componentstokensrkeyvaluerRrSrrrrOs@           rOcCstddd|S)Nz[:@/]cSsdt|dS)Nz%%%Xr)ordgroup)r_rrr(z!_rfc_1738_quote..)rTsub)textrrrr 'sr cCs t|S)N)rZunquote)rhrrrr]+sr]cCsHtd|}|dk r@|dd\}}tt|}t|f|SdSdS)Nz (\w+)://(.*)rr)rTrWrddictrrZr )rAr_argsZoptsrrr_parse_keyvalue_args/s  rk)rLrTZ interfacesrrrZdialectsrrobjectr rPrOr r]rkrrrrs     D =