
    Yf                         d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZmZ  ed          ZdedefdZe G d d	                      Zd	gZd
S )z2
An API for storing HTTP header names and values.
    )AnyStrClassVarDictIteratorListMappingOptionalSequenceTupleTypeVarUnionoverload)cmp
comparable_TheaderComponentreturnc                 P    d                     |                                           S )z
    Replace linear whitespace (C{\n}, C{\r\n}, C{\r}) in a header key
    or value with a single space.

    @param headerComponent: The header key or value to sanitize.

    @return: The sanitized header key or value.
        )join
splitlines)r   s    J/var/www/html/env/lib/python3.11/site-packages/twisted/web/http_headers.py_sanitizeLinearWhitespacer      s"     99_//11222    c            
          e Zd ZU dZdddddddd	Zeeeef                  ed
<   i Z	eee
eef         ef                  ed<   dZee         ed<   dgZ	 d#deeeee         f                  ddfdZdefdZd Zde
eef         defdZd ZdedefdZdeddfdZde
eef         dee
eef                  ddfdZde
eef         de
eef         ddfdZededeee                  fd            Zededede
ee         ef         fd             Z	 d#dedee         de
ee         ee         f         fd!Zde e!eee         f                  fd"Z"dS )$Headersa  
    Stores HTTP headers in a key and multiple value format.

    When passed L{str}, header names (e.g. 'Content-Type')
    are encoded using ISO-8859-1 and header values (e.g.
    'text/html;charset=utf-8') are encoded using UTF-8. Some methods that return
    values will return them in the same type as the name given.

    If the header keys or values cannot be encoded or decoded using the rules
    above, using just L{bytes} arguments to the methods of this class will
    ensure no decoding or encoding is done, and L{Headers} will treat the keys
    and values as opaque byte strings.

    @cvar _caseMappings: A L{dict} that maps lowercase header names
        to their canonicalized representation, for headers with unconventional
        capitalization.

    @cvar _canonicalHeaderCache: A L{dict} that maps header names to their
        canonicalized representation.

    @ivar _rawHeaders: A L{dict} mapping header names as L{bytes} to L{list}s of
        header values as L{bytes}.
    s   Content-MD5s   DNTs   ETags   P3Ps   TEs   WWW-Authenticates   X-XSS-Protection)s   content-md5s   dnts   etags   p3ps   tes   www-authenticates   x-xss-protection_caseMappings_canonicalHeaderCachei'  _MAX_CACHED_HEADERS_rawHeadersN
rawHeadersr   c                 |    i | _         |0|                                D ]\  }}|                     ||           d S d S N)r    itemssetRawHeaders)selfr!   namevaluess       r   __init__zHeaders.__init__S   s\     68! * 0 0 2 2 1 1f""40000 "!1 1r   c                 L    d                     | j        j        | j                  S )zR
        Return a string fully describing the headers set on this object.
        z{}({!r}))format	__class____name__r    r&   s    r   __repr__zHeaders.__repr__\   s*       N#
 
 	
r   c                     t          |t                    rXt          t          | j                                                  t          |j                                                            S t          S )zu
        Define L{Headers} instances as being equal to each other if they have
        the same raw headers.
        )
isinstancer   r   sortedr    r$   NotImplemented)r&   others     r   __cmp__zHeaders.__cmp__e   sc    
 eW%% 	t'--//00&9J9P9P9R9R2S2S   r   r'   c                    | j                             |d          x}r|S t          |t                    r|                    d          n|}|                                | j        v r | j        |                                         }n?t          d                    d |	                    d          D                                 }t          | j                   | j        k     r
|| j         |<   |S )a  
        Encode the name of a header (eg 'Content-Type') to an ISO-8859-1
        encoded bytestring if required.  It will be canonicalized and
        whitespace-sanitized.

        @param name: A HTTP header name

        @return: C{name}, encoded if required, lowercased
        Nz
iso-8859-1   -c                 6    g | ]}|                                 S  )
capitalize).0words     r   
<listcomp>z'Headers._encodeName.<locals>.<listcomp>   s"    PPP4??,,PPPr   )r   getr1   strencodelowerr   r   r   splitlenr   )r&   r'   canonicalName
bytes_nameresults        r   _encodeNamezHeaders._encodeNamep   s     !6::4FFF= 	!  2<T32G2GQT[[...T
!333'
(8(8(:(:;FF.		PP9I9I$9O9OPPPQQ F t)**T-EEE/5D&t,r   c                 6    |                      | j                  S )zg
        Return a copy of itself with the same headers set.

        @return: A new L{Headers}
        )r,   r    r.   s    r   copyzHeaders.copy   s     ~~d.///r   c                 :    |                      |          | j        v S )z
        Check for the existence of a given header.

        @param name: The name of the HTTP header to check for.

        @return: C{True} if the header exists, otherwise C{False}.
        )rG   r    r&   r'   s     r   	hasHeaderzHeaders.hasHeader   s      %%)999r   c                 b    | j                             |                     |          d           dS )z
        Remove the named header from this header object.

        @param name: The name of the HTTP header to remove.

        @return: L{None}
        N)r    poprG   rK   s     r   removeHeaderzHeaders.removeHeader   s1     	T--d33T:::::r   r(   c                     |                      |          }g }|D ]Q}t          |t                    r|                    d          }n|}|                    t          |                     R|| j        |<   dS )a  
        Sets the raw representation of the given header.

        @param name: The name of the HTTP header to set the values for.

        @param values: A list of strings each one being a header value of
            the given name.

        @raise TypeError: Raised if C{values} is not a sequence of L{bytes}
            or L{str}, or if C{name} is not L{bytes} or L{str}.

        @return: L{None}
        utf8N)rG   r1   r?   r@   appendr   r    )r&   r'   r(   _nameencodedValuesv_vs          r   r%   zHeaders.setRawHeaders   s        &&%' 	@ 	@A!S!! XXf%%  !:2!>!>????"/r   valuec                     | j                             |                     |          g                               t	          t          |t                    r|                    d          n|                     dS )z
        Add a new raw value for the given header.

        @param name: The name of the header for which to set the value.

        @param value: The value to set for the named header.
        rQ   N)r    
setdefaultrG   rR   r   r1   r?   r@   )r&   r'   rW   s      r   addRawHeaderzHeaders.addRawHeader   sw     	##D$4$4T$:$:B??FF%(25#(>(>IV$$$E 	
 	
 	
 	
 	
r   c                     d S r#   r9   rK   s     r   getRawHeaderszHeaders.getRawHeaders       r   defaultc                     d S r#   r9   )r&   r'   r^   s      r   r\   zHeaders.getRawHeaders   r]   r   c                     |                      |          }| j                            |g           }|s|S t          |t                    rd |D             S |S )a  
        Returns a sequence of headers matching the given name as the raw string
        given.

        @param name: The name of the HTTP header to get the values of.

        @param default: The value to return if no header with the given C{name}
            exists.

        @return: If the named header is present, a sequence of its
            values.  Otherwise, C{default}.
        c                 8    g | ]}|                     d           S )rQ   )decode)r;   rU   s     r   r=   z)Headers.getRawHeaders.<locals>.<listcomp>   s$    555AHHV$$555r   )rG   r    r>   r1   r?   )r&   r'   r^   encodedNamer(   s        r   r\   zHeaders.getRawHeaders   sg     &&t,,!%%k266 	NdC   	655f5555r   c                 N    t          | j                                                  S )z
        Return an iterator of key, value pairs of all headers contained in this
        object, as L{bytes}.  The keys are capitalized in canonical
        capitalization.
        )iterr    r$   r.   s    r   getAllRawHeaderszHeaders.getAllRawHeaders   s!     D$**,,---r   r#   )#r-   
__module____qualname____doc__r   r   r   bytes__annotations__r   r   r?   r   int	__slots__r	   r   r   r
   r)   r/   r5   rG   rI   boolrL   rO   r%   rZ   r   r\   r   r   r   rf   r9   r   r   r   r   )   s         2 '003 3M8D./    GI8Ducz):E)A$BCHHH)/#///I CG1 1WVXf-=%=>?1 
1 1 1 1
# 
 
 
 
	 	 	c5j 1 e    B0 0 0:f : : : : :; ;D ; ; ; ;0#u*%0/7c5j8I/J0	0 0 0 06
sEz!2 
5e;L 
QU 
 
 
 
 & Xhv6F-G    X & 2 %@PRT@T:U    X 59 %-b\	x"-	.   0.(51G+H"I . . . . . .r   r   N)ri   typingr   r   r   r   r   r   r	   r
   r   r   r   r   twisted.python.compatr   r   r   rj   r   r   __all__r9   r   r   <module>rr      s.  
                             2 1 1 1 1 1 1 1WT]]	3u 	3 	3 	3 	3 	3 R. R. R. R. R. R. R. R.j +r   