
    e              	          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mZ e
ee	eee         f         f         Zeeee         f         Zdee         dee         f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MutableMappingOptionalAnyStrSequenceUnionMapping)to_bytes
to_unicodeheaders_rawreturnc                 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     *lib/python3.11/site-packages/w3lib/http.py
<listcomp>z'headers_raw_to_dict.<locals>.<listcomp>$   s&    BBBfll4++BBB       r   r   )
splitlineslenstripappend)r   headersheaders_tuplesresult_dictheader_itemitem_key
item_values          r   headers_raw_to_dictr%   	   s    0 t$$&&GBB'BBBN%'K% 
1 
1;1$$q>'')) ^))++
{""!((4444%/LK!!r   headers_dictc                    | 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   headers_dict_to_rawr2   6   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 )r6   )r   r   r   )r4   r5   r6   auths       r   basic_auth_headerr:   V   sI     "";;Z%9%9;;D y$!B!B!BCCCCr   N)r3   )base64r   typingr   r   r   r   r   r	   r
   r   
w3lib.utilr   r   r*   HeadersDictInputHeadersDictOutputr%   r2   strr:    r   r   <module>rB      sK         X X X X X X X X X X X X X X X X X X X X + + + + + + + +5%Xe_(<"==> "5$u+#56 *Xe_ *BS9T * * * *Z#h/?&@ #Xe_ # # # #B 9ED DD &D25D
D D D D D Dr   