HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/yarl/__pycache__/_url.cpython-310.pyc
o

���g���@shddlZddlZddlZddlmZmZddlmZddlm	Z	m
Z
ddlmZddl
mZmZmZmZmZmZddlmZmZmZddlZddlmZmZdd	lmZd
dlm Z m!Z!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-m.Z.m/Z/d
dl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=dddddd�Z>e?e�Z@e?d�ZAe�BdejC�ZDed�ZEejFdkr�ddl
mGZGneZGGdd�de�ZHeHjIZJGdd�de�ZKGdd�dedd�ZLdeEd eEfd!d"�ZMe
d#eNd d$fd%d&��ZOe
d#eNd d$fd'd(��ZPe
d)eNd*eNd+eeNdfd,eeNdfd-eNd.eeQdfd/eNd0eNd1eNd d$fd2d3��ZRd)eNd4eNd/eNd5eNd1eNd d$fd6d7�ZSe
eS�ZTeMGd8d$�d$��ZUd9ZVd:ZWe
eV�d;eNd eNfd<d=��aXe
eV�d-eNd eNfd>d?��aYe
eW�d-eNd@eZd eNfdAdB��a[eMdOdCdD��Z\eMd eKfdEdF��Z]eMeVeVeJeJeJdG�dHeeQdfdIeeQdfdJeeQdeHfdKeeQdeHfdLeeQdeHfd dfdMdN��Z^dS)P�N)�Mapping�Sequence)�Enum)�
_CacheInfo�	lru_cache)�
ip_address)�
TYPE_CHECKING�Any�	TypedDict�TypeVar�Union�overload)�SplitResult�	parse_qsl�
uses_relative)�	MultiDict�MultiDictProxy)�under_cached_property�)�USES_AUTHORITY�SplitURLType�make_netloc�split_netloc�	split_url�unsplit_result)�normalize_path�normalize_path_segments)�Query�
QueryVariable�SimpleQuery�
get_str_query�get_str_query_from_iterable�$get_str_query_from_sequence_iterable)
�FRAGMENT_QUOTER�FRAGMENT_REQUOTER�PATH_QUOTER�
PATH_REQUOTER�PATH_SAFE_UNQUOTER�
PATH_UNQUOTER�QS_UNQUOTER�QUERY_QUOTER�QUERY_REQUOTER�QUOTER�REQUOTER�UNQUOTER�human_quote�Pi��)�http�https�ws�wss�ftpa<
        # any character not in the unreserved or sub-delims sets, plus %
        # (validated with the additional check for pct-encoded sequences below)
        [^a-z0-9\-._~!$&'()*+,;=%]
    |
        # % only allowed if it is part of a pct-encoded
        # sequence of 2 hex digits.
        %(?![0-9a-f]{2})
    �_T)��)�Selfc@seZdZdZdZdS)�
UndefinedTypez4Singleton type for use with not set sentinel values.rN)�__name__�
__module__�__qualname__�__doc__�
_singleton�rArA�4/usr/local/lib/python3.10/dist-packages/yarl/_url.pyr;Psr;c@s:eZdZUdZeed<eed<eed<eed<eed<dS)�	CacheInfozHost encoding cache.�idna_encode�idna_decoder�
host_validate�encode_hostN)r<r=r>r?r�__annotations__rArArArBrCYs
rCc@s�eZdZUeed<ded<eed<eed<eed<eed<eedfed	<eedfed
<eedfed<eedfed<eedfed
<eedfed<eedfed<eedfed<eedfed<eedfed<eed<eed<e	e
eefed<ded<eed<eed<eed<eed<eed<eed<e
edfed<e
edfed <ded!<eed"<eed#<eed$<eed%<e
edfed&<e
edfed'<dS)(�_InternalURLCache�_val�URL�_origin�absolute�scheme�
raw_authority�	authorityN�raw_user�user�raw_password�password�raw_host�host�host_subcomponent�host_port_subcomponent�port�
explicit_port�raw_path�path�
_parsed_query�MultiDictProxy[str]�query�raw_query_string�query_string�path_qs�raw_path_qs�raw_fragment�fragment.�	raw_parts�parts�parent�raw_name�name�
raw_suffix�suffix�raw_suffixes�suffixes)r<r=r>rrH�bool�strr�int�list�tuplerArArArBrIcsH
rIF)�total�obj�returncCs
d|_|S)N�yarl)r=)rurArArB�rewrite_module�srx�url_strrKcCs�i}t|�\}}}}}|sd}n�d|vsd|vsd|vr%t|�\}}	}}
nd}}	}
|}|durA|tvr?d|�d�}t|��d}t|dd	�}d|vrQ|d
d�n||d<|
|d
<|	durw|durw|
durg|n|�d|
��}d|d<d|d<n|r}t|�n|}|	r�t|	�n|	}
t||
||
�}||d<|
|d<|r�t|�}|r�d|vr�t|�}|r�t	|�}|r�t
|�}||d<|s�|r�dn||d<||d<||d<t�t
�}||_||_||_||_||_||_|S)zParse unencoded URL.��:�@�[Nz9Invalid URL: host is required for absolute urls with the � schemeF��
validate_hostr���rUrZrQrS�.rN�/r[r`rd)rr�SCHEME_REQUIRES_HOST�
ValueError�_encode_hostr-rr&rr+r$�object�__new__rK�_scheme�_netloc�_path�_query�	_fragment�_cache)ry�cacherN�netlocr\r_rerV�usernamerTrY�msgrQrS�selfrArArB�
encode_url�s`��

r�cCs4t�t�}t|�}|\|_|_|_|_|_i|_	|S)zParse pre-encoded URL.)
r�r�rKrr�r�r�r�r�r�)ryr��valrArArB�pre_encoded_url�s

r�rNrPrRrTrVrYr\rarec	
Cs�t�t�}	||	_|r||	_n4|r?|dur|t�|�krdn|}|dur6|dur6|dur-|n|�d|��|	_nt||||�|	_nd|	_||	_||	_	||	_
i|	_|	S)z#Build a pre-encoded URL from parts.Nr{rz)r�r�rKr�r��
DEFAULT_PORTS�getrr�r�r�r�)
rNrPrRrTrVrYr\rarer�rArArB�build_pre_encoded_url�s 

r�r�r_cCs2t�t�}||_||_||_||_||_i|_|S)zCreate a new URL from parts.)	r�r�rKr�r�r�r�r�r�)rNr�r\r_rer�rArArB�from_parts_uncached�s
r�c@s eZdZUdZeed<eed<eed<eed<eed<efddd	�d
eeede	fde
dee
dfd
dfdd�Zedddddddddddd�dededeedfdeedfdedee
dfdedeedfdedede
d
dfdd��Zdd�Zd
efd d!�Zd
efd"d#�Zd
efd$d%�Zd&ed
e
fd'd(�Zd
e
fd)d*�Zd&ed
e
fd+d,�Zd&ed
e
fd-d.�Zd&ed
e
fd/d0�Zd&ed
e
fd1d2�Zd3ed
dfd4d5�Zded
dfd6d7�Zd
e
fd8d9�Zd
eefd:d;�Z d<d=�Z!d�d>d?�Z"d
e
fd@dA�Z#d
e
fdBdC�Z$d�dDdE�Z%e&d
e'fdFdG��Z(e&d�dHdI��Z)d�dJdK�Z*e&d
e
fdLdM��Z+e&d
efdNdO��Z,e&d
efdPdQ��Z-e&d
efdRdS��Z.e&d
eedffdTdU��Z/e&d
eedffdVdW��Z0e&d
eedffdXdY��Z1e&d
eedffdZd[��Z2e&d
eedffd\d]��Z3e&d
eedffd^d_��Z4e&d
eedffd`da��Z5e&d
eedffdbdc��Z6e&d
ee
dffddde��Z7e&d
ee
dffdfdg��Z8e&d
efdhdi��Z9e&d
efdjdk��Z:e&d
efdldm��Z;e&d
e<eeeffdndo��Z=e&d�dqdr��Z>e&d
efdsdt��Z?e&d
efdudv��Z@e&d
efdwdx��ZAe&d
efdydz��ZBe&d
efd{d|��ZCe&d
efd}d~��ZDe&d
eedffd�d���ZEe&d
eedffd�d���ZFe&d�d�d���ZGe&d
efd�d���ZHe&d
efd�d���ZIe&d
efd�d���ZJe&d
efd�d���ZKe&d
eedffd�d���ZLe&d
eedffd�d���ZMd�d�d�de
d
dfd�d��ZNded
dfd�d��ZOdeedfd
dfd�d��ZPdeedfd
dfd�d��ZQded
dfd�d��ZRdee
dfd
dfd�d��ZSdddd��dede
d�e
d�e
d
df
d�d��ZTeUded
dfd�d���ZVeUd�eWd
dfd�d���ZVd�eXd�eXd
dfd�d��ZVeUded
dfd�d���ZYeUd�eWd
dfd�d���ZYd�eXd�eXd
dfd�d��ZYeUded
dfd�d���ZZeUd�eWd
dfd�d���ZZd�eXd�eXd
dfd�d��ZZd�ed
dfd�d��Z[deedfd
dfd�d��Z\ddd��d3ed�e
d�e
d
dfd�d��Z]ddd��d�ed�e
d�e
d
dfd�d��Z^d�d�d��Z_dd��d&ede
d
dfd�dÄZ`d
efd�dńZadS)�rK)r�r�r�r�r�r�r�r�r�r�r�FN)�encoded�strictr�r�r�rvcCs�|dur	t�d�t|�tur|rt|�St|�St|�|ur!|St|�tur1|s-td��t|�St	|t�rD|r>tt|��Stt|��S|t
urat�t
�}d|_|_|_|_|_i|_|Std��)Nzstrict parameter is ignoredz$Cannot apply decoding to SplitResultrzz#Constructor parameter should be str)�warnings�warn�typerpr�r�rr��
from_parts�
isinstance�	UNDEFINEDr�r�rKr�r�r�r�r�r��	TypeError)�clsr�r�r�r�rArArBr�Ys$


zURL.__new__rz)rNrPrRrTrVrYr\r_rarer�rNrPrRrTrVrYr\r_rarec
Cs�|r|s
|s
|s
|rtd��|dur!t|t�s!tdt|��d���|r)|s)td��|r1|	r1td��|dusI|dusI|dusI|dusI|	dusI|
durMtd��|rUt|�pTd}	|rct||||||||	|
�	St�t	�}||_
d}
|r�t|�\}}}
}|
rt|
d	d
�nd}
n|r�t|dd
�}
nd|_
|
dur�|dur�|t�|�kr�dn|}|dur�|dur�|dur�|
n|
�d|��|_
n	t|||
|d�|_
|r�t|�n|}|r�|j
r�d|vr�t|�}|d
dkr�d}t|��||_|s�|	r�t|	�}	|	|_|
r�t|
�n|
|_i|_|S)zCreates and returns a new URLz@Can't mix "authority" with "user", "password", "host" or "port".Nz$The port is required to be int, got r�z/Can't build URL with "port" but without "host".z6Only one of "query" or "query_string" should be passedz}NoneType is illegal for "scheme", "authority", "host", "path", "query_string", and "fragment" args, use empty string instead.rzFrTr{rr�zCPath in a URL with authority should start with a slash ('/') if set)r�r�rqr�r�r r�r�r�rKr�rr�r�r�r�rr%rr�r*r�r#r�r�)r�rNrPrRrTrVrYr\r_rarer�r��_hostr�rArArB�buildvs~���

�z	URL.buildcCstd|�d���)NzInheriting a class z from URL is forbidden)r�)r�rArArB�__init_subclass__��zURL.__init_subclass__cCsx|js|jr|js|jrd}n|j}|j}dur.|t�|j�kr.|j}t	|j
|j|d�}n|j}t|j|||j|j�S�Nr�)
r�r�r�r�rZr�r�r�rWrrQrSr)r�r\rYrVr�rArArB�__str__�s�zURL.__str__cCs|jj�dt|��d�S)Nz('z'))�	__class__r<rp�r�rArArB�__repr__�szURL.__repr__cCst|��d�S)N�ascii)rp�encoder�rArArB�	__bytes__�sz
URL.__bytes__�othercCstt|�turtS|js|jrdn|j}|js|jrdn|j}|j|jko9|j|jko9||ko9|j|jko9|j|jkSr�)r�rK�NotImplementedr�r�r�r�r�)r�r��path1�path2rArArB�__eq__�s
��
�
�z
URL.__eq__cCsR|j�d�}dur'|js|jrdn|j}t|j|j||j|jf�}|jd<|S)N�hashr�)r�r�r�r�r�r�r�r�)r��retr\rArArB�__hash__�s�zURL.__hash__cCst|�turtS|j|jkS�N�r�rKr�rJ�r�r�rArArB�__le__�z
URL.__le__cCst|�turtS|j|jkSr�r�r�rArArB�__lt__	r�z
URL.__lt__cCst|�turtS|j|jkSr�r�r�rArArB�__ge__r�z
URL.__ge__cCst|�turtS|j|jkSr�r�r�rArArB�__gt__r�z
URL.__gt__rjcCst|t�stS|�t|�f�Sr�)r�rpr��_make_child�r�rjrArArB�__truediv__s
zURL.__truediv__cCs
|�|�Sr�)�update_query�r�r_rArArB�__mod__s
zURL.__mod__cCst|jp|jp|jp|j�Sr�)ror�r�r�r�r�rArArB�__bool__ szURL.__bool__cCst�t|j�fSr�)rsr�rrJr�rArArB�__getstate__#r�zURL.__getstate__cCsR|ddurt|dt�r|dd}n|^}}|\|_|_|_|_|_i|_dS)NrrrJ)r��dictr�r�r�r�r�r�)r��stater��unusedrArArB�__setstate__&s

zURL.__setstate__cCs0|j}t|j�}|\|d<|d<|d<|d<dS)z"Cache the netloc parts of the URL.rQrSrUrZN)r�rr�)r��c�	split_locrArArB�
_cache_netloc/s
 zURL._cache_netloccC�|jS)z�A check for absolute URLs.

        Return True for absolute ones (having scheme or starting
        with //), False otherwise.

        Is is preferred to call the .absolute property instead
        as it is cached.
        )rMr�rArArB�is_absolute5s	zURL.is_absolutecCs(|j}dur|jdkS|t�|j�kS)z�A check for default port.

        Return True if port is default for specified scheme,
        e.g. 'http://python.org' or 'http://python.org:80', False
        otherwise.

        Return False for relative URLs.

        Nrz)rZr�r�r�r�)r��explicitrArArB�is_default_port@s

zURL.is_default_portcCr�)z}Return an URL with scheme, host and port parts only.

        user, password, path, query and fragment are removed.

        )rLr�rArArB�originQ�z
URL.origincCs|j|j|j|j|jfSr�)r�r�r�r�r�r�rArArBrJZszURL._valcCsj|j}s	td��|j}std��d|vr"|j}tdd||j�}n|js-|js-|js-|St	||ddd�S)z|Return an URL with scheme, host and port parts only.

        user, password, path, query and fragment are removed.
        �URL should be absolutezURL should have schemer|Nrz)
r�r�r�rWrrZr�r�r�r�)r�r�rN�encoded_hostrArArBrL^s

zURL._origincCs$|jstd��tdd|j|j|j�S)zhReturn a relative part of the URL.

        scheme, user, password, host and port are removed.

        r�rz)r�r�r�r�r�r�r�rArArB�relativeoszURL.relativecCs
|jdkS)z�A check for absolute URLs.

        Return True for absolute ones (having scheme or starting
        with //), False otherwise.

        rz�r�r�rArArBrMys
zURL.absolutecCr�)zdScheme for absolute URLs.

        Empty string for relative URLs or URLs starting with //

        )r�r�rArArBrN�r�z
URL.schemecCr�)zQEncoded authority part of URL.

        Empty string for relative URLs.

        r�r�rArArBrO�r�zURL.raw_authoritycCst|j|j|j|j�S)zQDecoded authority part of URL.

        Empty string for relative URLs.

        )rrRrTrVrYr�rArArBrP��z
URL.authoritycC�|��|jdS)zEEncoded user part of URL.

        None if user is missing.

        rQ�r�r�r�rArArBrQ�s
zURL.raw_usercC�|j}dur	dSt|�S)zEDecoded user part of URL.

        None if user is missing.

        N)rQr.)r�rQrArArBrR��zURL.usercCr�)zMEncoded password part of URL.

        None if password is missing.

        rSr�r�rArArBrS��
zURL.raw_passwordcCr�)zMDecoded password part of URL.

        None if password is missing.

        N)rSr.)r�rSrArArBrT�r�zURL.passwordcCr�)z�Encoded host part of URL.

        None for relative URLs.

        When working with IPv6 addresses, use the `host_subcomponent` property instead
        as it will return the host subcomponent with brackets.
        rUr�r�rArArBrU�s
zURL.raw_hostcCs6|j}dur	dS|r|d��sd|vr|St|�S)zDDecoded host part of URL.

        None for relative URLs.

        Nr�r{)rU�isdigit�_idna_decode�r��rawrArArBrV�s
zURL.hostcCs*|j}dur	dSd|vrd|�d�S|S)a�Return the host subcomponent part of URL.

        None for relative URLs.

        https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2

        `IP-literal = "[" ( IPv6address / IPvFuture  ) "]"`

        Examples:
        - `http://example.com:8080` -> `example.com`
        - `http://example.com:80` -> `example.com`
        - `https://127.0.0.1:8443` -> `127.0.0.1`
        - `https://[::1]:8443` -> `[::1]`
        - `http://[::1]` -> `[::1]`

        Nr{r}�])rUr�rArArBrW�szURL.host_subcomponentcCs�|j}dur	dS|ddkr|�d�}|j}|dus#|t�|j�kr/d|vr-d|�d�S|Sd|vr;d|�d|��S|�d|��S)aReturn the host and port subcomponent part of URL.

        Trailing dots are removed from the host part.

        This value is suitable for use in the Host header of an HTTP request.

        None for relative URLs.

        https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2
        `IP-literal = "[" ( IPv6address / IPvFuture  ) "]"`
        https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3
        port        = *DIGIT

        Examples:
        - `http://example.com:8080` -> `example.com:8080`
        - `http://example.com:80` -> `example.com`
        - `http://example.com.:80` -> `example.com`
        - `https://127.0.0.1:8443` -> `127.0.0.1:8443`
        - `https://[::1]:8443` -> `[::1]:8443`
        - `http://[::1]` -> `[::1]`

        Nr�r�r{r}r�z]:)rU�rstriprZr�r�r�)r�r�rYrArArBrX�s
&zURL.host_port_subcomponentcCs|j}dur	|St�|j�S)z�Port part of URL, with scheme-based fallback.

        None for relative URLs or URLs without explicit port and
        scheme without default port substitution.

        N)rZr�r�r�)r�rZrArArBrY%szURL.portcCr�)zyPort part of URL, without scheme-based fallback.

        None for relative URLs or URLs without explicit port.

        rZr�r�rArArBrZ1r�zURL.explicit_portcCs|js|js	|jSdS)zNEncoded path of URL.

        / for absolute URLs without path part.

        r�)r�r�r�rArArBr[;r�zURL.raw_pathcC�|jrt|j�S|jr
dSdS)zNDecoded path of URL.

        / for absolute URLs without path part.

        r�rz)r�r(r�r�rArArBr\DszURL.pathcCr�)z{Decoded path of URL.

        / for absolute URLs without path part.

        / (%2F) and % (%25) are not decoded

        r�rz)r�r'r�r�rArArB�	path_safeMs	
z
URL.path_safecCst|jdd�S)zParse query part of URL.T��keep_blank_values)rr�r�rArArBr]ZszURL._parsed_queryr^cCstt|j��S)z�A MultiDictProxy representing parsed query parameters in decoded
        representation.

        Empty value if URL has no query part.

        )rrr]r�rArArBr__sz	URL.querycCr�)zOEncoded query part of URL.

        Empty string if query is missing.

        )r�r�rArArBr`ir�zURL.raw_query_stringcC�|jrt|j�SdS)zODecoded query part of URL.

        Empty string if query is missing.

        rz)r�r)r�rArArBrar�zURL.query_stringcCs |j}s|jS|j�d|��S)zDecoded path of URL with query.�?)rar\�r��qrArArBrb{s zURL.path_qscCsF|j}r|js|js|j�d|��Sd|��S|js|js!|jSdS)zEncoded path of URL with query.r�z/?r�)r�r�r�r�rArArBrc�s
&zURL.raw_path_qscCr�)zUEncoded fragment part of URL.

        Empty string if fragment is missing.

        )r�r�rArArBrd�r�zURL.raw_fragmentcCr�)zUDecoded fragment part of URL.

        Empty string if fragment is missing.

        rz)r�r.r�rArArBre�r�zURL.fragment.cCsf|j}|jr|rdg|dd��d��RSdS|r,|ddkr,dg|dd��d��RSt|�d��S)zjA tuple containing encoded *path* parts.

        ('/',) for absolute URLs if *path* is missing.

        r�rN)r�r)r�r��splitrs)r�r\rArArBrf�s"z
URL.raw_partscC�tdd�|jD��S)zjA tuple containing decoded *path* parts.

        ('/',) for absolute URLs if *path* is missing.

        cs��|]}t|�VqdSr��r.)�.0�partrArArB�	<genexpr>���zURL.parts.<locals>.<genexpr>)rsrfr�rArArBrg�r�z	URL.partscCsb|j}|r	|dkr|js|jrt|j|j|dd�S|S|�d�}t|j|jd�|dd��dd�S)z]A new URL with last part of path removed and cleaned up query and
        fragment.

        r�rzNr�)r�r�r�r�r�r�r��join)r�r\rgrArArBrh�s
"z
URL.parentcCs0|j}|js
|dS|dd�}|r|dSdS)zThe last part of raw_parts.r�rNrz)rfr�)r�rgrArArBri�s
zURL.raw_namecC�
t|j�S)zThe last part of parts.)r.rir�rArArBrj�s
zURL.namecCs@|j}|�d�}d|krt|�dkrnn||d�SdS)Nr�rrrz)ri�rfind�len)r�rj�irArArBrk�s
0zURL.raw_suffixcCr�r�)r.rkr�rArArBrl�s
z
URL.suffixcCs>|j}|�d�r
dS|�d�}tdd�|�d�dd�D��S)Nr�rAcss�|]}d|VqdS)r�NrA�r�rlrArArBr��r�z#URL.raw_suffixes.<locals>.<genexpr>r)ri�endswith�lstriprsr�r�rArArBrm�s


 zURL.raw_suffixescCr�)Ncsr�r�r�r�rArArBr��r�zURL.suffixes.<locals>.<genexpr>)rsrmr�rArArBrn�szURL.suffixes�pathsz
Sequence[str]cCsbg}d}tt|��D]A\}}|dk}|r"|ddkr"td|�d���|r&|nt|�}|d|vO}|�d�}|��||sH|ddkrH|dd	�n|7}q
|j}rn|�d�}	rn|	d
dkrd|	d	d
�n|	}
|
��||
7}|j}r�|r�|d
dkr�|�d�|��|r�|s�t	|j
|d�|�dd�Sd�t|��}|r�|ddkr�d|��}t	|j
||dd�S)z�
        add paths to self._path, accounting for absolute vs relative paths,
        keep existing, but do not create new, empty segments
        Frr�zAppending path z! starting from slash is forbiddenr�rzrNr�)
�	enumerate�reversedr�r%r��reverser�r��appendr�r�r�r)r�r�r��parsed�needs_normalize�idxr\�last�segments�old_segments�oldr�rArArBr��s4
�
&

zURL._make_childcCsVt|t�s	td��|��}|j}|s |tvr d|�d�}t|��t|||j|j	|j
�S)z&Return a new URL with scheme replaced.zInvalid scheme typez<scheme replacement is not allowed for relative URLs for the r~)r�rpr��lowerr�r�r�r�r�r�r�)r�rN�lower_schemer�r�rArArB�with_schemes
��zURL.with_schemecCst|durd}nt|t�rt|�}|j}ntd��|j}s!td��|jp%d}t||||j	�}t
|j||j|j
|j�S)z�Return a new URL with user replaced.

        Autoencode user if needed.

        Clear user/password if user is None.

        NzInvalid user typez1user replacement is not allowed for relative URLsrz)r�rpr,rSr�r�r�rWrrZr�r�r�r�r�)r�rRrTr�r�rArArB�	with_user s	


z
URL.with_usercCsp|durnt|t�rt|�}ntd��|j}std��|jp d}|j}t|j	|||�}t
|j||j|j
|j�S)z�Return a new URL with password replaced.

        Autoencode password if needed.

        Clear password if argument is None.

        NzInvalid password typez5password replacement is not allowed for relative URLsrz)r�rpr,r�r�r�rWrZrrQr�r�r�r�r�)r�rTr�r�rYrArArB�
with_password6s	



zURL.with_passwordcCstt|t�s	td��|j}std��|std��|r t|dd�nd}|j}t|j|j	||�}t
|j||j|j
|j�S)z�Return a new URL with host replaced.

        Autoencode host if needed.

        Changing host for relative URLs is not allowed, use .join()
        instead.

        zInvalid host typez1host replacement is not allowed for relative URLszhost removing is not allowedTrrz)r�rpr�r�r�r�rZrrQrSr�r�r�r�r�)r�rVr�r�rYrArArB�	with_hostLs


z
URL.with_hostcCs�|dur)t|t�st|t�stdt|�����d|kr!dks)ntd|����|j}s2td��|jp6d}t|j	|j
||�}t|j||j
|j|j�S)z`Return a new URL with port replaced.

        Clear port to default if None is passed.

        Nz port should be int or None, got ri��z&port must be between 0 and 65535, got z1port replacement is not allowed for relative URLsrz)r�rorqr�r�r�r�rWrrQrSr�r�r�r�r�)r�rYr�r�rArArB�	with_portas

z
URL.with_port)r��
keep_query�
keep_fragmentrrcCsr|j}|st|�}|rd|vrt|�n|}|r"|ddkr"d|��}|r'|jnd}|r.|jnd}t|j||||�S)z$Return a new URL with path replaced.r�rr�rz)r�r%rr�r�r�r�)r�r\r�rrr�r_rerArArB�	with_pathss	
z
URL.with_pathcC�dSr�rAr�rArArB�
with_query��zURL.with_query�kwargscKrr�rA�r�rrArArBr�r�argscOs*t|i|��pd}t|j|j|j||j�S)a[Return a new URL with query part replaced.

        Accepts any Mapping (e.g. dict, multidict.MultiDict instances)
        or str, autoencode the argument if needed.

        A sequence of (key, value) pairs is supported as well.

        It also can take an arbitrary number of keyword arguments.

        Clear query if None is passed.

        rz)r r�r�r�r�r�)r�rrr_rArArBr�s�cCrr�rAr�rArArB�extend_query�rzURL.extend_querycKrr�rArrArArBr�rcOs\t|i|��}s|S|j}r ||ddkr|nd|��7}n|}t|j|j|j||j�S)a&Return a new URL with query part combined with the existing.

        This method will not remove existing query parameters.

        Example:
        >>> url = URL('http://example.com/?a=1&b=2')
        >>> url.extend_query(a=3, c=4)
        URL('http://example.com/?a=1&b=2&a=3&c=4')
        r��&)r r�r�r�r�r�r�)r�rr�	new_queryr_rArArBr�s

 �cCrr�rAr�rArArBr��rzURL.update_querycKrr�rArrArArBr��rc	Os|r
|r
d}t|��|}nt|�dkr|d}ntd��|dur#d}n^|s)|j}nXt|t�r?t|j�}|�|�t|�	��}nBt|t
�rYt|j�}|�t|dd��t|�	��}n(t|t
ttf�rgd}t|��t|t�r}t|j�}|�|�t|�	��}ntd	��t|j|j|j||j�S)
aReturn a new URL with query part updated.

        This method will overwrite existing query parameters.

        Example:
        >>> url = URL('http://example.com/?a=1&b=2')
        >>> url.update_query(a=3, c=4)
        URL('http://example.com/?a=3&b=2&c=4')
        z7Either kwargs or single query parameter must be presentrrNrzTr�zAInvalid query type: bytes, bytearray and memoryview are forbiddenzRInvalid query type: only str, mapping or sequence of (key, value) pairs is allowed)r�r�r�r�rrr]�updater"�itemsrprr!�bytes�	bytearray�
memoryviewr�rr�r�r�r�r�)	r�rrr��in_queryr_�qm�qstr�qsrArArBr��sB








���query_paramscs<t|�|j��@��s
|S|�t�fdd�|j��D���S)z4Remove some keys from query part and return new URL.c3s$�|]
\}}|�vr||fVqdSr�rA)r�rj�value��params_to_removerArBr��s���z+URL.without_query_params.<locals>.<genexpr>)�setr_�keysrrsr)r�r'rAr)rB�without_query_params�s��zURL.without_query_paramscCsN|durd}n
t|t�std��t|�}|j|kr|St|j|j|j|j	|�S)z�Return a new URL with fragment replaced.

        Autoencode fragment if needed.

        Clear fragment to default if None is passed.

        NrzzInvalid fragment type)
r�rpr�r#r�r�r�r�r�r�)r�rerdrArArB�
with_fragments	

�zURL.with_fragment�rrcCs�t|t�s	td��d|vrtd��t|�}|dvrtd��t|j�}|j}r<t|�dkr3|�	|�n||d<d|d	<n||d<|d	dkrJd|d	<|rO|j
nd}|rV|jnd}t|j
|d�|�||�S)
z�Return a new URL with name (last part of path) replaced.

        Query and fragment parts are cleaned up.

        Name is encoded if needed.

        zInvalid name typer�zSlash in name is not allowed)r�z..z. and .. values are forbiddenrr�rzr)r�rpr�r�r%rrrfr�r�rr�r�r�r�r�)r�rjrrrgr�r_rerArArB�	with_names&



z
URL.with_namerlcCs�t|t�s	td��|r|ddkr|dkrtd|����|j}|s(t|�d���|j}|s1||n
|dt|��|}|j|||d�S)z�Return a new URL with suffix (file extension of name) replaced.

        Query and fragment parts are cleaned up.

        suffix is encoded if needed.
        zInvalid suffix typerr�zInvalid suffix z has an empty nameNr/)r�rpr�r�rirkr�r0)r�rlrrrj�
old_suffixrArArB�with_suffix?s

"zURL.with_suffix�urlcCs4t|�tur
td��|jp|j}||jks|tvr|S|j}r/|tvr/t|||j|j	|j
�S|j}|j}r||ddkr@|}n1|sHd|��}n)|ddkrU|�|��}nd�g|jdd��d��|}|ddkrq|dd�}d|vryt
|�n|}n|}t||j||s�|j	r�|j	n|j	|s�|j
r�|j
�S|j
�S)	u_Join URLs

        Construct a full (“absolute”) URL by combining a “base URL”
        (self) with another URL (url).

        Informally, this uses components of the base URL, in
        particular the addressing scheme, the network location and
        (part of) the path, to provide missing components in the
        relative URL.

        zurl should be URLrr�r�Nrzrr�)r�rKr�r��
USES_RELATIVEr�rr�r�r�r�r�rgr)r�r3rN�join_netloc�	orig_path�	join_pathr\rArArBr�Xs:
 ��zURL.join�r�cGs|j||d�S)zAReturn a new URL with the elements in other appended to the path.r8)r�)r�r�r�rArArB�joinpath�szURL.joinpathcCs�t|jd�}t|jd�}|j}rd|vrd|�d�}t|jd�}tr)|dus)J�d�dd	�|j��D��}t|j	d
�}trD|dusDJ�t
||||j�}t|j
||||�S)z<Return decoded human readable string for URL representation.z#/:?@[]r{r}r�z#?Nrcss,�|]\}}d�t|d�t|d��VqdS)z{}={}z#&+;=N)�formatr/)r��k�vrArArBr��s
��
�z!URL.human_repr.<locals>.<genexpr>rz)r/rRrTrVr\rr�r_rrerrZrr�)r�rRrTrVr\rarer�rArArB�
human_repr�s
�zURL.human_repr�rvN)rvrK)rvr^)F)r3rKrvrK)br<r=r>�	__slots__rprHr�rrr;ror��classmethodrqrr�r�r�r�r r�r�r�r�r�r�r�r�r�r�r�rsr�r�r�r�r�r��cached_propertyrrJrLr�rMrNrOrPrQrRrSrTrUrVrWrXrYrZr[r\r�rrr]r_r`rarbrcrdrerfrgrhrirjrkrlrmrnr�r
rrrrrr
rrr	rr�r-r.r0r2r�r9r=rArArArBrK
s�
G����
�
����
�
��
�	�

���
��^
	
	




	


%		

/�����
�5
����
�*����
�
4�ir�cCs6z	t�|�d��WSty|�d��d�YSw)Nr��idna)rC�decoder��UnicodeError)r�rArArBr��s
�r�cCs:ztj|dd��d�WSty|�d��d�YSw)NT)�uts46r�rC)rCr�rDrE)rVrArArB�_idna_encode�s
�rGr�c
	Cs|rH|d��sd|vrH|�d�\}}}zt|�}Wn	ty#Yn%w|j}|jdkr=|r7d|�d|�d�Sd|�d�S|rF|�d|��S|S|��r�|��}|r�t�	|�}r�|�
�|��d}}}	|dksu|dkrwd||d	�vrwd
}	td|�d|�d
|�d|	���d	�|St|�S)zEncode host part of URL.r�r{�%�r}r�rzr|NzQ, if the value includes a username or password, use 'authority' instead of 'host'zHost z cannot contain z (at position �))
r��	partitionrr��
compressed�version�isasciir�NOT_REG_NAME�search�group�startrG)
rVr��raw_ip�sep�zone�ip�invalidr(�pos�extrarArArBr��s2�
" ���r�cCst��t��t��dS)zClear all LRU caches.N)rG�cache_clearr�r�rArArArBrZ�srZcCs$t��t��t��t��t��d�S)zReport cache statistics.)rDrErrFrG)rG�
cache_infor�r�rArArArBr[�s�r[)�idna_encode_size�idna_decode_size�ip_address_size�host_validate_size�encode_host_sizer\r]r^r_r`cCs�|tus|turtjdtdd�|durL||fD]-}|dur!d}q|tur,|tur+|}q|turEtr@t|t�s9J�t|t�s@J�t||�}q|turLt}trUt|t	�rUJ�t
|�tj�at
|�t
j�a
t
|�tj�adS)zConfigure LRU cache sizes.z�cache_configure() no longer accepts the ip_address_size or host_validate_size arguments, they are used to set the encode_host_size instead and will be removed in the future�)�
stacklevelN)r�r�r��DeprecationWarningrr�rq�max�_DEFAULT_ENCODE_SIZEr�rr��__wrapped__r�rG)r\r]r^r_r`�sizerArArB�cache_configures6
�	�
�rhr>)_�re�sysr��collections.abcrr�enumr�	functoolsrr�	ipaddressr�typingrr	r
rrr
�urllib.parserrrrC�	multidictrr�
propcache.apirrA�_parserrrrrrr�rrr�rrrr r!r"�_quotersr#r$r%r&r'r(r)r*r+r,r-r.r/r��	frozensetr4r��compile�VERBOSErOr7�version_infor:r;r@r�rCrIrxrpr�r�rqr�r�r�rK�_DEFAULT_IDNA_SIZErer�rGror�rZr[rhrArArArB�<module>s�   <	�

&?	��
�
��
���	�
� �����
�"9�
�
�����