
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
U
    Zlx                     @   s   d dl Z d dlmZmZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZmZ d dlZddlmZmZ dZd	Zd
dd
ddZe ZG dd dZG dd dZdS )    N)MappingSequence)
ip_address)SplitResult	parse_qslurljoinurlsplit
urlunsplit)	MultiDictMultiDictProxy   )_Quoter	_Unquoterz1.1.1)URLP   i  )httphttpswswssc                   @   s,   e Zd ZdZdd ZefddZdd ZdS )	cached_propertyaR  Use as a class method decorator.  It operates almost exactly like
    the Python `@property` decorator, but it puts the result of the
    method it decorates into the instance dict after the first call,
    effectively replacing the function it decorates with an instance
    variable.  It is, in Python parlance, a data descriptor.

    c                 C   s:   || _ z|j| _W n tk
r,   d| _Y nX |j| _d S )N )wrapped__doc__AttributeError__name__name)selfr    r   @/opt/alt/python38/lib64/python3.8/site-packages/yarl/__init__.py__init__(   s    zcached_property.__init__c                 C   sB   |d kr| S |j | j|}||k	r(|S | |}||j | j< |S N)_cachegetr   r   )r   instowner	_sentinelvalr   r   r   __get__0   s    
zcached_property.__get__c                 C   s   t dd S )Nzcached property is read-only)r   )r   r#   valuer   r   r   __set__:   s    zcached_property.__set__N)r   
__module____qualname__r   r   sentinelr'   r)   r   r   r   r   r      s   
r   c                   @   s  e Zd ZdZe ZedddZeddddZeddd	Zedd
Z	e
 Ze
ddZe
ddZddddddZeddddddddddd
ddZdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Ze d5d6 Z!e d7d8 Z"e#d9d: Z$e d;d< Z%e#d=d> Z&e d?d@ Z'e#dAdB Z(e dCdD Z)e dEdF Z*e#dGdH Z+e#dIdJ Z,e dKdL Z-e#dMdN Z.e#dOdP Z/e#dQdR Z0e dSdT Z1e#dUdV Z2e#dWdX Z3e#dYdZ Z4e#d[d\ Z5e#d]d^ Z6e#d_d` Z7edadb Z8edcdd Z9ededf Z:dgdh Z;didj Z<dkdl Z=dmdn Z>dodp Z?ddqdrdsZ@dtdu ZAdvdw ZBdxdy ZCdzd{ ZDd|d} ZEd~d ZFdd ZGdS )r   )r!   _valz@:z/+)safe	protectedz?/:@z=+&;T)r.   r/   qs)r.   r0   )r.   +)Zunsafe)r0   r   FN)encodedstrictc          	      C   s  |d k	rt d t|tr0|j| _|j| _d S t|trDt|}n t|tr\|sdt	dnt
d|s|d svd}n0|j}|d krt	d| j|j|j||jdd}| |d	 }|r| |}| |d
 }| |d }t|d ||||}|| _i | _d S )Nzstrict parameter is ignoredz$Cannot apply decoding to SplitResultz#Constructor parameter should be strr   r   z/Invalid URL: host is required for abolute urls.Tencode         r   )warningswarn
isinstancer   r-   r!   strr   r   
ValueError	TypeErrorhostname_make_netlocusernamepasswordport_PATH_QUOTER_normalize_path_QUERY_QUOTER_FRAGMENT_QUOTER)	r   r&   r2   r3   netlochostpathqueryfragmentr   r   r   r      sD    






zURL.__init__)
schemeuserrB   rI   rC   rJ   rK   query_stringrL   r2   c       
         C   s   |r|st d|s |r t d|r0|r0t d|sF|sF|sF|sFd}n| j|||||
 d}|
s| |}|rx| |}| |}| |	}	| t|||||	dd}|r||S |S dS )	zCreates and returns a new URLz1Can't build URL with "host" but without "scheme".z1Can't build URL with "scheme" but without "host".z6Only one of "query" or "query_string" should be passedr   r4   Tr2   N)r=   r@   rD   rE   rF   rG   r   
with_query)clsrM   rN   rB   rI   rC   rJ   rK   rO   rL   r2   rH   urlr   r   r   build   sH    




z	URL.buildc                 C   s4   | j }|js,|  r,|js |jr,|jdd}t|S N/rJ   )r-   rJ   is_absoluterK   rL   _replacer	   r   r&   r   r   r   __str__   s    zURL.__str__c                 C   s   d | jjt| S )Nz{}('{}'))format	__class__r   r<   r   r   r   r   __repr__   s    zURL.__repr__c                 C   sV   t |tstS | j}|js.|  r.|jdd}|j}|jsN| rN|jdd}||kS rU   )r;   r   NotImplementedr-   rJ   rX   rY   )r   otherZval1Zval2r   r   r   __eq__   s    
z
URL.__eq__c                 C   sJ   | j d}|d krF| j}|js4|  r4|jdd}t| }| j d< |S )NhashrV   rW   )r!   r"   r-   rJ   rX   rY   rc   )r   retr&   r   r   r   __hash__   s    zURL.__hash__c                 C   s   t |tstS | j|jkS r    r;   r   r`   r-   r   ra   r   r   r   __le__  s    
z
URL.__le__c                 C   s   t |tstS | j|jk S r    rf   rg   r   r   r   __lt__	  s    
z
URL.__lt__c                 C   s   t |tstS | j|jkS r    rf   rg   r   r   r   __ge__  s    
z
URL.__ge__c                 C   s   t |tstS | j|jkS r    rf   rg   r   r   r   __gt__  s    
z
URL.__gt__c                 C   s   |  |}|drtd| jj}|dkr6d| }n6|sH|  sH|}n$|dd}|| d	|}|  r~| 
|}t| jj|dddddS )NrV   z/Appending path starting from slash is forbiddenr   rJ   rK   rL   TrP   )rD   
startswithr=   r-   rJ   rX   rstripsplitappendjoinrE   r   rY   )r   r   rJ   new_pathpartsr   r   r   __truediv__  s     





zURL.__truediv__c                 C   s   | j fS r    )r-   r^   r   r   r   __getstate__+  s    zURL.__getstate__c                 C   s>   |d d kr*t |d tr*|d d | _n
|^| _}i | _d S )Nr   r   r-   )r;   dictr-   r!   )r   stateunusedr   r   r   __setstate__.  s    
zURL.__setstate__c                 C   s
   | j dk	S )zA check for absolute URLs.

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

        N)raw_hostr^   r   r   r   rX   6  s    zURL.is_absolutec                 C   s0   | j dkrdS t| j}|dkr&dS | j |kS )zA 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.

        NF)rC   DEFAULT_PORTSr"   rM   )r   defaultr   r   r   is_default_port?  s    
zURL.is_default_portc                 C   s\   |   std| jjs td| j}| jdd|j|jdd}|j|dddd}t|dd	S )
z}Return an URL with scheme, host and port parts only.

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

        URL should be absolutezURL should have schemeNFr4   r   )rH   rJ   rK   rL   TrP   )	rX   r=   r-   rM   r@   r?   rC   rY   r   )r   vrH   r&   r   r   r   originN  s    z
URL.originc                 C   s,   |   std| jjddd}t|ddS )zhReturn a relative part of the URL.

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

        r~   r   )rM   rH   TrP   )rX   r=   r-   rY   r   rZ   r   r   r   relative_  s    zURL.relativec                 C   s   | j jS )zdScheme for absolute URLs.

        Empty string for relative URLs or URLs starting with //

        )r-   rM   r^   r   r   r   rM   j  s    z
URL.schemec                 C   s   | j j}|sdS |S )zEEncoded user part of URL.

        None if user is missing.

        N)r-   rA   r   rd   r   r   r   raw_users  s    zURL.raw_userc                 C   s   |  | jS )zEDecoded user part of URL.

        None if user is missing.

        )	_UNQUOTERr   r^   r   r   r   rN     s    zURL.userc                 C   s   | j jS )zMEncoded password part of URL.

        None if password is missing.

        )r-   rB   r^   r   r   r   raw_password  s    zURL.raw_passwordc                 C   s   |  | jS )zMDecoded password part of URL.

        None if password is missing.

        )r   r   r^   r   r   r   rB     s    zURL.passwordc                 C   s   | j jS )zDEncoded host part of URL.

        None for relative URLs.

        )r-   r?   r^   r   r   r   rz     s    	zURL.raw_hostc                 C   sZ   | j }|dkrdS d|kr|S zt|dW S  tk
rT   |dd Y S X dS )zDDecoded host part of URL.

        None for relative URLs.

        N%asciiidna)rz   r   decoder5   UnicodeError)r   rawr   r   r   rI     s    zURL.hostc                 C   s   | j jpt| j jS )zPort part of URL.

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

        )r-   rC   r{   r"   rM   r^   r   r   r   rC     s    zURL.portc                 C   s   | j j}|s|  rd}|S )zNEncoded path of URL.

        / for absolute URLs without path part.

        rV   )r-   rJ   rX   r   r   r   r   raw_path  s    zURL.raw_pathc                 C   s   |  | jS )zNDecoded path of URL.

        / for absolute URLs without path part.

        )_PATH_UNQUOTERr   r^   r   r   r   rJ     s    zURL.pathc                 C   s   t t| jdd}t|S )zA MultiDictProxy representing parsed query parameters in decoded
        representation.

        Empty value if URL has no query part.

        Tkeep_blank_values)r
   r   raw_query_stringr   r   r   r   r   rK     s    z	URL.queryc                 C   s   | j jS )zOEncoded query part of URL.

        Empty string if query is missing.

        )r-   rK   r^   r   r   r   r     s    zURL.raw_query_stringc                 C   s   |  | jS )zODecoded query part of URL.

        Empty string if query is missing.

        )_QS_UNQUOTERr   r^   r   r   r   rO     s    zURL.query_stringc                 C   s   | j s| jS d| j| j S )zDecoded path of URL with query.{}?{})rO   rJ   r\   r^   r   r   r   path_qs  s    zURL.path_qsc                 C   s   | j s| jS d| j| j S )zEncoded path of URL with query.r   )r   r   r\   r^   r   r   r   raw_path_qs  s    zURL.raw_path_qsc                 C   s   | j jS )zUEncoded fragment part of URL.

        Empty string if fragment is missing.

        )r-   rL   r^   r   r   r   raw_fragment  s    zURL.raw_fragmentc                 C   s   |  | jS )zUDecoded fragment part of URL.

        Empty string if fragment is missing.

        )r   r   r^   r   r   r   rL     s    zURL.fragmentc                 C   sl   | j j}|  r6|sdg}qddg|dd d }n.|drZdg|dd d }n
|d}t|S )zjA tuple containing encoded *path* parts.

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

        rV   r   N)r-   rJ   rX   ro   rm   tuple)r   rJ   rs   r   r   r   	raw_parts  s    

zURL.raw_partsc                    s   t  fdd jD S )zjA tuple containing decoded *path* parts.

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

        c                 3   s   | ]}  |V  qd S r    )r   ).0partr^   r   r   	<genexpr>3  s     zURL.parts.<locals>.<genexpr>)r   r   r^   r   r^   r   rs   ,  s    z	URL.partsc                 C   sp   | j }|r|dkr:| js| jr6t| jjdddddS | S |d}| jjd|dd ddd}t|ddS )	z]A new URL with last part of path removed and cleaned up query and
        fragment.

        rV   r   )rK   rL   TrP   Nrl   )r   r   r   r   r-   rY   ro   rq   )r   rJ   rs   r&   r   r   r   parent5  s    
 z
URL.parentc                 C   s8   | j }|  r,|dd }|s"dS |d S n|d S dS )zThe last part of raw_parts.r   Nr   r   )r   rX   )r   rs   r   r   r   raw_nameF  s    
zURL.raw_namec                 C   s   |  | jS )zThe last part of parts.)r   r   r^   r   r   r   r   S  s    zURL.namec              	   C   sz   | d}g }|D ]F}|dkrBz|  W qX tk
r>   Y qXX q|dkrNqq|| q|d dkrp|d d|S )NrV   ...r   r   r   r   )ro   pop
IndexErrorrp   rq   )rR   rJ   segmentsresolved_pathsegr   r   r   rE   X  s    

zURL._normalize_pathc                 C   s   z| d\}}}t|}W nR tk
rn   ztj|ddd}W n$ tk
rh   |dd}Y nX Y n.X |j}|r|d| 7 }|jdkrd| d }|S )	Nr   T)Zuts46r   r      [])		partitionr   r=   r   r5   r   r   
compressedversion)rR   rI   ipsepzoner   r   r   _encode_hostu  s    
zURL._encode_hostc                 C   s   |r|  |}n|}|r(|d t| }|r`|s6d}n|rD| |}|rR| |}|d | }n|rr|rr| |}|r|d | }|S )N:r   @)r   r<   _QUOTER)rR   rN   rB   rI   rC   r5   rd   r   r   r   r@     s$    


zURL._make_netlocc                 C   s<   t |tstd|  s"tdt| jj| dddS )z&Return a new URL with scheme replaced.zInvalid scheme typez3scheme replacement is not allowed for relative URLs)rM   TrP   )	r;   r<   r>   rX   r=   r   r-   rY   lower)r   rM   r   r   r   with_scheme  s
    
zURL.with_schemec              	   C   sr   | j }|dkrd}n$t|tr0| |}|j}ntd|  sHtdt| j j	| j
|||j|jdddddS )	zReturn a new URL with user replaced.

        Autoencode user if needed.

        Clear user/password if user is None.

        NzInvalid user typez1user replacement is not allowed for relative URLsFr4   rH   TrP   )r-   r;   r<   r   rB   r>   rX   r=   r   rY   r@   r?   rC   )r   rN   r&   rB   r   r   r   	with_user  s"    	

zURL.with_userc              	   C   sj   |dkr
nt |tr | |}ntd|  s8td| j}t| jj| j	|j
||j|jdddddS )	zReturn a new URL with password replaced.

        Autoencode password if needed.

        Clear password if argument is None.

        NzInvalid password typez5password replacement is not allowed for relative URLsFr4   r   TrP   )r;   r<   r   r>   rX   r=   r-   r   rY   r@   rA   r?   rC   )r   rB   r&   r   r   r   with_password  s&    	
zURL.with_passwordc              	   C   sj   t |tstd|  s"td|s.td| |}| j}t| jj| j	|j
|j||jdddddS )	zReturn a new URL with host replaced.

        Autoencode host if needed.

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

        zInvalid host typez1host replacement is not allowed for relative URLszhost removing is not allowedFr4   r   TrP   )r;   r<   r>   rX   r=   r   r-   r   rY   r@   rA   rB   rC   )r   rI   r&   r   r   r   	with_host  s"    


zURL.with_hostc              	   C   sf   |dk	r$t |ts$tdt||  s4td| j}t| jj	| j
|j|j|j|ddddd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 {}z1port replacement is not allowed for relative URLsFr4   r   TrP   )r;   intr>   r\   typerX   r=   r-   r   rY   r@   rA   rB   r?   )r   rC   r&   r   r   r   	with_port  s     zURL.with_portrP   c                C   sZ   |s |  |}|  r | |}t|dkr@|d dkr@d| }t| jj|dddddS )z$Return a new URL with path replaced.r   rV   r   rl   TrP   )rD   rX   rE   lenr   r-   rY   )r   rJ   r2   r   r   r   	with_path  s    

zURL.with_pathc                    s.  |rt |dkrtd|}nt |dkr4|d }ntd|d krJd}nt|tr| j g }| D ]R\}}t|trzn$t|tkrt|}nt	d
|| |d  |  qfd|}ndt|tr| |}nNt|tttfrt	dn4t|tr"| j d fd	d
|D }nt	d|S )Nr   z7Either kwargs or single query parameter must be presentr   r   zCInvalid variable type: mapping value should be str or int, got {!r}=&zAInvalid query type: bytes, bytearray and memoryview are forbiddenc                 3   s&   | ]\}} |d   | V  qdS )r   Nr   )r   kr   quoterr   r   r   >  s   z%URL._get_str_query.<locals>.<genexpr>zPInvalid query type: only str, mapping or sequence of (str, str) pairs is allowed)r   r=   r;   r   _QUERY_PART_QUOTERitemsr<   r   r   r>   r\   rp   rq   rF   bytes	bytearray
memoryviewr   )r   argskwargsrK   lstr   r   r   r   r   _get_str_query  sF    






zURL._get_str_queryc                 O   s(   | j ||}t| jj| jj|ddd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.

        It also can take an arbitrary number of keyword arguments.

        Clear query if None is passed.

        )rJ   rK   TrP   )r   r   r-   rY   rJ   )r   r   r   	new_queryr   r   r   rQ   F  s
    zURL.with_queryc                 O   sL   | j ||}tt|dd}t| j}|| t| jj|  |dddS )z)Return a new URL with query part updated.Tr   )rK   rP   )r   r
   r   rK   updater   r-   rY   )r   r   r   sr   rK   r   r   r   update_queryX  s    

zURL.update_queryc                 C   s<   |dkrd}nt |ts tdt| jj| |dddS )zReturn a new URL with fragment replaced.

        Autoencode fragment if needed.

        Clear fragment to default if None is passed.

        Nr   zInvalid fragment type)rL   TrP   )r;   r<   r>   r   r-   rY   rG   )r   rL   r   r   r   with_fragmentb  s    	
zURL.with_fragmentc                 C   s   t |tstdd|kr"td| |}|dkr<tdt| j}|  rxt|dkrf|	| n||d< d|d	< n||d< |d	 dkrd|d	< t
| jjd|ddd
ddS )zReturn a new URL with name (last part of path) replaced.

        Query and fragment parts are cleaned up.

        Name is encoded if needed.

        zInvalid name typerV   zSlash in name is not allowedr   z. and .. values are forbiddenr   r   r   r   rl   TrP   )r;   r<   r>   r=   rD   listr   rX   r   rp   r   r-   rY   rq   )r   r   rs   r   r   r   	with_namet  s.    	



 zURL.with_namec                 C   s,   t |tstdttt| t|dd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.

        zurl should be URLTrP   )r;   r   r>   r   r<   )r   rS   r   r   r   rq     s    
zURL.joinc              
   C   s6   t t| j| j| j| j| j| jjdd| j	| j
| jS )z<Return decoded human readable string for URL representation.Fr4   )r	   r   rM   r@   rN   rB   rI   r-   rC   rJ   rO   rL   r^   r   r   r   
human_repr  s    zURL.human_repr)r   )Hr   r*   r+   	__slots__r   r   rD   rF   r   rG   r   r   r   r   r   classmethodrT   r[   r_   rb   re   rh   ri   rj   rk   rt   ru   ry   rX   r}   r   r   propertyrM   r   r   rN   r   rB   rz   rI   rC   r   rJ   rK   r   rO   r   r   r   rL   r   rs   r   r   r   rE   r   r@   r   r   r   r   r   r   r   rQ   r   r   r   rq   r   r   r   r   r   r   >   s   F


'
   ,		








	

















+
r   )r9   collections.abcr   r   Z	ipaddressr   urllib.parser   r   r   r   r	   Z	multidictr
   r   r   Zquotingr   r   __version____all__r{   objectr,   r   r   r   r   r   r   <module>   s    