fnPdZddlZejdZddZGddZy)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[ \(\)<>@,;:\\"/\[\]\?=]c|Vt|dkDrH|stj|r*|jddjdd}|d|dS|d|S|S)z~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. r\z\\"z\"z="=)len tspecialssearchreplace)paramvaluequotes &/usr/lib/python3.12/wsgiref/headers.py _formatparamr s\  SZ!^ I$$U+MM$/77UCE %u- -#U+ + czeZdZdZddZdZdZdZdZdZ d Z d Z dd Z d Z d ZdZdZdZdZdZdZy)Headersz,Manage a collection of HTTP response headersNc||ng}t|tur td||_ |D]'\}}|j ||j |)y)Nz+Headers must be a list of name/value tuples)typelist TypeError_headers_convert_string_type)selfheaderskvs r__init__zHeaders.__init__s_$0'b = $IJ J  -1))!,))!, -rcnt|tur|Stdjt |)zConvert/check value type.z1Header names/values must be of type str (got {0}))rstrAssertionErrorformatrepr)rr s rrzHeaders._convert_string_type)s3 ;# L%%+VDK%8: :rc,t|jS)z9Return the total number of headers, including duplicates.)rrrs r__len__zHeaders.__len__0s4==!!rc||=|jj|j||j|fy)zSet the value of a header.N)rappendr)rnamevals r __setitem__zHeaders.__setitem__4s: J   & &t ,d.G.G.L M Orc|j|j}|jDcgc]}|dj|k7s|c}|jddycc}w)zyDelete all occurrences of a header, if present. Does *not* raise an exception if the header is missing. rNrlowerrrr(kvs r __delitem__zHeaders.__delitem__:sK ((6)-P2"Q%++-4:OBP aPs A Ac$|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 occurrence gets returned is undefined. Use getall() to get all the values matching a header field name. getrr(s r __getitem__zHeaders.__getitem__Bsxx~rc(|j|duS)z/Return true if the message contains the header.Nr2r4s r __contains__zHeaders.__contains__Msxx~T))rc|j|j}|jDcgc]}|dj|k(s|d c}Scc}w)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. rr,r.s rget_allzHeaders.get_allRsG((6 $ E"A1D1EEEs A Ac|j|j}|jD]\}}|j|k(s|cS|S)z:Get the first header value for 'name', or return 'default'r,)rr(defaultrrs rr3z Headers.get^sH((6== CAawwy$ rcL|jDcgc]\}}| c}}Scc}}w)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. rrrrs rkeysz Headers.keysg #mm,da,,, cL|jDcgc]\}}| c}}Scc}}w)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. r>r?s rvalueszHeaders.valuesqrArBc |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. Nr>r$s ritemsz Headers.items{s}}QrcN|jjd|jdS)N()) __class____name__rr$s r__repr__zHeaders.__repr__s>>22DMMBBrcndj|jDcgc]}d|z c}ddgzScc}w)zkstr() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.z z%s: %s)joinr)rr/s r__str__zHeaders.__str__s2{{DMMBbHrMBBr7JKKBs 2c6t|jdS)Nz iso-8859-1)rencoder$s r __bytes__zHeaders.__bytes__s4y --rc|j|}|=|jj|j||j|f|S|S)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'.)r3rr'r)rr(r results r setdefaultzHeaders.setdefaultsR $ > MM $";";D"A))%0"2 3LMrc g}|"|j|}|j||jD]v\}}|j|}|"|j|jdd;|j|}|jt |jdd|x|j j|j|dj |fy)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; )rr'rFr rrrO)r_name_value_paramspartsrrs r add_headerzHeaders.add_headers   ..v6F LL MMO CDAq))!,Ay QYYsC01--a0 \!))C*=qAB  C d77> %@PQRr)N)rK __module__ __qualname____doc__rrr%r*r0r5r7r:r3r@rDrFrLrPrSrVr^rrrrs`6-:"O Q * F-- CL . Srr)Nr9)rarecompilerrrrbrrres3 BJJ2 3  \S\Sr