File: //proc/self/root/lib/python3/dist-packages/twisted/web/__pycache__/http_headers.cpython-38.pyc
U
W[' � @ sN d Z ddlmZmZ ddlmZmZmZ dd� ZeG dd� de ��Z
dgZdS ) z2
An API for storing HTTP header names and values.
� )�division�absolute_import)�
comparable�cmp�unicodec C s d� dd� | �d�D ��S )a
Return a byte string which is capitalized using '-' as a word separator.
@param name: The name of the header to capitalize.
@type name: L{bytes}
@return: The given header capitalized using '-' as a word separator.
@rtype: L{bytes}
� -c S s g | ]}|� � �qS � )�
capitalize)�.0Zwordr r �:/usr/lib/python3/dist-packages/twisted/web/http_headers.py�
<listcomp> s z#_dashCapitalize.<locals>.<listcomp>)�join�split)�namer r r �_dashCapitalize s
r c @ s� e Zd ZdZdddddddd �Zd)dd�Zd
d� Zdd� Zdd� Zdd� Z dd� Z
dd� Zdd� Zdd� Z
dd� Zdd � Zd!d"� Zd*d#d$�Zd%d&� Zd'd(� Zd
S )+�Headersa�
Stores HTTP headers in a key and multiple value format.
Most methods accept L{bytes} and L{unicode}, with an internal L{bytes}
representation. When passed L{unicode}, 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.
@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-protectionNc C s0 i | _ |d k r,|�� D ]\}}| �||� qd S )N)�_rawHeaders�items�
setRawHeaders)�selfZ
rawHeadersr �valuesr r r �__init__; s zHeaders.__init__c C s d| j j| jf S )zR
Return a string fully describing the headers set on this object.
z%s(%r))� __class__�__name__r �r r r r �__repr__B s zHeaders.__repr__c C s, t |t�r(tt| j�� �t|j�� ��S tS )zu
Define L{Headers} instances as being equal to each other if they have
the same raw headers.
)�
isinstancer r �sortedr r �NotImplemented)r �otherr r r �__cmp__I s
�zHeaders.__cmp__c C s t |t�r|�� �d�S |�� S )a"
Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 encoded
bytestring if required.
@param name: A HTTP header name
@type name: L{unicode} or L{bytes}
@return: C{name}, encoded if required, lowercased
@rtype: L{bytes}
z
iso-8859-1)r r �lower�encode�r r r r r �_encodeNameU s
zHeaders._encodeNamec C s t |t�r|�d�S |S )a
Encode a single header value to a UTF-8 encoded bytestring if required.
@param value: A single HTTP header value.
@type value: L{bytes} or L{unicode}
@return: C{value}, encoded if required
@rtype: L{bytes}
�utf8)r r r"