o
    þÞhÜp  ã                   @   sr  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mZ d dlmZ d d	lmZmZmZ d d
lmZmZm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z'm(Z( d dl)m*Z* e+ƒ Z,e*dƒZ-G dd„ de.ƒZ/G dd„ de0ƒZ1G dd„ dƒZ2G dd„ deƒZ3G dd„ de ƒZ4G dd„ dƒZ5dd„ Z6dd„ Z7d d!„ Z8dS )"é    N)ÚBytesIO)Úchain)Ú	parse_qslÚquoteÚ	urlencodeÚurljoinÚurlsplit)Úsettings)Úsigning)Ú
BadRequestÚDisallowedHostÚImproperlyConfiguredÚRequestDataTooBigÚTooManyFieldsSent)Úuploadhandler)ÚMultiPartParserÚMultiPartParserErrorÚTooManyFilesSent)ÚCaseInsensitiveMappingÚImmutableListÚMultiValueDict)Úescape_uri_pathÚ
iri_to_uri)Úcached_property)Úis_same_domainÚparse_header_parameters)Ú_lazy_re_compilez7^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9.:]+\])(?::([0-9]+))?$c                   @   s   e Zd ZdS )ÚUnreadablePostErrorN)Ú__name__Ú
__module__Ú__qualname__© r!   r!   úS/var/www/html/premium_crap/venv/lib/python3.10/site-packages/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                   @   sj  e Zd ZdZdZg Zdd„ Zdd„ Ze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dd„ Zdd„ ZdIdd„ZdIdd„Zd d!„ Zed"dfd#d$„ZdJd%d&„Zed'd(„ ƒZd)d*„ Zed+d,„ ƒZd-d.„ Zed/d0„ ƒZejd1d0„ ƒZd2d3„ Z ed4d5„ ƒZ!e!jd6d5„ ƒZ!d7d8„ Z"ed9d:„ ƒZ#d;d<„ Z$d=d>„ Z%d?d@„ Z&dAdB„ Z'dCdD„ Z(dEdF„ Z)dGdH„ Z*dS )KÚ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   ÚFILESÚpathÚ	path_infoÚmethodÚresolver_matchÚcontent_typeÚcontent_params©Úselfr!   r!   r"   Ú__init__<   s   
zHttpRequest.__init__c                 C   s6   | j d u s	|  ¡ sd| jj S d| jj| j |  ¡ f S )Nz<%s>z<%s: %s %r>)r0   Úget_full_pathÚ	__class__r   r4   r!   r!   r"   Ú__repr__N   s   ýzHttpRequest.__repr__c                 C   s
   t | jƒS ©N)ÚHttpHeadersr,   r4   r!   r!   r"   ÚheadersW   ó   
zHttpRequest.headersc                    s8   | j  dd¡}t‡ fdd„| d¡D ƒt dd¡dd	�S )
zGReturn a list of MediaType instances, in order of preference (quality).ÚAcceptz*/*c                 3   s.   � | ]}|  ¡ rt|ƒ ‰ jd krˆ V  qdS )r   N)ÚstripÚ	MediaTypeÚquality)Ú.0Útoken©Ú
media_typer!   r"   Ú	<genexpr>`   s   € ýþýz-HttpRequest.accepted_types.<locals>.<genexpr>ú,rA   ÚspecificityT©ÚkeyÚreverse)r<   ÚgetÚsortedÚsplitÚoperatorÚ
attrgetter)r5   Úheader_valuer!   rD   r"   Úaccepted_types[   s   
þ
ùzHttpRequest.accepted_typesc                 C   s   t | jt dd¡dd�S )z]
        Return a list of MediaType instances, in order of precedence (specificity).
        rH   rA   TrI   )rM   rR   rO   rP   r4   r!   r!   r"   Úaccepted_types_by_precedencei   s
   
ýz(HttpRequest.accepted_types_by_precedencec                    s"   t ˆ ƒ‰ t‡ fdd„| jD ƒdƒS )zX
        Return the MediaType instance which best matches the given media type.
        c                 3   s   � | ]
}ˆ   |¡r|V  qd S r:   )Úmatch)rB   Úaccepted_typerD   r!   r"   rF   z   s   € ý
ÿz,HttpRequest.accepted_type.<locals>.<genexpr>N)r@   ÚnextrS   ©r5   rE   r!   rD   r"   rU   t   s   
þúzHttpRequest.accepted_typec                    sB   |rˆj sdS ‡ ‡fdd„|D ƒ}|sdS t|‡fdd„d�d S )z:Select the preferred media type from the provided options.Nc                    s&   g | ]}ˆ  |¡ ‰ d urˆ |f‘qS r:   ©rU   )rB   rE   ©rU   r5   r!   r"   Ú
<listcomp>‡   s
    þz2HttpRequest.get_preferred_type.<locals>.<listcomp>c                    s   ˆ j  | d ¡S )Nr   )rR   Úindex)Útr4   r!   r"   Ú<lambda>‘   s    z0HttpRequest.get_preferred_type.<locals>.<lambda>)rJ   é   )rR   Úmin)r5   Úmedia_typesÚdesired_typesr!   rY   r"   Úget_preferred_type‚   s   
þzHttpRequest.get_preferred_typec                 C   s   |   |¡duS )z:Does the client accept a response in the given media type?NrX   rW   r!   r!   r"   Úaccepts“   s   zHttpRequest.acceptsc                 C   s`   t | dd¡ƒ\| _| _d| jv r.z
t | jd ¡ W n
 ty%   Y dS w | jd | _dS dS )z/Set content_type, content_params, and encoding.ÚCONTENT_TYPEr'   ÚcharsetN)r   rL   r2   r3   ÚcodecsÚlookupÚLookupErrorÚencoding)r5   Úmetar!   r!   r"   Ú_set_content_type_params—   s   
ÿ
ÿúz$HttpRequest._set_content_type_paramsc                 C   sl   t jrd| jv r| jd }|S d| jv r| jd }|S | jd }|  ¡ }||  ¡ r+dndkr4d||f }|S )z—
        Return the HTTP host using the environment or request headers. Skip
        allowed hosts protection, so may return an insecure host.
        ÚHTTP_X_FORWARDED_HOSTÚ	HTTP_HOSTÚSERVER_NAMEÚ443Ú80z%s:%s)r	   ÚUSE_X_FORWARDED_HOSTr,   Úget_portÚ	is_secure)r5   ÚhostÚserver_portr!   r!   r"   Ú_get_raw_host¤   s   
	
ø

üzHttpRequest._get_raw_hostc                 C   sn   |   ¡ }tj}tjr|sg d¢}t|ƒ\}}|rt||ƒr|S d| }|r/|d| 7 }t|ƒ‚|d7 }t|ƒ‚)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.)rv   r	   ÚALLOWED_HOSTSÚDEBUGÚsplit_domain_portÚvalidate_hostr   )r5   rt   Úallowed_hostsÚdomainÚportÚmsgr!   r!   r"   Úget_host¶   s   
ýÿzHttpRequest.get_hostc                 C   s4   t jrd| jv r| jd }t|ƒS | jd }t|ƒS )z3Return the port number for the request as a string.ÚHTTP_X_FORWARDED_PORTÚSERVER_PORT)r	   ÚUSE_X_FORWARDED_PORTr,   Ústr)r5   r}   r!   r!   r"   rr   Ì   s
   

ÿzHttpRequest.get_portFc                 C   ó   |   | j|¡S r:   )Ú_get_full_pathr.   ©r5   Úforce_append_slashr!   r!   r"   r7   Ô   ó   zHttpRequest.get_full_pathc                 C   r„   r:   )r…   r/   r†   r!   r!   r"   Úget_full_path_info×   rˆ   zHttpRequest.get_full_path_infoc              	   C   sL   dt |ƒ|r| d¡sdnd| j dd¡r"dt| j dd¡ƒ f S df S )Nú%s%s%sú/r'   ÚQUERY_STRINGú?)r   Úendswithr,   rL   r   )r5   r.   r‡   r!   r!   r"   r…   Ú   s   ÿüúzHttpRequest._get_full_pathr'   c                 C   st   z| j | }W n ty   |tur| Y S ‚ w ztj|| d�j||d�}W |S  tjy9   |tur8| Y S ‚ w )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
   Úget_cookie_signerÚunsignÚBadSignature)r5   rJ   Údefaultr�   r�   Úcookie_valueÚvaluer!   r!   r"   Úget_signed_cookieç   s"   üÿûüzHttpRequest.get_signed_cookiec                 C   s�   |du rd|   ¡  }nt|ƒ}t|ƒ}|jr|jsD|j d¡r;|js;|js;d|jvr;d|jvr;| j| d¡ }t
|ƒS 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//%sr‹   z/./z/../z//)r7   rƒ   r   ÚschemeÚnetlocr.   Ú
startswithÚ_current_scheme_hostÚremoveprefixr   r   )r5   ÚlocationÚbitsr!   r!   r"   Úbuild_absolute_uriÿ   s"   	
ÿþý

ÿzHttpRequest.build_absolute_uric                 C   s   d  | j|  ¡ ¡S )Nz{}://{})Úformatrš   r   r4   r!   r!   r"   r�   &  s   z HttpRequest._current_scheme_hostc                 C   s   dS )zf
        Hook for subclasses like WSGIRequest to implement. Return 'http' by
        default.
        Úhttpr!   r4   r!   r!   r"   Ú_get_scheme*  s   zHttpRequest._get_schemec                 C   sl   t jr2zt j\}}W n ty   tdƒ‚w | j |¡}|d ur2| dd¡^}}| ¡ |kr0dS dS |  ¡ S )NzJThe SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.rG   r^   Úhttpsr£   )	r	   ÚSECURE_PROXY_SSL_HEADERÚ
ValueErrorr   r,   rL   rN   r?   r¤   )r5   ÚheaderÚsecure_valuerQ   Ú_r!   r!   r"   rš   1  s   ÿÿzHttpRequest.schemec                 C   s
   | j dkS )Nr¥   )rš   r4   r!   r!   r"   rs   A  s   
zHttpRequest.is_securec                 C   s   | j S r:   ©Ú	_encodingr4   r!   r!   r"   ri   D  s   zHttpRequest.encodingc                 C   s*   || _ t| dƒr
| `t| dƒr| `dS 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­   )r5   Úvalr!   r!   r"   ri   H  s   

ÿc                    s   ‡ fdd„t jD ƒˆ _d S )Nc                    s   g | ]}t  |ˆ ¡‘qS r!   )r   Úload_handler)rB   Úhandlerr4   r!   r"   rZ   V  s    
ÿÿz4HttpRequest._initialize_handlers.<locals>.<listcomp>)r	   ÚFILE_UPLOAD_HANDLERSÚ_upload_handlersr4   r!   r4   r"   Ú_initialize_handlersU  s   
þz HttpRequest._initialize_handlersc                 C   s   | j s|  ¡  | j S r:   )r³   r´   r4   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³   )r5   rµ   r!   r!   r"   rµ   b  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   ri   Úparse)r5   r,   Ú	post_dataÚparserr!   r!   r"   Úparse_file_uploadk  s   ýzHttpRequest.parse_file_uploadc              
   C   s¦   t | dƒsP| jrtdƒ‚tjd ur"t| j d¡pdƒtjkr"tdƒ‚z!z|  	¡ | _
W n ty< } zt|jŽ |‚d }~ww W | j ¡  n| j ¡  w 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	   ÚDATA_UPLOAD_MAX_MEMORY_SIZEÚintr,   rL   r   Úreadr½   ÚOSErrorr   ÚargsÚ_streamÚcloser   )r5   Úer!   r!   r"   Úbodyw  s,   
ÿ
ÿÿ€ÿÿzHttpRequest.bodyc                 C   s   t ƒ | _tƒ | _d S r:   )r(   r­   r   r¶   r4   r!   r!   r"   Ú_mark_post_parse_error’  s   z"HttpRequest._mark_post_parse_errorc              	   C   s  | j dkrt| jd�tƒ | _| _dS | jr!t| dƒs!|  ¡  dS | j	dkrPt| dƒr1t
| jƒ}n| }z|  | j|¡\| _| _W dS  ttfyO   |  ¡  ‚ w | j	dkrs| jdure| j ¡ dkretdƒ‚t| jdd�| _tƒ | _dS t| jd�tƒ | _| _dS )	zFPopulate self._post and self._files if the content-type is a form typer*   )ri   Nr½   zmultipart/form-dataz!application/x-www-form-urlencodedzutf-8z^HTTP requests with the 'application/x-www-form-urlencoded' content type must be UTF-8 encoded.)r0   r(   r¬   r   r­   r¶   r¿   r®   rÉ   r2   r   r½   r¼   r,   r   r   Úlowerr   rÈ   )r5   Údatar!   r!   r"   Ú_load_post_and_files–  s8   


þ

ú
ÿ
þz HttpRequest._load_post_and_filesc                 C   s:   t | dƒrt dd„ | j ¡ D ƒ¡D ]}| ¡  qd S d S )Nr¶   c                 s   s   � | ]}|d  V  qdS )r^   Nr!   )rB   Úlist_r!   r!   r"   rF   Ä  s   € z$HttpRequest.close.<locals>.<genexpr>)r®   r   Úfrom_iterabler¶   ÚlistsrÆ   )r5   Úfr!   r!   r"   rÆ   Â  s
   

þzHttpRequest.closec              
   O   ó@   d| _ z
| jj|i |¤ŽW S  ty } zt|jŽ |‚d }~ww ©NT)r¿   rÅ   rÂ   rÃ   r   rÄ   ©r5   rÄ   ÚkwargsrÇ   r!   r!   r"   rÂ   Ï  ó   €ÿzHttpRequest.readc              
   O   rÑ   rÒ   )r¿   rÅ   ÚreadlinerÃ   r   rÄ   rÓ   r!   r!   r"   rÖ   Ö  rÕ   zHttpRequest.readlinec                 C   s   t | jdƒS )Nó    )ÚiterrÖ   r4   r!   r!   r"   Ú__iter__Ý  ó   zHttpRequest.__iter__c                 C   s   t | ƒS r:   )Úlistr4   r!   r!   r"   Ú	readlinesà  s   zHttpRequest.readlines)Fr:   )+r   r   r    r$   r¬   r³   r6   r9   r   r<   rR   rS   rU   rb   rc   rk   rv   r   rr   r7   r‰   r…   r’   r™   r¡   r�   r¤   Úpropertyrš   rs   ri   Úsetterr´   rµ   r¼   rÈ   rÉ   rÌ   rÆ   rÂ   rÖ   rÙ   rÜ   r!   r!   r!   r"   r%   5   sb    	






'






,r%   c                       sp   e Zd ZdZddhZ‡ fdd„Z‡ fdd„Zedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZ‡  ZS )r;   ÚHTTP_rd   r¾   c                    s<   i }|  ¡ D ]\}}|  |¡}|r|||< qtƒ  |¡ d S r:   )ÚitemsÚparse_header_nameÚsuperr6   )r5   Úenvironr<   r¨   r˜   Úname©r8   r!   r"   r6   é  s   
€zHttpHeaders.__init__c                    s   t ƒ  | dd¡¡S )z:Allow header lookup using underscores in place of hyphens.rª   ú-)râ   Ú__getitem__Úreplace©r5   rJ   rå   r!   r"   rç   ñ  s   zHttpHeaders.__getitem__c                 C   s8   |  | j¡r| | j¡}n|| jvrd S | dd¡ ¡ S )Nrª   ræ   )rœ   ÚHTTP_PREFIXrž   ÚUNPREFIXED_HEADERSrè   Útitle©Úclsr¨   r!   r!   r"   rá   õ  s
   
zHttpHeaders.parse_header_namec                 C   s,   |  dd¡ ¡ }|| jv r|S | j› |› �S ©Nræ   rª   )rè   Úupperrë   rê   rí   r!   r!   r"   Úto_wsgi_nameý  s   
zHttpHeaders.to_wsgi_namec                 C   s   |  dd¡ ¡ S rï   )rè   rð   rí   r!   r!   r"   Úto_asgi_name  s   zHttpHeaders.to_asgi_namec                    ó   ‡ fdd„|  ¡ D ƒS )Nc                    ó   i | ]
\}}ˆ   |¡|“qS r!   )rñ   ©rB   Úheader_namer˜   ©rî   r!   r"   Ú
<dictcomp>
  ó    
ÿÿz-HttpHeaders.to_wsgi_names.<locals>.<dictcomp>©rà   ©rî   r<   r!   r÷   r"   Úto_wsgi_names  ó   
þzHttpHeaders.to_wsgi_namesc                    ró   )Nc                    rô   r!   )rò   rõ   r÷   r!   r"   rø     rù   z-HttpHeaders.to_asgi_names.<locals>.<dictcomp>rú   rû   r!   r÷   r"   Úto_asgi_names  rý   zHttpHeaders.to_asgi_names)r   r   r    rê   rë   r6   rç   Úclassmethodrá   rñ   rò   rü   rþ   Ú__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ƒr3z| | j¡}W n t	y2   | d¡}Y nw zt
|fi |¤ŽD ]
\}}|  ||¡ q<W n tyY } ztdƒ|‚d }~ww || _d S )Nr'   T)Úkeep_blank_valuesri   Úmax_num_fieldsz
iso-8859-1zRThe number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.)râ   r6   r	   ÚDEFAULT_CHARSETri   ÚDATA_UPLOAD_MAX_NUMBER_FIELDSÚ
isinstanceÚbytesÚdecodeÚUnicodeDecodeErrorr   Ú
appendlistr§   r   Ú_mutable)r5   Úquery_stringr&   ri   Úparse_qsl_kwargsrJ   r˜   rÇ   rå   r!   r"   r6   +  s4   
ý
þÿÿý€û
	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&   ri   F)r	  r
  )rî   Úiterabler˜   r&   ri   ÚqrJ   r!   r!   r"   ÚfromkeysI  s   zQueryDict.fromkeysc                 C   s   | j d u r	tj| _ | j S r:   )r¬   r	   r  r4   r!   r!   r"   ri   V  s   
zQueryDict.encodingc                 C   s
   || _ d S r:   r«   )r5   r˜   r!   r!   r"   ri   \  r=   c                 C   s   | j stdƒ‚d S )Nz$This QueryDict instance is immutable)r
  r·   r4   r!   r!   r"   Ú_assert_mutable`  s   ÿzQueryDict._assert_mutablec                    ó2   |   ¡  t|| jƒ}t|| jƒ}tƒ  ||¡ d S r:   )r  Úbytes_to_textri   râ   Ú__setitem__©r5   rJ   r˜   rå   r!   r"   r  d  ó   zQueryDict.__setitem__c                    s   |   ¡  tƒ  |¡ d S r:   )r  râ   Ú__delitem__ré   rå   r!   r"   r  j  s   zQueryDict.__delitem__c                 C   s4   | j dd| jd�}|  ¡ D ]
\}}| ||¡ q|S ©Nr'   Tr  )r8   ri   rÏ   Úsetlist)r5   ÚresultrJ   r˜   r!   r!   r"   Ú__copy__n  s   zQueryDict.__copy__c                 C   sP   | j dd| jd�}||t| ƒ< |  ¡ D ]\}}| t ||¡t ||¡¡ q|S r  )r8   ri   ÚidrÏ   r  ÚcopyÚdeepcopy)r5   Úmemor  rJ   r˜   r!   r!   r"   Ú__deepcopy__t  s
   zQueryDict.__deepcopy__c                    s8   ˆ   ¡  t|ˆ jƒ}‡ fdd„|D ƒ}tƒ  ||¡ d S )Nc                    s   g | ]}t |ˆ jƒ‘qS r!   )r  ri   )rB   Úeltr4   r!   r"   rZ   ~  s    z%QueryDict.setlist.<locals>.<listcomp>)r  r  ri   râ   r  )r5   rJ   rÍ   rå   r4   r"   r  {  s   zQueryDict.setlistc                    s   |   ¡  tƒ  ||¡S r:   )r  râ   Úsetlistdefault)r5   rJ   Údefault_listrå   r!   r"   r"  �  ó   zQueryDict.setlistdefaultc                    r  r:   )r  r  ri   râ   r	  r  rå   r!   r"   r	  …  r  zQueryDict.appendlistc                    s   |   ¡  tƒ j|g|¢R Ž S r:   )r  râ   Úpop)r5   rJ   rÄ   rå   r!   r"   r%  ‹  s   zQueryDict.popc                    s   |   ¡  tƒ  ¡ S r:   )r  râ   Úpopitemr4   rå   r!   r"   r&  �  s   
zQueryDict.popitemc                    s   |   ¡  tƒ  ¡  d S r:   )r  râ   Úclearr4   rå   r!   r"   r'  “  r$  zQueryDict.clearc                    s.   |   ¡  t|| jƒ}t|| jƒ}tƒ  ||¡S r:   )r  r  ri   râ   Ú
setdefault)r5   rJ   r–   rå   r!   r"   r(  —  s   zQueryDict.setdefaultc                 C   s
   |   i ¡S )z%Return a mutable copy of this object.)r   r4   r!   r!   r"   r  �  r=   zQueryDict.copyc                    sb   g }ˆrˆ  ˆj¡‰‡fdd„‰ ndd„ ‰ ˆ ¡ D ]\‰}| ‡ ‡‡fdd„|D ƒ¡ qd |¡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"   Úencode²  s   z#QueryDict.urlencode.<locals>.encodec                 S   s   t | |iƒS r:   )r   r)  r!   r!   r"   r-  ·  rÚ   c                 3   s.   � | ]}ˆ ˆ  ˆj¡t|ƒ  ˆj¡ƒV  qd S r:   )r-  ri   rƒ   )rB   r+  )r-  r*  r5   r!   r"   rF   »  s
   € ÿ
ÿz&QueryDict.urlencode.<locals>.<genexpr>ú&)r-  ri   rÏ   ÚextendÚjoin)r5   r,  ÚoutputrÍ   r!   )r-  r*  r,  r5   r"   r   ¡  s   
þ
zQueryDict.urlencode)NFN)r'   FNr:   )r   r   r    r$   r
  r¬   r6   rÿ   r  rÝ   ri   rÞ   r  r  r  r  r   r  r"  r	  r%  r&  r'  r(  r  r   r   r!   r!   rå   r"   r(     s2    

r(   c                   @   sP   e Zd Zdd„ Zdd„ Zdd„ Zedd„ ƒZd	d
„ Zedd„ ƒZ	e
dd„ ƒZdS )r@   c                 C   s.   t |r|ndƒ\}| _| d¡\| _}| _d S )Nr'   r‹   )r   ÚparamsÚ	partitionÚ	main_typeÚsub_type)r5   Úmedia_type_raw_lineÚ	full_typerª   r!   r!   r"   r6   Ã  s   

ÿzMediaType.__init__c                 C   s@   d  dd„ | j ¡ D ƒ¡}d| j| jrd| j |f S d|f S )Nr'   c                 s   s    � | ]\}}d ||f V  qdS )z; %s=%sNr!   )rB   r*  r+  r!   r!   r"   rF   Ê  s   € z$MediaType.__str__.<locals>.<genexpr>rŠ   z/%s)r0  r2  rà   r4  r5  )r5   Ú
params_strr!   r!   r"   Ú__str__É  s   ýýzMediaType.__str__c                 C   s   d| j j| f S )Nz<%s: %s>)r8   r    r4   r!   r!   r"   r9   Ñ  s   zMediaType.__repr__c                 C   s   | j  ¡ }| dd ¡ |S )Nr  )r2  r  r%  )r5   r2  r!   r!   r"   Úrange_paramsÔ  s   
zMediaType.range_paramsc                 C   s²   |sdS t |tƒst|ƒ}| j|jg}| j|jg}tg |¢|¢R ƒs$dS ||fD ]\}}||kr;|dkr;|dkr; dS q(t| jƒt|jƒkrN| j|jk}|S t| jpU|j ƒ}|S )NFÚ*)r  r@   r4  r5  ÚallÚboolr:  )r5   ÚotherÚ
main_typesÚ	sub_typesÚ	this_typeÚ
other_typer  r!   r!   r"   rT   Ú  s"   
€ÿzMediaType.matchc                 C   sJ   zt | j dd¡ƒ}W n
 ty   Y dS w |dk s|dkr dS t|dƒS )Nr  r^   r   é   )Úfloatr2  rL   r§   Úround)r5   rA   r!   r!   r"   rA   ö  s   þ
zMediaType.qualityc                 C   s*   | j dkrdS | jdkrdS | jsdS dS )zM
        Return a value from 0-3 for how specific the media type is.
        r;  r   r^   é   rC  )r4  r5  r:  r4   r!   r!   r"   rH     s   

zMediaType.specificityN)r   r   r    r6   r9  r9   r   r:  rT   rA   rÝ   rH   r!   r!   r!   r"   r@   Â  s    

r@   c                 C   s   t | tƒrt| |dƒS | 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è   )r  r  rƒ   )Úsri   r!   r!   r"   r    s   
r  c                 C   s4   t  |  ¡ ¡ }r|jdd�\}}| d¡|fS d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'   )Úhost_validation_reÚ	fullmatchrÊ   ÚgroupsÚremovesuffix)rt   rT   r|   r}   r!   r!   r"   ry   #  s   ry   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;  N)r   )rB   Úpattern©rt   r!   r"   rF   @  s   € 
ÿz validate_host.<locals>.<genexpr>)Úany)rt   r{   r!   rN  r"   rz   1  s   ÿrz   )9rf   r  rO   Úior   Ú	itertoolsr   Úurllib.parser   r   r   r   r   Údjango.confr	   Údjango.corer
   Údjango.core.exceptionsr   r   r   r   r   Údjango.core.filesr   Údjango.http.multipartparserr   r   r   Údjango.utils.datastructuresr   r   r   Údjango.utils.encodingr   r   Údjango.utils.functionalr   Údjango.utils.httpr   r   Údjango.utils.regex_helperr   Úobjectr’   rI  rÃ   r   Ú	Exceptionr#   r%   r;   r(   r@   r  ry   rz   r!   r!   r!   r"   Ú<module>   sB    ÿ
   23 ,S