i f@sJdZddlZejdZddddZGdddZdS) zManage HTTP Response Headers Much of this module is red-handedly pilfered from email.message in the stdlib, so portions are Copyright (C) 2001,2002 Python Software Foundation, and were written by Barry Warsaw. Nz[ \(\)<>@,;:\\"/\[\]\?=]cCsx|dk rpt|dkrp|s3tj|r_|jddjdd}d||fSd||fSn|SdS) z~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. Nr\z\\"z\"z%s="%s"z%s=%s)len tspecialssearchreplace)ZparamvalueZquoter 4/opt/alt/python34/lib64/python3.4/wsgiref/headers.py _formatparam s r c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$ZdS)%Headersz,Manage a collection of HTTP response headerscCs_t|tk r!tdn||_x.|D]&\}}|j||j|q1WdS)Nz+Headers must be a list of name/value tuples)typelist TypeError_headers_convert_string_type)selfZheaderskvr r r __init__ s   zHeaders.__init__cCs5t|tkr|Stdjt|dS)zConvert/check value type.z1Header names/values must be of type str (got {0})N)rstrAssertionErrorformatrepr)rr r r r r)s zHeaders._convert_string_typecCs t|jS)z9Return the total number of headers, including duplicates.)rr)rr r r __len__0szHeaders.__len__cCs3||=|jj|j||j|fdS)zSet the value of a header.N)rappendr)rnamevalr r r __setitem__4s zHeaders.__setitem__csB|jjfdd|jD|jdd@s z'Headers.__delitem__..N)rr r)rrr )rr __delitem__:szHeaders.__delitem__cCs |j|S)aHGet the first header value for 'name' Return None if the header is missing instead of raising an exception. Note that if the header appeared multiple times, the first exactly which occurrance gets returned is undefined. Use getall() to get all the values matching a header field name. )get)rrr r r __getitem__Bs zHeaders.__getitem__cCs|j|dk S)z/Return true if the message contains the header.N)r%)rrr r r __contains__MszHeaders.__contains__cs/|jjfdd|jDS)aqReturn a list of all the values for the named field. These will be sorted in the order they appeared in the original header list or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. If no fields exist with the given name, returns an empty list. cs0g|]&}|djkr|dqS)rr)r )r!r")rr r r#[s z#Headers.get_all..)rr r)rrr )rr get_allRszHeaders.get_allNcCsI|j|j}x-|jD]"\}}|j|kr|SqW|S)z:Get the first header value for 'name', or return 'default')rr r)rrdefaultrrr r r r%^s z Headers.getcCsdd|jDS)a*Return a list of all the header field names. These will be sorted in the order they appeared in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cSsg|]\}}|qSr r )r!rrr r r r#os z Headers.keys..)r)rr r r keysgsz Headers.keyscCsdd|jDS)a!Return a list of all header values. These will be sorted in the order they appeared in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cSsg|]\}}|qSr r )r!rrr r r r#ys z"Headers.values..)r)rr r r valuesqszHeaders.valuescCs|jddS)aGet all the header fields and values. These will be sorted in the order they were in the original header list, or were added to this instance, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. N)r)rr r r items{sz Headers.itemscCs d|jS)Nz Headers(%r))r)rr r r __repr__szHeaders.__repr__cCs'djdd|jDddgS)zkstr() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.z cSsg|]}d|qS)z%s: %sr )r!r"r r r r#s z#Headers.__str__..)joinr)rr r r __str__szHeaders.__str__cCst|jdS)Nz iso-8859-1)rencode)rr r r __bytes__szHeaders.__bytes__cCsO|j|}|dkrG|jj|j||j|f|S|SdS)zReturn first matching header value for 'name', or 'value' If there is no header named 'name', add a new header with name 'name' and value 'value'.N)r%rrr)rrr resultr r r setdefaults  zHeaders.setdefaultcKsg}|dk r1|j|}|j|nx|jD]t\}}|j|}|dkr|j|jddq>|j|}|jt|jdd|q>W|jj|j|dj|fdS)afExtended header setting. _name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. Example: h.add_header('content-disposition', 'attachment', filename='bud.gif') Note that unlike the corresponding 'email.message' method, this does *not* handle '(charset, language, value)' tuples: all values must be strings or None. N_-z; )rrr,rr rr/)r_nameZ_valueZ_paramspartsrrr r r add_headers  &zHeaders.add_header)__name__ __module__ __qualname____doc__rrrrr$r&r'r(r%r*r+r,r-r0r2r4r9r r r r r s$           r )r=recompilerr r r r r r s