ž ¬ÿfc@sJdZddlZejdƒZdddd„ZGdd„dƒZdS( uÓManage 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. iNu[ \(\)<>@,;:\\"/\[\]\?=]icCsx|dk rpt|ƒdkrp|s3tj|ƒr_|jddƒjddƒ}d||fSd||fSn|SdS( u~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. iu\u\\u"u\"u%s="%s"u%s=%sN(uNoneulenu tspecialsusearchureplace(uparamuvalueuquote((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu _formatparam s u _formatparamcBsé|EeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z d$dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$S(%uHeadersu,Manage a collection of HTTP response headerscCs_t|ƒtk r!tdƒ‚n||_x.|D]&\}}|j|ƒ|j|ƒq1WdS(Nu+Headers must be a list of name/value tuples(utypeulistu TypeErroru_headersu_convert_string_type(uselfuheadersukuv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu__init__ s   uHeaders.__init__cCs5t|ƒtkr|Stdjt|ƒƒƒ‚dS(uConvert/check value type.u1Header names/values must be of type str (got {0})N(utypeustruAssertionErroruformaturepr(uselfuvalue((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu_convert_string_type)s uHeaders._convert_string_typecCs t|jƒS(u9Return the total number of headers, including duplicates.(ulenu_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu__len__0suHeaders.__len__cCs3||=|jj|j|ƒ|j|ƒfƒdS(uSet the value of a header.N(u_headersuappendu_convert_string_type(uselfunameuval((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu __setitem__4s uHeaders.__setitem__csB|jˆjƒƒ‰‡fdd†|jDƒ|jdd…@s u'Headers.__delitem__..N(u_convert_string_typeuloweru_headers(uselfuname((unameu4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu __delitem__:suHeaders.__delitem__cCs |j|ƒS(uHGet 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. (uget(uselfuname((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu __getitem__Bs uHeaders.__getitem__cCs|j|ƒdk S(u/Return true if the message contains the header.N(ugetuNone(uselfuname((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu __contains__MsuHeaders.__contains__cs/|jˆjƒƒ‰‡fdd†|jDƒS(uqReturn 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|]&}|djƒˆkr|d‘qS(ii(ulower(u.0ukv(uname(u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu [s u#Headers.get_all..(u_convert_string_typeuloweru_headers(uselfuname((unameu4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyuget_allRsuHeaders.get_allcCsI|j|jƒƒ}x-|jD]"\}}|jƒ|kr|SqW|S(u:Get the first header value for 'name', or return 'default'(u_convert_string_typeuloweru_headers(uselfunameudefaultukuv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyuget^s u Headers.getcCsdd„|jDƒS(u*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|]\}}|‘qS(((u.0ukuv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu os u Headers.keys..(u_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyukeysgsu Headers.keyscCsdd„|jDƒS(u!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|]\}}|‘qS(((u.0ukuv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu ys u"Headers.values..(u_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyuvaluesqsuHeaders.valuescCs|jdd…S(uGet 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(u_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyuitems{su Headers.itemscCs d|jS(Nu Headers(%r)(u_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu__repr__…suHeaders.__repr__cCs'djdd„|jDƒddgƒS(ukstr() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.u cSsg|]}d|‘qS(u%s: %s((u.0ukv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu ‹s u#Headers.__str__..u(ujoinu_headers(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu__str__ˆsuHeaders.__str__cCst|ƒjdƒS(Nu iso-8859-1(ustruencode(uself((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu __bytes__suHeaders.__bytes__cCsO|j|ƒ}|dkrG|jj|j|ƒ|j|ƒfƒ|S|SdS(u£Return 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(ugetuNoneu_headersuappendu_convert_string_type(uselfunameuvalueuresult((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu setdefaults  uHeaders.setdefaultcKsâg}|dk r1|j|ƒ}|j|ƒnx‚|jƒD]t\}}|j|ƒ}|dkr|j|jddƒƒq>|j|ƒ}|jt|jddƒ|ƒƒq>W|jj|j|ƒdj|ƒfƒdS(ufExtended 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. u_u-u; N(uNoneu_convert_string_typeuappenduitemsureplaceu _formatparamu_headersujoin(uselfu_nameu_valueu_paramsupartsukuv((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyu add_headers  &uHeaders.add_headerN(u__name__u __module__u __qualname__u__doc__u__init__u_convert_string_typeu__len__u __setitem__u __delitem__u __getitem__u __contains__uget_alluNoneugetukeysuvaluesuitemsu__repr__u__str__u __bytes__u setdefaultu add_header(u __locals__((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyuHeaderss$          uHeaders(u__doc__ureucompileu tspecialsuNoneu _formatparamuHeaders(((u4/opt/alt/python33/lib64/python3.3/wsgiref/headers.pyus