
    a
                     &    d dl mZ d Zd ZddZdS )    )urlsafe_b64encodec                 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)headers_raw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   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)headers_dict	raw_lineskeyvaluevs        r   headers_dict_to_rawr'   1   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-1c                     | d|}t          |t                    s|                    |          }d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   encoder   )usernamepasswordencodingauths       r   basic_auth_headerr0   Q   sM     hh)DdE"" % {{8$$(....r   N)r(   )base64r   r   r'   r0    r   r   <module>r3      sU    $ $ $ $ $ $* * *Z# # #@/ / / / / /r   