
    k"g1                        d dl Z d dlZd dlZd dl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 d dl
mZ d dlmZ d d	lmZ  ed
ej(                        Zdj-                         ZdZdZdZdZdZdZ ededededed	      Z ededededed	      Z ededededed	      Z dZ!dZ"d,dZd-dZ#d Z$d Z%d Z&d  Z'd! Z(d" Z)d# Z*d$ Z+d% Z,d,d&Z-d,d'Z.d( Z/d) Z0d* Z1d+ Z2y).    N)Error)datetimetimezone
formatdate)quoteunquote)	urlencode)urlparse)MultiValueDict)_lazy_re_compilez
    \A(      # start of string and capture group
    (?:W/)?  # optional weak indicator
    "        # opening quote
    [^"]*    # any sequence of non-quote characters
    "        # end quote
    )\Z      # end of string and capture group
z/jan feb mar apr may jun jul aug sep oct nov decz(?P<day>[0-9]{2})z(?P<day>[ 0-9][0-9])z(?P<mon>\w{3})z(?P<year>[0-9]{4})z(?P<year>[0-9]{2})z6(?P<hour>[0-9]{2}):(?P<min>[0-9]{2}):(?P<sec>[0-9]{2})z^\w{3},  z GMT$z
^\w{6,9}, -z^\w{3} $z:/?#[]@z!$&'()*+,;=c                    t        | t              r| j                         } nt        | d      r| j	                         } g }| D ]  \  }}|t        d|z        |rt        |t        t        f      r|}nR	 t        |      }g }|D ]>  }|t        d|z        t        |t              st        |      }|j                  |       @ 	 |j                  ||f        t        ||      S # t
        $ r |}Y .w xY w)z
    A version of Python's urllib.parse.urlencode() function that can operate on
    MultiValueDict and non-string values.
    itemszjCannot encode None for key '%s' in a query string. Did you mean to pass an empty string or omit the value?)
isinstancer   listshasattrr   	TypeErrorstrbytesiterappendoriginal_urlencode)querydoseqquery_paramskeyvalue	query_valitritems           J/var/www/html/djangosite/lib/python3.12/site-packages/django/utils/http.pyr
   r
   *   s   
 %(		 L .
U=BDGH  *US%L9I+5k 	 	+D|'.034 
 (e4"4y$$T*	+ 	S),-7.8 lE22#  "!	"s   4C&&C43C4c                     t        | d      S )aj  
    Format the time to match the RFC 5322 date format as specified by RFC 9110
    Section 5.6.7.

    `epoch_seconds` is a floating point number expressed in seconds since the
    epoch, in UTC - such as that outputted by time.time(). If set to None, it
    defaults to the current time.

    Output a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
    T)usegmtr   )epoch_secondss    r$   	http_dater(   S   s     mD11    c           	         t         t        t        fD ]  }|j                  |       }| n t	        d| z        	 t        |d         }|dk  rOt        j                  t        j                        j                  }||dz  z
  }||dz  z
  dkD  r	||dz
  z  }n||z  }t        j                  |d   j                               dz   }t        |d	         }t        |d
         }t        |d         }	t        |d         }
t        |||||	|
t        j                        }t        |j                               S # t        $ r}t	        d| z        |d}~ww xY w)a  
    Parse a date format as specified by HTTP RFC 9110 Section 5.6.7.

    The three formats allowed by the RFC are accepted, even if only the first
    one is still in widespread use.

    Return an integer expressed in seconds since the epoch, in UTC.
    Nz%%r is not in a valid HTTP date formatyeard   )tz2   mon   dayhourminsec)tzinfoz%r is not a valid date)RFC1123_DATERFC850_DATEASCTIME_DATEmatch
ValueErrorintr   nowr   utcr+   MONTHSindexlower	timestamp	Exception)dateregexmr+   current_yearcurrent_centurymonthr1   r2   r3   r4   resultexcs                r$   parse_http_daterK   a   sX    {L8 IKK=I
 @4GHHC1V9~#:#<<8<<8==L*lS.@AO|c)*R/ #--'QuX^^-.2!E(m1V9~!E(m!E(m$sD#s8<<P6##%&& C1D89sBCs   C;D7 7	E EEc                 8    	 t        |       S # t        $ r Y yw xY w)zK
    Same as parse_http_date, but return None if the input is invalid.
    N)rK   rB   )rC   s    r$   parse_http_date_saferM      s$    t$$ s   
 	c                 L    t        |       dkD  rt        d      t        | d      S )zf
    Convert a base 36 string to an int. Raise ValueError if the input won't fit
    into an int.
       zBase36 input too large$   )lenr:   r;   ss    r$   base36_to_intrT      s'     1v{122q":r)   c                     d}| dk  rt        d      | dk  r||    S d}| dk7  rt        | d      \  } }||   |z   }| dk7  r|S )z&Convert an integer to a base36 string.$0123456789abcdefghijklmnopqrstuvwxyzr   z!Negative base36 conversion input.rP    )r:   divmod)ichar_setb36ns       r$   int_to_base36r]      sd    5H1u<==2v{
C
q&a}1qkC q& Jr)   c                 h    t        j                  |       j                  d      j                  d      S )ze
    Encode a bytestring to a base64 string for use in URLs. Strip any trailing
    equal signs.
    s   
=ascii)base64urlsafe_b64encoderstripdecoderR   s    r$   urlsafe_base64_encoderd      s+    
 ##A&--f5<<WEEr)   c                     | j                         } 	 t        j                  | j                  t	        |       t	        |       dz  z   d            S # t
        t        f$ r}t        |      d}~ww xY w)zn
    Decode a base64 encoded string. Add back any trailing equal signs that
    might have been stripped.
          =N)encoder`   urlsafe_b64decodeljustrQ   LookupErrorBinasciiErrorr:   )rS   es     r$   urlsafe_base64_decodern      s`    
 	

A''AQ!0CT(JKK' ms   <A A.A))A.c                     | j                         dk(  rdgS d | j                  d      D        }|D cg c]
  }|s|d    c}S c c}w )z
    Parse a string of ETags given in an If-None-Match or If-Match header as
    defined by RFC 9110. Return a list of quoted ETags, or ['*'] if all ETags
    should be matched.
    *c              3   b   K   | ]'  }t         j                  |j                                ) y wN)
ETAG_MATCHr9   strip).0etags     r$   	<genexpr>zparse_etags.<locals>.<genexpr>   s!     W4
((6Ws   -/,r0   )rt   split)etag_stretag_matchesr9   s      r$   parse_etagsr|      sK     ~~3u X8>>RUCVW&2<Uea<<<s
   AAc                 :    t         j                  |       r| S d| z  S )z
    If the provided string is already a quoted ETag, return it. Otherwise, wrap
    the string in quotes, making it a strong ETag.
    z"%s")rs   r9   )rz   s    r$   
quote_etagr~      s"    
 !  r)   c                     |sy|j                         }|d   dk(  xr | j                  |      xs | |dd k(  xs || k(  S )a4  
    Return ``True`` if the host is either an exact match or a match
    to the wildcard pattern.

    Any pattern beginning with a period matches a domain and all of its
    subdomains. (e.g. ``.example.com`` matches ``example.com`` and
    ``foo.example.com``). Anything else is an exact string match.
    Fr   .r0   N)r@   endswith)hostpatterns     r$   is_same_domainr      sS     mmoG
c 	<]]7#:twqr{':	d?r)   c                     | | j                         } | sy|t               }nt        |t              r|h}t	        | ||      xr t	        | j                  dd      ||      S )a  
    Return ``True`` if the url uses an allowed host and a safe scheme.

    Always return ``False`` on an empty url.

    If ``require_https`` is ``True``, only 'https' will be considered a valid
    scheme, as opposed to 'http' and 'https' with the default, ``False``.

    Note: "True" doesn't entail that a URL is "safe". It may still be e.g.
    quoted incorrectly. Ensure to also use django.utils.encoding.iri_to_uri()
    on the path component of untrusted URLs.
    F)require_https\/)rt   setr   r    _url_has_allowed_host_and_schemereplace)urlallowed_hostsr   s      r$   url_has_allowed_host_and_schemer      sm     iik	M3	'& ,]- 
*D#]r)   c                 z   | j                  d      ry	 t        |       }|j                  s|j                  ryt        j                  | d         d   dk(  ry|j                  }|j                  s|j                  rd}|rdgnddg}|j                   xs |j                  |v xr	 | xs ||v S # t        $ r Y yw xY w)Nz///Fr   Chttphttps)
startswithr   r:   netlocschemeunicodedatacategory)r   r   r   url_infor   valid_schemess         r$   r   r     s     ~~eC= ??x CF#A&#-__F??x!.WIVW4EMC8??m#C 
-f-%  s   B. .	B:9B:c                 h    | j                  d      r dj                  | j                  d            } | S )z
    If redirecting to an absolute path (two leading slashes), a slash must be
    escaped to prevent browsers from handling the path as schemaless and
    redirecting to another host.
    z//z/%2F{})r   formatremoveprefix)r   s    r$   escape_leading_slashesr   .  s.     ~~dooc..t45Jr)   c              #     K   | d d dk(  r| dd  } | j                  d      }|dkD  ro| j                  dd|      | j                  dd|      z
  dz  rE| j                  d|dz         }|dkD  r+| j                  dd|      | j                  dd|      z
  dz  rE|dk  rt        |       }| d | }|j                          | |d  } | d d dk(  ry y w)Nr0   ;r   "\"   )findcountrQ   rt   )rS   endfs      r$   _parseparamr   9  s     
BQ%3,abEffSkAg17733/!''%C2HHAM&&cAg&C Ag17733/!''%C2HHAM7a&CdsGggicdG BQ%3,s   BC4C
Cc                 P   t        d| z         }|j                         j                         }i }|D ]  }|j                  d      }|dk\  sd}|d| j	                         j                         }|j                  d      r|dd }|j                  d      d	k(  rd
}||dz   d j	                         }t        |      d	k\  r;|d   |d   cxk(  rdk(  r*n n'|dd }|j                  dd      j                  dd      }|r"|j                  d      \  }	}
}t        ||	      }|||<    ||fS )zi
    Parse a Content-type like header.
    Return the main content-type and a dictionary of options.
    r   =r   FNrp   'r   Tr0   r   \\r   r   )encoding)r   __next__r@   r   rt   r   r   rQ   r   ry   r	   )linepartsr   pdictprY   has_encodingnamer    r   langs              r$   parse_header_parametersr   F  s4   
 d
#E
..

 
 
"CE  FF3K6 LRa5;;=&&(D}}S! CRy773<1$#'La!egJ$$&E5zQ58uRy#?C#?afd3;;E3G(-C(8%$9E$K% & :r)   c                     |rP| rdnd}	 |j                  d       dj                  |j                  dd      j                  dd            }| d
| S | ryy# t        $ r d	j                  t	        |            }Y 0w xY w)zq
    Construct a Content-Disposition HTTP header value from the given filename
    as specified by RFC 6266.
    
attachmentinliner_   zfilename="{}"r   r   r   r   zfilename*=utf-8''{}z; N)rh   r   r   UnicodeEncodeErrorr   )as_attachmentfilenamedisposition	file_exprs       r$   content_disposition_headerr   d  s    
 &3l	FOOG$'..  v.66sEBI
 b,,	 " 	F-44U8_EI	Fs   AA #A=<A=)Frr   )3r`   rer   binasciir   rl   r   r   email.utilsr   urllib.parser   r	   r
   r   r   django.utils.datastructuresr   django.utils.regex_helperr   Xrs   ry   r>   __D__D2__M__Y__Y2__Tr6   r7   r8   RFC3986_GENDELIMSRFC3986_SUBDELIMSr(   rK   rM   rT   r]   rd   rn   r|   r~   r   r   r   r   r   r   r    r)   r$   <module>r      s    	  + ' " ' 8 ! 6 6  DD

 
;	@	@	B?sCc RSS$PSTU#tS# NO ! &3R2%CP
F	=!(<<
<r)   