
    Dg              	          d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZmZ eee	eee         f         f         Zeeee         f         Ze
dedefd            Ze
dd	            Zdee         dee         fd
Ze
dedefd            Ze
dd            Zdee         dee         fdZ	 ddedededefdZdS )    )	b64encode)AnyListMappingMutableMappingOptionalSequenceUnionoverload)
StrOrBytes)to_bytes
to_unicodeheaders_rawreturnc                     d S N r   s    ?/var/www/sysmax/venv/lib/python3.11/site-packages/w3lib/http.pyheaders_raw_to_dictr          BE#    Nc                     d S r   r   r   s    r   r   r      s    47Cr   c                 8   | dS |                                  }d |D             }i }|D ]p}t          |          dk    s|d                                         }|d                                         }||v r||                             |           j|g||<   q|S )a  
    Convert raw headers (single multi-line bytestring)
    to a dictionary.

    For example:

    >>> import w3lib.http
    >>> w3lib.http.headers_raw_to_dict(b"Content-type: text/html\n\rAccept: gzip\n\n")   # doctest: +SKIP
    {'Content-type': ['text/html'], 'Accept': ['gzip']}

    Incorrect input:

    >>> w3lib.http.headers_raw_to_dict(b"Content-typt gzip\n\n")
    {}
    >>>

    Argument is ``None`` (return ``None``):

    >>> w3lib.http.headers_raw_to_dict(None)
    >>>

    Nc                 :    g | ]}|                     d d          S )   :   )split).0headers     r   
<listcomp>z'headers_raw_to_dict.<locals>.<listcomp>7   s&    BBBfll4++BBBr      r   r   )
splitlineslenstripappend)r   headersheaders_tuplesresult_dictheader_itemitem_key
item_values          r   r   r      s    0 t$$&&GBB'BBBN%'K% 
1 
1;1$$q>'')) ^))++
{""!((4444%/LK!!r   headers_dictc                     d S r   r   r-   s    r   headers_dict_to_rawr0   I   r   r   c                     d S r   r   r/   s    r   r0   r0   M   s    58Sr   c                    | dS g }|                                  D ]\  }}t          |t                    r+|                    d                    ||g                     Et          |t
          t          f          r/|D ],}|                    d                    ||g                     -d                    |          S )a  
    Returns a raw HTTP headers representation of headers

    For example:

    >>> import w3lib.http
    >>> w3lib.http.headers_dict_to_raw({b'Content-type': b'text/html', b'Accept': b'gzip'}) # doctest: +SKIP
    'Content-type: text/html\\r\\nAccept: gzip'
    >>>

    Note that keys and values must be bytes.

    Argument is ``None`` (returns ``None``):

    >>> w3lib.http.headers_dict_to_raw(None)
    >>>

    Ns   : s   
)items
isinstancebytesr&   joinlisttuple)r-   	raw_lineskeyvaluevs        r   r0   r0   Q   s    ( tI"((** 7 7
UeU## 	7UZZe556666e}-- 	7 7 7  S!H!5!56666<<	"""r   
ISO-8859-1usernamepasswordencodingc                     t          |            dt          |           }dt          t          ||                    z   S )aA  
    Return an `Authorization` header field value for `HTTP Basic Access Authentication (RFC 2617)`_

    >>> import w3lib.http
    >>> w3lib.http.basic_auth_header('someuser', 'somepass')
    'Basic c29tZXVzZXI6c29tZXBhc3M='

    .. _HTTP Basic Access Authentication (RFC 2617): http://www.ietf.org/rfc/rfc2617.txt

    :s   Basic )r@   )r   r   r   )r>   r?   r@   auths       r   basic_auth_headerrD   q   sI     "";;Z%9%9;;D y$!B!B!BCCCCr   )r   Nr   N)r-   Nr   N)r=   )base64r   typingr   r   r   r   r   r	   r
   r   w3lib._typesr   
w3lib.utilr   r   r5   HeadersDictInputHeadersDictOutputr   r0   strrD   r   r   r   <module>rL      s        	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 $ # # # # # + + + + + + + +5%Xe_(<"==> "5$u+#56  
 EU E/@ E E E 
 E 
 7 7 7 
 7*Xe_ *BS9T * * * *Z 
 E&6 E5 E E E 
 E 
 8 8 8 
 8#h/?&@ #Xe_ # # # #B AMD DD$.D:=D
D D D D D Dr   