fnTdZddlZejdZddZGddZdS) 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|ht|dkrU|st|r2|dddd}|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. Nr\z\\"z\"z="=)len tspecialssearchreplace)paramvaluequotes 6/opt/alt/python311/lib64/python3.11/wsgiref/headers.py _formatparamr s  SZZ!^^  ,I$$U++ ,MM$//77UCCE %uuu- -#eeUU+ + c|eZdZdZddZdZdZdZdZdZ d Z d Z dd Z d Z d ZdZdZdZdZdZdZdS)Headersz,Manage a collection of HTTP response headersNcj||ng}t|turtd||_dS)Nz+Headers must be a list of name/value tuples)typelist TypeError_headers_convert_string_type)selfheaderskvs r__init__zHeaders.__init__sA$0''b == $ $IJJ J  - -rct|tur|Stdt |)zConvert/check value type.z1Header names/values must be of type str (got {0}))rstrAssertionErrorformatrepr)rr s rrzHeaders._convert_string_type)sB ;;#  L%%+VDKK%8%8:: :rc*t|jS)z9Return the total number of headers, including duplicates.)rrrs r__len__zHeaders.__len__0s4=!!!rc||=|j||||fdS)zSet the value of a header.N)rappendr)rnamevals r __setitem__zHeaders.__setitem__4sV J   & &t , ,d.G.G.L.L M O O O O Orc|fd|jD|jdd<dS)zyDelete all occurrences of a header, if present. Does *not* raise an exception if the header is missing. cPg|]"}|dk |#S)rlower.0kvr)s r z'Headers.__delitem__..@s/PPP2"Q%++--4:O:OB:O:O:OrNrr/rrr)s `r __delitem__zHeaders.__delitem__:sL ((66PPPPPPP aaarc,||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. getr5s r __getitem__zHeaders.__getitem__Bsxx~~rc0||duS)z/Return true if the message contains the header.Nr8r5s r __contains__zHeaders.__contains__Msxx~~T))rcx|fd|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. c\g|](}|dk |d)S)rrr.r0s rr3z#Headers.get_all..[s3EEE"A1D1D11D1D1Drr4r5s `rget_allzHeaders.get_allRs<((66EEEE EEEErc||}|jD]!\}}||kr|cS"|S)z:Get the first header value for 'name', or return 'default'r4)rr)defaultrrs rr9z Headers.get^sV((66=  CAawwyy$rc$d|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. cg|]\}}|SrDr1rrs rr3z Headers.keys..o,,,da,,,rrr%s rkeysz Headers.keysg-,dm,,,,rc$d|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. cg|]\}}|SrDrDrEs rr3z"Headers.values..yrFrrGr%s rvalueszHeaders.valuesqrIrc |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. NrGr%s ritemsz Headers.items{s}QQQrc0|jjd|jdS)N()) __class____name__rr%s r__repr__zHeaders.__repr__s>222DMMMBBrcTdd|jDddgzS)zkstr() returns the formatted headers, complete with end line, suitable for direct HTTP transmission.z cg|]}d|zS)z%s: %srD)r1r2s rr3z#Headers.__str__..sBBBbHrMBBBr)joinrr%s r__str__zHeaders.__str__s0{{BBDMBBBBr7JKKKrcFt|dS)Nz iso-8859-1)r encoder%s r __bytes__zHeaders.__bytes__s4yy ---rc||}|D|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'.)r9rr(r)rr)r results r setdefaultzHeaders.setdefaultsb $ > M $";";D"A"A))%00"2 3 3 3LMrc 4g}|*||}|||D]\}}||}|*||ddF||}|t |dd||j||d|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; )rr(rNr rrrX)r_name_value_paramspartsrrs r add_headerzHeaders.add_headers   ..v66F LL MMOO C CDAq))!,,Ay QYYsC001111--a00 \!))C*=*=qAABBBB d77>> %@P@PQRRRRRr)N)rS __module__ __qualname____doc__rrr&r+r6r:r<r?r9rHrLrNrTrYr\r_rgrDrrrrs766----:::"""OOO QQQ   *** F F F------   CCCLLL ...   SSSSSrr)Nr)rjrecompiler rrrDrrrms BJ2 3 3     \S\S\S\S\S\S\S\S\S\Sr