
    hy"                        S r SSKJr  SSKJrJrJrJrJrJ	r	J
r
JrJrJrJrJr  SSKJrJr  SSKJr   " S S\5      r\" S5      rSS	 jr\ " S
 S5      5       r " S S5      r\" 5       r S/rg)z2
An API for storing HTTP header names and values.
    )annotations)AnyStrClassVarDictIteratorListMappingOptionalSequenceTupleTypeVarUnionoverload)cmp
comparable)_istokenc                      \ rS rSrSrSrg)InvalidHeaderName   z=
HTTP header names must be tokens, per RFC 9110 section 5.1.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       _/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/http_headers.pyr   r      s    r   r   _Tc                @    SR                  U R                  5       5      $ )z
Replace linear whitespace (C{\n}, C{\r\n}, C{\r}) in a header
value with a single space.

@param headerComponent: The header value to sanitize.

@return: The sanitized header value.
    )join
splitlines)headerComponents    r   _sanitizeLinearWhitespacer%   &   s     99_//122r   c                      \ rS rSrSrS/r S   SS jjrSS jrS rSS jr	SS	 jr
SS
 jr      SS jrSS jr\SS j5       r\SS j5       r S     SS jjrSS jrSrg)Headers2   a  
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.

@ivar _rawHeaders: A L{dict} mapping header names as L{bytes} to L{list}s of
    header values as L{bytes}.
_rawHeadersNc                n    0 U l         Ub+  UR                  5        H  u  p#U R                  X#5        M     g g N)r)   itemssetRawHeaders)self
rawHeadersnamevaluess       r   __init__Headers.__init__G   s:     68! * 0 0 2""40 !3 "r   c                b    SR                  U R                  R                  U R                  5      $ )zB
Return a string fully describing the headers set on this object.
z{}({!r}))format	__class__r   r)   r.   s    r   __repr__Headers.__repr__P   s-       NN##
 	
r   c                    [        U[        5      (       aN  [        [        U R                  R                  5       5      [        UR                  R                  5       5      5      $ [        $ )z]
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__Headers.__cmp__Y   sS    
 eW%%t''--/0&9J9J9P9P9R2S  r   c                8    U R                  U R                  5      $ )zO
Return a copy of itself with the same headers set.

@return: A new L{Headers}
)r6   r)   r7   s    r   copyHeaders.copyd   s     ~~d..//r   c                F    [         R                  U5      U R                  ;   $ )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}.
)_nameEncoderencoder)   r.   r0   s     r   	hasHeaderHeaders.hasHeadern   s      ""4(D,<,<<<r   c                b    U R                   R                  [        R                  U5      S5        g)zy
Remove the named header from this header object.

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

@return: L{None}
N)r)   poprE   rF   rG   s     r   removeHeaderHeaders.removeHeaderx   s%     	\006=r   c                    [         R                  U5      n/ nU HF  n[        U[        5      (       a  UR                  S5      nOUnUR	                  [        U5      5        MH     X@R                  U'   g)aY  
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)rE   rF   r;   strappendr%   r)   )r.   r0   r1   _nameencodedValuesv_vs          r   r-   Headers.setRawHeaders   sg      ##D)%'A!S!!XXf%  !:2!>?  #0r   c                    U R                   R                  [        R                  U5      / 5      R	                  [        [        U[        5      (       a  UR                  S5      OU5      5        g)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.
rO   N)r)   
setdefaultrE   rF   rQ   r%   r;   rP   )r.   r0   values      r   addRawHeaderHeaders.addRawHeader   sR     	##L$7$7$=rBII%(25#(>(>V$E	
r   c                    g r+   r   rG   s     r   getRawHeadersHeaders.getRawHeaders       r   c                    g r+   r   )r.   r0   defaults      r   r]   r^      r_   r   c                    [         R                  U5      nU R                  R                  U/ 5      nU(       d  U$ [	        U[
        5      (       a!  U Vs/ s H  oUR                  S5      PM     sn$ U$ s  snf )aE  
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}.
rO   )rE   rF   r)   getr;   rP   decode)r.   r0   ra   encodedNamer1   rT   s         r   r]   r^      sg     #))$/!!%%k26NdC  .45fHHV$f55 6s   A3c                H    [        U R                  R                  5       5      $ )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,   r7   s    r   getAllRawHeadersHeaders.getAllRawHeaders   s     D$$**,--r   )r)   r+   )r/   z+Optional[Mapping[AnyStr, Sequence[AnyStr]]]returnNone)rj   rP   )rj   r'   )r0   r   rj   bool)r0   r   rj   rk   )r0   Union[str, bytes]r1   zSequence[Union[str, bytes]]rj   rk   )r0   rm   rY   rm   rj   rk   )r0   r   rj   zOptional[Sequence[AnyStr]])r0   r   ra   r   rj   zUnion[Sequence[AnyStr], _T])r0   r   ra   zOptional[_T]rj   z%Union[Sequence[AnyStr], Optional[_T]])rj   z'Iterator[Tuple[bytes, Sequence[bytes]]])r   r   r   r   r   	__slots__r2   r8   r?   rB   rH   rL   r-   rZ   r   r]   rh   r   r   r   r   r'   r'   2   s    " I CG1?1 
1
	0=>0%0/J0	06
     59%1	.0.r   r'   c                  d    \ rS rSr% SrSrS\S'   SSSS	S
SSS.rS\S'   SrS\S'   S r	SS jr
Srg)_NameEncoder   a|  
C{_NameEncoder} converts HTTP header names to L{bytes} and canonicalizies
their capitalization.

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

@cvar _canonicalHeaderCache: A L{dict} that maps header names to their
    canonicalized representation.
_canonicalHeaderCachezDict[Union[bytes, str], bytes]rs   s   Content-MD5s   DNTs   ETags   P3Ps   TEs   WWW-Authenticates   X-XSS-Protection)s   Content-Md5s   Dnts   Etags   P3ps   Tes   Www-Authenticates   X-Xss-ProtectionzClassVar[Dict[bytes, bytes]]_caseMappingsi'  zClassVar[int]_MAX_CACHED_HEADERSc                    0 U l         g r+   rr   r7   s    r   r2   _NameEncoder.__init__   s
    %'"r   c                   U R                   R                  U5      =n(       a  U$ [        U[        5      (       a  UR	                  S5      OUn[        U5      (       d  [        U5      eSR                  UR                  S5       Vs/ s H  oDR                  5       PM     sn5      nXPR                  ;   a  U R                  U   n[        U R                   5      U R                  :  a  XPR                   U'   U$ s  snf )aL  
Encode the name of a header (eg 'Content-Type') to an ISO-8859-1
bytestring if required. It will be canonicalized to Http-Header-Case.

@raises InvalidHeaderName:
    If the header name contains invalid characters like whitespace
    or NUL.

@param name: An HTTP header name

@return: C{name}, encoded if required, in Header-Case
z
iso-8859-1   -)rs   rc   r;   rP   rF   r   r   r"   split
capitalizert   lenru   )r.   r0   canonicalName
bytes_namewordresults         r   rF   _NameEncoder.encode   s     !66::4@@=@  2<T32G2GT[[.T

###J//*:J:J4:PQ:P$OO-:PQR '''''/F t))*T-E-EE/5&&t, Rs   C7N)r0   rm   rj   bytes)r   r   r   r   r   rn   __annotations__rt   ru   r2   rF   r   r   r   r   rp   rp      sQ    
 +I99 '003M/  *0/(#r   rp   N)r$   r   rj   r   )r   
__future__r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   twisted.python.compatr   r   twisted.web._abnfr   
ValueErrorr   r   r%   r'   rp   rE   __all__r   r   r   <module>r      s   
 #    2 &
  T]	3 ^. ^. ^.BB BJ ~
 +r   