U
    }®cHc  ã                   @   s¾  d dl Z d dlZd dlZd dlZd dl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 d dlmZ d dlmZmZmZmZ d dlmZ d d	lmZmZ d d
lmZmZmZ d dl m!Z! d dl"m#Z#m$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. e*e	dƒ�r$e*e	dƒ�s0d dl'm	Z	 e/ƒ Z0e,dƒZ1G dd„ de2ƒZ3G dd„ de4ƒZ5G dd„ dƒZ6G dd„ deƒZ7G dd „ d eƒZ8G d!d"„ d"ƒZ9d#d$„ Z:d%d&„ Z;d'd(„ Z<d)d*„ Z=dS )+é    N)ÚBytesIO)Úchain)Ú	parse_qslÚquoteÚ	urlencodeÚurljoinÚurlsplit)Úsettings)Úsigning)ÚDisallowedHostÚImproperlyConfiguredÚRequestDataTooBigÚTooManyFieldsSent)Úuploadhandler)ÚMultiPartParserÚMultiPartParserError)ÚCaseInsensitiveMappingÚImmutableListÚMultiValueDict)ÚRemovedInDjango40Warning)Úescape_uri_pathÚ
iri_to_uri)Úcached_property©Úis_same_domain)Úfunc_supports_parameter)Ú_lazy_re_compileé   )Úparse_headerÚmax_num_fieldsÚ	separator)r   z1^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9\.:]+\])(:\d+)?$c                   @   s   e Zd ZdS )ÚUnreadablePostErrorN)Ú__name__Ú
__module__Ú__qualname__© r%   r%   ú7/tmp/pip-unpacked-wheel-7m9rsep5/django/http/request.pyr!   +   s   r!   c                   @   s   e Zd ZdZdS )ÚRawPostDataExceptionzŽ
    You cannot access raw_post_data from a request that has
    multipart/* POST data if it has been accessed via POST,
    FILES, etc..
    N)r"   r#   r$   Ú__doc__r%   r%   r%   r&   r'   /   s   r'   c                   @   s^  e Zd ZdZdZg Zdd„ Zdd„ Zedd„ ƒZ	ed	d
„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdGdd„ZdHdd„Zdd„ Zeddfdd„Zdd „ ZdId!d"„Zed#d$„ ƒZd%d&„ Zed'd(„ ƒZd)d*„ Zd+d,„ Zed-d.„ ƒZejd/d.„ ƒZd0d1„ Zed2d3„ ƒZ e jd4d3„ ƒZ d5d6„ Z!ed7d8„ ƒZ"d9d:„ Z#d;d<„ Z$d=d>„ Z%d?d@„ Z&dAdB„ Z'dCdD„ Z(dEdF„ Z)dS )JÚHttpRequestzA basic HTTP request.Nc                 C   sT   t dd�| _t dd�| _i | _i | _tƒ | _d| _d| _d | _	d | _
d | _d | _d S )NT)ÚmutableÚ )Ú	QueryDictÚGETÚPOSTÚCOOKIESÚMETAr   ZFILESÚpathÚ	path_infoÚmethodZresolver_matchÚcontent_typeÚcontent_params©Úselfr%   r%   r&   Ú__init__?   s    zHttpRequest.__init__c                 C   s6   | j d ks|  ¡ sd| jj S d| jj| j |  ¡ f S )Nz<%s>z<%s: %s %r>)r3   Úget_full_pathÚ	__class__r"   r6   r%   r%   r&   Ú__repr__Q   s    zHttpRequest.__repr__c                 C   s
   t | jƒS ©N)ÚHttpHeadersr0   r6   r%   r%   r&   ÚheadersV   s    zHttpRequest.headersc                 C   s   t | j dd¡ƒS )z%Return a list of MediaType instances.ÚAcceptz*/*)Úparse_accept_headerr>   Úgetr6   r%   r%   r&   Úaccepted_typesZ   s    zHttpRequest.accepted_typesc                    s   t ‡ fdd„| jD ƒƒS )Nc                 3   s   | ]}|  ˆ ¡V  qd S r<   )Úmatch)Ú.0Zaccepted_type©Ú
media_typer%   r&   Ú	<genexpr>`   s   ÿz&HttpRequest.accepts.<locals>.<genexpr>)ÚanyrB   )r7   rF   r%   rE   r&   Úaccepts_   s    þzHttpRequest.acceptsc                 C   s^   t  | dd¡¡\| _| _d| jkrZzt | jd ¡ W n tk
rL   Y nX | jd | _dS )z/Set content_type, content_params, and encoding.ÚCONTENT_TYPEr+   ÚcharsetN)	Úcgir   rA   r4   r5   ÚcodecsÚlookupÚLookupErrorÚencoding)r7   Úmetar%   r%   r&   Ú_set_content_type_paramse   s    
z$HttpRequest._set_content_type_paramsc                 C   sh   t jrd| jkr| jd }nHd| jkr2| jd }n2| jd }|  ¡ }||  ¡ rRdndkrdd||f }|S )z—
        Return the HTTP host using the environment or request headers. Skip
        allowed hosts protection, so may return an insecure host.
        ZHTTP_X_FORWARDED_HOSTZ	HTTP_HOSTZSERVER_NAMEÚ443Ú80z%s:%s)r	   ZUSE_X_FORWARDED_HOSTr0   Úget_portÚ	is_secure)r7   ÚhostZserver_portr%   r%   r&   Ú_get_raw_hostp   s    ÿ

zHttpRequest._get_raw_hostc                 C   sn   |   ¡ }tj}tjr"|s"dddg}t|ƒ\}}|r@t||ƒr@|S d| }|rZ|d| 7 }n|d7 }t|ƒ‚dS )z>Return the HTTP host using the environment or request headers.z
.localhostz	127.0.0.1z[::1]zInvalid HTTP_HOST header: %r.z) You may need to add %r to ALLOWED_HOSTS.zB The domain name provided is not valid according to RFC 1034/1035.N)rX   r	   ZALLOWED_HOSTSÚDEBUGÚsplit_domain_portÚvalidate_hostr   )r7   rW   Úallowed_hostsÚdomainÚportÚmsgr%   r%   r&   Úget_hostƒ   s    

zHttpRequest.get_hostc                 C   s.   t jrd| jkr| jd }n
| jd }t|ƒS )z3Return the port number for the request as a string.ZHTTP_X_FORWARDED_PORTZSERVER_PORT)r	   ZUSE_X_FORWARDED_PORTr0   Ústr)r7   r^   r%   r%   r&   rU   —   s    
zHttpRequest.get_portFc                 C   s   |   | j|¡S r<   )Ú_get_full_pathr1   ©r7   Úforce_append_slashr%   r%   r&   r9   Ÿ   s    zHttpRequest.get_full_pathc                 C   s   |   | j|¡S r<   )rb   r2   rc   r%   r%   r&   Úget_full_path_info¢   s    zHttpRequest.get_full_path_infoc              	   C   sH   dt |ƒ|r| d¡sdnd| j dd¡r@dt| j dd¡ƒ ndf S )Nú%s%s%sú/r+   ÚQUERY_STRINGú?)r   Úendswithr0   rA   r   )r7   r1   rd   r%   r%   r&   rb   ¥   s
    &ýzHttpRequest._get_full_pathr+   c                 C   s‚   z| j | }W n& tk
r4   |tk	r.| Y S ‚ Y nX ztj|| d�j||d�}W n( tjk
r|   |tk	rv| Y S ‚ Y nX |S )z×
        Attempt to return a signed cookie. If the signature fails or the
        cookie has expired, raise an exception, unless the `default` argument
        is provided,  in which case return that value.
        )Úsalt)Úmax_age)r/   ÚKeyErrorÚRAISE_ERRORr
   Zget_cookie_signerZunsignZBadSignature)r7   ÚkeyÚdefaultrk   rl   Zcookie_valueÚvaluer%   r%   r&   Úget_signed_cookie®   s      ÿ
zHttpRequest.get_signed_cookiec                 C   s   dj | j|  ¡ |  ¡ d�S )z•
        Return an absolute URI from variables available in this request. Skip
        allowed hosts protection, so may return insecure URI.
        z{scheme}://{host}{path})ÚschemerW   r1   )Úformatrs   rX   r9   r6   r%   r%   r&   Úget_raw_uriÅ   s
    ýzHttpRequest.get_raw_uric                 C   sš   |dkrd|   ¡  }nt|ƒ}t|ƒ}|jr2|js’|j d¡r€|js€|js€d|jkr€d|jkr€| d¡rt|dd… }| j| }nt| j| j |ƒ}t	|ƒS )aÆ  
        Build an absolute URI from the location and the variables available in
        this request. If no ``location`` is specified, build the absolute URI
        using request.get_full_path(). If the location is absolute, convert it
        to an RFC 3987 compliant URI and return it. If location is relative or
        is scheme-relative (i.e., ``//example.com/``), urljoin() it to a base
        URL constructed from the request variables.
        Nz//%srg   z/./z/../z//é   )
r9   ra   r   rs   Únetlocr1   Ú
startswithÚ_current_scheme_hostr   r   )r7   ÚlocationÚbitsr%   r%   r&   Úbuild_absolute_uriÐ   s    	ÿÿ
zHttpRequest.build_absolute_uric                 C   s   d  | j|  ¡ ¡S )Nz{}://{})rt   rs   r`   r6   r%   r%   r&   ry   ô   s    z HttpRequest._current_scheme_hostc                 C   s   dS )zf
        Hook for subclasses like WSGIRequest to implement. Return 'http' by
        default.
        Úhttpr%   r6   r%   r%   r&   Ú_get_schemeø   s    zHttpRequest._get_schemec                 C   s^   t jrVzt j\}}W n tk
r0   tdƒ‚Y nX | j |¡}|d k	rV||krRdS dS |  ¡ S )NzJThe SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.Úhttpsr}   )r	   ZSECURE_PROXY_SSL_HEADERÚ
ValueErrorr   r0   rA   r~   )r7   ÚheaderZsecure_valueÚheader_valuer%   r%   r&   rs   ÿ   s    ÿ
zHttpRequest.schemec                 C   s
   | j dkS )Nr   )rs   r6   r%   r%   r&   rV     s    zHttpRequest.is_securec                 C   s    t jdtdd� | j d¡dkS )Nzfrequest.is_ajax() is deprecated. See Django 3.1 release notes for more details about this deprecation.rv   )Ú
stacklevelZHTTP_X_REQUESTED_WITHZXMLHttpRequest)ÚwarningsÚwarnr   r0   rA   r6   r%   r%   r&   Úis_ajax  s    üzHttpRequest.is_ajaxc                 C   s   | j S r<   ©Ú	_encodingr6   r%   r%   r&   rP     s    zHttpRequest.encodingc                 C   s&   || _ t| dƒr| `t| dƒr"| `dS )zÓ
        Set the encoding used for GET/POST accesses. If the GET or POST
        dictionary has already been created, remove and recreate it on the
        next access (so that it is decoded correctly).
        r-   Ú_postN)rˆ   Úhasattrr-   r‰   )r7   Úvalr%   r%   r&   rP     s
    

c                    s   ‡ fdd„t jD ƒˆ _d S )Nc                    s   g | ]}t  |ˆ ¡‘qS r%   )r   Zload_handler)rD   Úhandlerr6   r%   r&   Ú
<listcomp>+  s   ÿz4HttpRequest._initialize_handlers.<locals>.<listcomp>)r	   ZFILE_UPLOAD_HANDLERSÚ_upload_handlersr6   r%   r6   r&   Ú_initialize_handlers*  s    
ÿz HttpRequest._initialize_handlersc                 C   s   | j s|  ¡  | j S r<   )rŽ   r�   r6   r%   r%   r&   Úupload_handlers.  s    zHttpRequest.upload_handlersc                 C   s   t | dƒrtdƒ‚|| _d S )NÚ_fileszGYou cannot set the upload handlers after the upload has been processed.)rŠ   ÚAttributeErrorrŽ   )r7   r�   r%   r%   r&   r�   5  s    
c                 C   s*   t | jdd�| _t||| j| jƒ}| ¡ S )z9Return a tuple of (POST QueryDict, FILES MultiValueDict).zEYou cannot alter upload handlers after the upload has been processed.)Úwarning)r   r�   r   rP   Úparse)r7   r0   Z	post_dataÚparserr%   r%   r&   Úparse_file_upload;  s    þzHttpRequest.parse_file_uploadc              
   C   s”   t | dƒsŽ| jrtdƒ‚tjd k	rDt| j d¡p2dƒtjkrDtdƒ‚z|  	¡ | _
W n. tk
r€ } zt|jŽ |‚W 5 d }~X Y nX t| j
ƒ| _| j
S )NÚ_bodyz?You cannot access body after reading from request's data streamÚCONTENT_LENGTHr   z;Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE.)rŠ   Ú_read_startedr'   r	   ZDATA_UPLOAD_MAX_MEMORY_SIZEÚintr0   rA   r   Úreadr—   ÚOSErrorr!   Úargsr   Ú_stream)r7   Úer%   r%   r&   ÚbodyD  s    

ÿzHttpRequest.bodyc                 C   s   t ƒ | _tƒ | _d S r<   )r,   r‰   r   r‘   r6   r%   r%   r&   Ú_mark_post_parse_errorV  s    z"HttpRequest._mark_post_parse_errorc                 C   sæ   | j dkr&t| jd�tƒ  | _| _dS | jrBt| dƒsB|  ¡  dS | j	dkr¢t| dƒrbt
| jƒ}n| }z|  | j|¡\| _| _W qâ tk
rž   |  ¡  ‚ Y qâX n@| j	dkrÊt| j| jd�tƒ  | _| _nt| jd�tƒ  | _| _dS )zFPopulate self._post and self._files if the content-type is a form typer.   )rP   Nr—   zmultipart/form-dataz!application/x-www-form-urlencoded)r3   r,   rˆ   r   r‰   r‘   r™   rŠ   r¡   r4   r   r—   r–   r0   r   r    )r7   Údatar%   r%   r&   Ú_load_post_and_filesZ  s$    




z HttpRequest._load_post_and_filesc                 C   s6   t | dƒr2t dd„ | j ¡ D ƒ¡D ]}| ¡  q$d S )Nr‘   c                 s   s   | ]}|d  V  qdS )r   Nr%   )rD   Úlist_r%   r%   r&   rG   y  s     z$HttpRequest.close.<locals>.<genexpr>)rŠ   r   Úfrom_iterabler‘   ÚlistsÚclose)r7   Úfr%   r%   r&   r§   w  s    
zHttpRequest.closec              
   O   sJ   d| _ z| jj||ŽW S  tk
rD } zt|jŽ |‚W 5 d }~X Y nX d S ©NT)r™   rž   r›   rœ   r!   r�   ©r7   r�   ÚkwargsrŸ   r%   r%   r&   r›   „  s
    zHttpRequest.readc              
   O   sJ   d| _ z| jj||ŽW S  tk
rD } zt|jŽ |‚W 5 d }~X Y nX d S r©   )r™   rž   Úreadlinerœ   r!   r�   rª   r%   r%   r&   r¬   ‹  s
    zHttpRequest.readlinec                 C   s   t | jdƒS )Nó    )Úiterr¬   r6   r%   r%   r&   Ú__iter__’  s    zHttpRequest.__iter__c                 C   s   t | ƒS r<   )Úlistr6   r%   r%   r&   Ú	readlines•  s    zHttpRequest.readlines)F)F)N)*r"   r#   r$   r(   rˆ   rŽ   r8   r;   r   r>   rB   rI   rR   rX   r`   rU   r9   re   rb   rn   rr   ru   r|   ry   r~   Úpropertyrs   rV   r†   rP   Úsetterr�   r�   r–   r    r¡   r£   r§   r›   r¬   r¯   r±   r%   r%   r%   r&   r)   8   s\   



	
$

	



	
r)   c                       s@   e Zd ZdZddhZ‡ fdd„Z‡ fdd„Zedd	„ ƒZ‡  Z	S )
r=   ZHTTP_rJ   r˜   c                    s<   i }|  ¡ D ]\}}|  |¡}|r|||< qtƒ  |¡ d S r<   )ÚitemsÚparse_header_nameÚsuperr8   )r7   Úenvironr>   r�   rq   Úname©r:   r%   r&   r8   ž  s    

zHttpHeaders.__init__c                    s   t ƒ  | dd¡¡S )z:Allow header lookup using underscores in place of hyphens.Ú_ú-)r¶   Ú__getitem__Úreplace©r7   ro   r¹   r%   r&   r¼   ¦  s    zHttpHeaders.__getitem__c                 C   s>   |  | j¡r |t| jƒd … }n|| jkr.d S | dd¡ ¡ S )Nrº   r»   )rx   ÚHTTP_PREFIXÚlenÚUNPREFIXED_HEADERSr½   Útitle)Úclsr�   r%   r%   r&   rµ   ª  s
    
zHttpHeaders.parse_header_name)
r"   r#   r$   r¿   rÁ   r8   r¼   Úclassmethodrµ   Ú__classcell__r%   r%   r¹   r&   r=   ™  s   r=   c                       sì   e Zd ZdZdZdZd)‡ fdd„	Zed*dd	„ƒZe	d
d„ ƒZ
e
jdd„ ƒZ
dd„ Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Z‡ fdd„Zd+‡ fdd„	Z‡ fdd„Z‡ fdd„Z‡ fdd „Z‡ fd!d"„Zd,‡ fd#d$„	Zd%d&„ Zd-d'd(„Z‡  ZS ).r,   aû  
    A specialized MultiValueDict which represents a query string.

    A QueryDict can be used to represent GET or POST data. It subclasses
    MultiValueDict since keys in such data can be repeated, for instance
    in the data from a form with a <select multiple> field.

    By default QueryDicts are immutable, though the copy() method
    will always return a mutable copy.

    Both keys and values set on this class are converted from the given encoding
    (DEFAULT_CHARSET by default) to str.
    TNFc              
      sÆ   t ƒ  ¡  |ptj| _|pd}d| jtjdœ}t|tƒrhz| | j¡}W n t	k
rf   | d¡}Y nX z&t
|f|ŽD ]\}}|  ||¡ qvW n, tk
rº } ztdƒ|‚W 5 d }~X Y nX || _d S )Nr+   T)Úkeep_blank_valuesrP   r   z
iso-8859-1zRThe number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.)r¶   r8   r	   ÚDEFAULT_CHARSETrP   ZDATA_UPLOAD_MAX_NUMBER_FIELDSÚ
isinstanceÚbytesÚdecodeÚUnicodeDecodeErrorr   Ú
appendlistr€   r   Ú_mutable)r7   Zquery_stringr*   rP   Zparse_qsl_kwargsro   rq   rŸ   r¹   r%   r&   r8   Ç  s,    
ý
ÿýzQueryDict.__init__r+   c                 C   s2   | dd|d�}|D ]}|  ||¡ q|s.d|_|S )zt
        Return a new QueryDict with keys (may be repeated) from an iterable and
        values from value.
        r+   T©r*   rP   F)rÌ   rÍ   )rÃ   Úiterablerq   r*   rP   Úqro   r%   r%   r&   Úfromkeyså  s    zQueryDict.fromkeysc                 C   s   | j d krtj| _ | j S r<   )rˆ   r	   rÇ   r6   r%   r%   r&   rP   ò  s    
zQueryDict.encodingc                 C   s
   || _ d S r<   r‡   )r7   rq   r%   r%   r&   rP   ø  s    c                 C   s   | j stdƒ‚d S )Nz$This QueryDict instance is immutable)rÍ   r’   r6   r%   r%   r&   Ú_assert_mutableü  s    zQueryDict._assert_mutablec                    s2   |   ¡  t|| jƒ}t|| jƒ}tƒ  ||¡ d S r<   )rÒ   Úbytes_to_textrP   r¶   Ú__setitem__©r7   ro   rq   r¹   r%   r&   rÔ      s    zQueryDict.__setitem__c                    s   |   ¡  tƒ  |¡ d S r<   )rÒ   r¶   Ú__delitem__r¾   r¹   r%   r&   rÖ     s    zQueryDict.__delitem__c                 C   s4   | j dd| jd�}|  ¡ D ]\}}| ||¡ q|S ©Nr+   TrÎ   )r:   rP   r¦   Úsetlist)r7   Úresultro   rq   r%   r%   r&   Ú__copy__
  s    zQueryDict.__copy__c                 C   sP   | j dd| jd�}||t| ƒ< |  ¡ D ]$\}}| t ||¡t ||¡¡ q&|S r×   )r:   rP   Úidr¦   rØ   ÚcopyÚdeepcopy)r7   ÚmemorÙ   ro   rq   r%   r%   r&   Ú__deepcopy__  s
    zQueryDict.__deepcopy__c                    s8   ˆ   ¡  t|ˆ jƒ}‡ fdd„|D ƒ}tƒ  ||¡ d S )Nc                    s   g | ]}t |ˆ jƒ‘qS r%   )rÓ   rP   )rD   Úeltr6   r%   r&   r�     s     z%QueryDict.setlist.<locals>.<listcomp>)rÒ   rÓ   rP   r¶   rØ   )r7   ro   r¤   r¹   r6   r&   rØ     s    zQueryDict.setlistc                    s   |   ¡  tƒ  ||¡S r<   )rÒ   r¶   Úsetlistdefault)r7   ro   Zdefault_listr¹   r%   r&   rá     s    zQueryDict.setlistdefaultc                    s2   |   ¡  t|| jƒ}t|| jƒ}tƒ  ||¡ d S r<   )rÒ   rÓ   rP   r¶   rÌ   rÕ   r¹   r%   r&   rÌ   !  s    zQueryDict.appendlistc                    s   |   ¡  tƒ j|f|žŽ S r<   )rÒ   r¶   Úpop)r7   ro   r�   r¹   r%   r&   râ   '  s    zQueryDict.popc                    s   |   ¡  tƒ  ¡ S r<   )rÒ   r¶   Úpopitemr6   r¹   r%   r&   rã   +  s    zQueryDict.popitemc                    s   |   ¡  tƒ  ¡  d S r<   )rÒ   r¶   Úclearr6   r¹   r%   r&   rä   /  s    zQueryDict.clearc                    s.   |   ¡  t|| jƒ}t|| jƒ}tƒ  ||¡S r<   )rÒ   rÓ   rP   r¶   Ú
setdefault)r7   ro   rp   r¹   r%   r&   rå   3  s    zQueryDict.setdefaultc                 C   s
   |   i ¡S )z%Return a mutable copy of this object.)rß   r6   r%   r%   r&   rÜ   9  s    zQueryDict.copyc                    sb   g }ˆr"ˆ  ˆj¡‰‡fdd„‰ ndd„ ‰ ˆ ¡ D ]$\‰}| ‡ ‡‡fdd„|D ƒ¡ q2d |¡S )ah  
        Return an encoded string of all query string arguments.

        `safe` specifies characters which don't require quoting, for example::

            >>> q = QueryDict(mutable=True)
            >>> q['next'] = '/a&b/'
            >>> q.urlencode()
            'next=%2Fa%26b%2F'
            >>> q.urlencode(safe='/')
            'next=/a%26b/'
        c                    s   dt | ˆ ƒt |ˆ ƒf S )Nz%s=%s)r   ©ÚkÚv)Úsafer%   r&   ÚencodeN  s    z#QueryDict.urlencode.<locals>.encodec                 S   s   t | |iƒS r<   )r   ræ   r%   r%   r&   rê   Q  s    c                 3   s,   | ]$}ˆ ˆ  ˆj¡t|ƒ  ˆj¡ƒV  qd S r<   )rê   rP   ra   )rD   rè   )rê   rç   r7   r%   r&   rG   T  s   ÿz&QueryDict.urlencode.<locals>.<genexpr>ú&)rê   rP   r¦   ÚextendÚjoin)r7   ré   Úoutputr¤   r%   )rê   rç   ré   r7   r&   r   =  s    þ
zQueryDict.urlencode)NFN)r+   FN)N)N)N)r"   r#   r$   r(   rÍ   rˆ   r8   rÄ   rÑ   r²   rP   r³   rÒ   rÔ   rÖ   rÚ   rß   rØ   rá   rÌ   râ   rã   rä   rå   rÜ   r   rÅ   r%   r%   r¹   r&   r,   ³  s0   

r,   c                   @   s8   e Zd Zdd„ Zdd„ Zdd„ Zedd„ ƒZd	d
„ ZdS )Ú	MediaTypec                 C   s4   t |r| d¡ndƒ\}| _| d¡\| _}| _d S )NÚasciir­   rg   )r   rê   ÚparamsÚ	partitionÚ	main_typeÚsub_type)r7   Zmedia_type_raw_lineZ	full_typerº   r%   r%   r&   r8   \  s    ÿ
zMediaType.__init__c                 C   s:   d  dd„ | j ¡ D ƒ¡}d| j| jr0d| j nd|f S )Nr+   c                 s   s$   | ]\}}d ||  d¡f V  qdS )z; %s=%srð   N)rÊ   )rD   rç   rè   r%   r%   r&   rG   c  s   ÿz$MediaType.__str__.<locals>.<genexpr>rf   z/%s)rí   rñ   r´   ró   rô   )r7   Z
params_strr%   r%   r&   Ú__str__b  s    
þýzMediaType.__str__c                 C   s   d| j j| f S )Nz<%s: %s>)r:   r$   r6   r%   r%   r&   r;   m  s    zMediaType.__repr__c                 C   s   | j dko| jdkS )NÚ*)ró   rô   r6   r%   r%   r&   Úis_all_typesp  s    zMediaType.is_all_typesc                 C   s6   | j r
dS t|ƒ}| j|jkr2| jd|jhkr2dS dS )NTrö   F)r÷   rï   ró   rô   )r7   Úotherr%   r%   r&   rC   t  s    zMediaType.matchN)	r"   r#   r$   r8   rõ   r;   r²   r÷   rC   r%   r%   r%   r&   rï   [  s   
rï   c                 C   s   t | tƒrt| |dƒS | S dS )u×   
    Convert bytes objects to strings, using the given encoding. Illegally
    encoded input characters are replaced with Unicode "unknown" codepoint
    (ï¿½).

    Return any non-bytes objects without change.
    r½   N)rÈ   rÉ   ra   )ÚsrP   r%   r%   r&   rÓ   €  s    
rÓ   c                 C   sx   |   ¡ } t | ¡sdS | d dkr*| dfS |  dd¡}t|ƒdkrF|n
|d df\}}| d	¡rl|d
d… n|}||fS )z”
    Return a (domain, port) tuple from a given host.

    Returned domain is lowercased. If the host is invalid, the domain will be
    empty.
    )r+   r+   éÿÿÿÿú]r+   ú:r   rv   r   Ú.N)ÚlowerÚhost_validation_rerC   ÚrsplitrÀ   rj   )rW   r{   r]   r^   r%   r%   r&   rZ   Ž  s    
 rZ   c                    s   t ‡ fdd„|D ƒƒS )a4  
    Validate the given host for this site.

    Check that the host looks valid and matches a host or host pattern in the
    given list of ``allowed_hosts``. Any pattern beginning with a period
    matches a domain and all its subdomains (e.g. ``.example.com`` matches
    ``example.com`` and any subdomain), ``*`` matches anything, and anything
    else must match exactly.

    Note: This function assumes that the given host is lowercased and has
    already had the port, if any, stripped off.

    Return ``True`` for a valid host, ``False`` otherwise.
    c                 3   s    | ]}|d kpt ˆ |ƒV  qdS )rö   Nr   )rD   Úpattern©rW   r%   r&   rG   ³  s     z validate_host.<locals>.<genexpr>)rH   )rW   r\   r%   r  r&   r[   ¤  s    r[   c                 C   s   dd„ |   d¡D ƒS )Nc                 S   s   g | ]}|  ¡ rt|ƒ‘qS r%   )Ústriprï   )rD   Útokenr%   r%   r&   r�   ·  s      z'parse_accept_header.<locals>.<listcomp>ú,)Úsplit)r�   r%   r%   r&   r@   ¶  s    r@   )>rL   rM   rÜ   r„   Úior   Ú	itertoolsr   Úurllib.parser   r   r   r   r   Zdjango.confr	   Zdjango.corer
   Zdjango.core.exceptionsr   r   r   r   Zdjango.core.filesr   Zdjango.http.multipartparserr   r   Zdjango.utils.datastructuresr   r   r   Zdjango.utils.deprecationr   Zdjango.utils.encodingr   r   Zdjango.utils.functionalr   Zdjango.utils.httpr   Zdjango.utils.inspectr   Zdjango.utils.regex_helperr   Zmultipartparserr   Úobjectrn   rÿ   rœ   r!   Ú	Exceptionr'   r)   r=   r,   rï   rÓ   rZ   r[   r@   r%   r%   r%   r&   Ú<module>   sN   ÿþ	  c )%