Ϫfs#dZddlmZddlmZmZmZmZm Z m Z mZm Z m Z m Z mZddlmZmZe dZdedefdZd edefd ZeGd d Zd gZy )z2 An API for storing HTTP header names and values. )Sequence) AnyStrDictIteratorListMappingOptionalrTupleTypeVarUnionoverload)cmp comparable_Tnamereturncdj|jdDcgc]}|jc}Scc}w)z Return a byte string which is capitalized using '-' as a word separator. @param name: The name of the header to capitalize. @return: The given header capitalized using '-' as a word separator. -)joinsplit capitalize)rwords :/usr/lib/python3/dist-packages/twisted/web/http_headers.py_dashCapitalizers1 99DJJt4DEDdoo'E FFEs=headerComponentc@dj|jS)z Replace linear whitespace (C{\n}, C{\r\n}, C{\r}) in a header key or value with a single space. @param headerComponent: The header key or value to sanitize. @return: The sanitized header key or value.  )r splitlines)rs r_sanitizeLinearWhitespacer(s 99_//1 22c 4eZdZdZdddddddd Z d"d eeeeefd d fd Z d e fdZ dZ de e efd efdZdZded efdZded d fdZede e efdeed d fdZede e efdee d d fdZede e efdee e efd d fdZde e efded d fdZde e efde e efd d fdZeded eeefdZededed e eeeffdZ d"dedeed e eeeeffdZd eeeeeffd Zded efd!Zy )#Headersa@ Stores HTTP headers in a key and multiple value format. When passed L{str}, 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-MD5sDNTsETagsP3PsTEsWWW-AuthenticatesX-XSS-Protection)s content-md5sdntsetagsp3psteswww-authenticatesx-xss-protectionN rawHeadersrcli|_|+|jD]\}}|j||yyN) _rawHeadersitems setRawHeaders)selfr#rvaluess r__init__zHeaders.__init__TsC68  ! * 0 0 2 1 f""40 1 "r cbdj|jj|jS)zR Return a string fully describing the headers set on this object. z{}({!r}))format __class____name__r&r)s r__repr__zHeaders.__repr__]s-  NN # #     r ct|trNtt|jj t|jj St S)zu Define L{Headers} instances as being equal to each other if they have the same raw headers. ) isinstancer"rsortedr&r'NotImplemented)r)others r__cmp__zHeaders.__cmp__fsP eW %t''--/0&9J9J9P9P9R2S r rct|tr|jjdS|jS)z Encode the name of a header (eg 'Content-Type') to an ISO-8859-1 encoded bytestring if required. @param name: A HTTP header name @return: C{name}, encoded if required, lowercased z iso-8859-1)r3strlowerencoder)rs r _encodeNamezHeaders._encodeNameqs1 dC ::<&&|4 4zz|r c8|j|jS)zg Return a copy of itself with the same headers set. @return: A new L{Headers} )r.r&r0s rcopyz Headers.copy~s ~~d..//r c<|j||jvS)z Check for the existence of a given header. @param name: The name of the HTTP header to check for. @return: C{True} if the header exists, otherwise C{False}. )r=r&r<s r hasHeaderzHeaders.hasHeaders %)9)999r cZ|jj|j|dy)z Remove the named header from this header object. @param name: The name of the HTTP header to remove. @return: L{None} N)r&popr=r<s r removeHeaderzHeaders.removeHeaders% T--d3T:r r*cyr%r)rr*s rr(zHeaders.setRawHeaders r cyr%rFrGs rr(zHeaders.setRawHeadersrHr cyr%rFrGs rr(zHeaders.setRawHeaderss r c t|tstd|dt|dt|tt fstdt|dt |D]6\}}t|tt frtd|dt|dt|j|}g}|D]@}t|t r|jd}n|}|jt|B||j|<y ) a Sets the raw representation of the given header. @param name: The name of the HTTP header to set the values for. @param values: A list of strings each one being a header value of the given name. @raise TypeError: Raised if C{values} is not a sequence of L{bytes} or L{str}, or if C{name} is not L{bytes} or L{str}. @return: L{None} z Header entry z* should be sequence but found instance of z insteadHeader name is an instance of , not bytes or strzHeader value at position z is an instance of utf8N) r3 _Sequence TypeErrortypebytesr9 enumeraterr=r;appendr&) r)rr*countvalue_name encodedValuesv_vs rr(zHeaders.setRawHeaderss&),,0$v,@  $ -0d>PQ &f- LE5eeS\2U  *$*:*:4*@A%'  @A!S!XXf%  !:2!> ?  @#0r rVct|ttfstdt |dt|ttfstdt |d|j j t|j|gjtt|tr|jdy|y)z Add a new raw value for the given header. @param name: The name of the header for which to set the value. @param value: The value to set for the named header. rLrMzHeader value is an instance of rNN) r3rRr9rPrQr& setdefaultrr=rTr;)r)rrVs r addRawHeaderzHeaders.addRawHeaders$ -0d>PQ %%."&u+0  ## %d&6&6t&< =r & %(25#(> V$  DI  r cyr%rFr<s r getRawHeaderszHeaders.getRawHeadersrHr defaultcyr%rF)r)rr`s rr_zHeaders.getRawHeadersrHr c|j|}|jj|g}|s|St|tr|Dcgc]}|j dc}S|Scc}w)a Returns a sequence of headers matching the given name as the raw string given. @param name: The name of the HTTP header to get the values of. @param default: The value to return if no header with the given C{name} exists. @return: If the named header is present, a sequence of its values. Otherwise, C{default}. rN)r=r&getr3r9decode)r)rr` encodedNamer*rYs rr_zHeaders.getRawHeaderssb&&t, !!%%k26N dC .45AHHV$5 5 6sA#c#zK|jjD]\}}|j||fyw)z Return an iterator of key, value pairs of all headers contained in this object, as L{bytes}. The keys are capitalized in canonical capitalization. N)r&r'_canonicalNameCaps)r)krYs rgetAllRawHeaderszHeaders.getAllRawHeaderss@ $$**, 0DAq))!,a/ / 0s9;cL|jj|t|S)z Return the canonical name for the given header. @param name: The all-lowercase header name to capitalize in its canonical form. @return: The canonical name of the header. ) _caseMappingsrcrr<s rrgzHeaders._canonicalNameCapss"!!%%dOD,ABBr r%)r/ __module__ __qualname____doc__rkr rrrr+r9r1r7r rRr=r?boolrArDr r(objectr]r_rrr rirgrFr rr"r"4s*'00MCG1WVXf-=%=>?1 1 #   c5j 1 e 0:f::;;D; %U "3 Xe_ QU   %U "3 Xc] t   #u*% /7c5j8I/J   -0%U "3-0V-0-0^ sEz!2 5e;L QU 6 & Xhv6F-G   & 2 %@PRT@T:U  59%-b\ x"- .00(51G+H"I0 Cu C Cr r"N)rncollections.abcrrOtypingrrrrrr r r r r twisted.python.compatrrrrRrrr"__all__rFr rrus 2    2 T]G%GEG 3u 3 3 oCoC oCd +r