o
    .jd                     @  s  d dl mZ d dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dlmZ dd	lmZ dd
lmZmZmZmZmZ 	 G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZ G d!d" d"eZ!G d#d$ d$eZ"G d%d& d&eZ#G d'd( d(eZ$G d)d* d*eZ%G d+d, d,eZ&G d-d. d.eZ'G d/d0 d0eZ(G d1d2 d2eZ)G d3d4 d4eZ*G d5d6 d6e*Z+G d7d8 d8e*Z,G d9d: d:eZ-G d;d< d<eZ.G d=d> d>eZ/G d?d@ d@eZ0G dAdB dBe"Z1G dCdD dDeZ2G dEdF dFeZ3G dGdH dHe"Z4G dIdJ dJeZ5G dKdL dLeZ6G dMdN dNeZ7G dOdP dPeZ8G dQdR dReZ9G dSdT dTeZ:G dUdV dVeZ;G dWdX dXeZ<G dYdZ dZeZ=G d[d\ d\eZ>G d]d^ d^e"Z?G d_d` d`e"Z@G dadb dbe"ZAG dcdd ddeZBG dedf dfeZCG dgdh dheCZDG didj djeZEG dkdl dleZFdmS )n    )annotations)	b64decode	b64encode)datetimetimezone)utils)findall	fullmatch)quote)unquote   )Header)class_to_header_nameheader_content_splitprettify_header_namer
   r   c                      sJ   e Zd ZU dZdZded< g Zded< dZded	< dd fddZ  Z	S )CustomHeadera  
    This class is a helper to create ready-to-use Header object with creation assistance.
    Should NOT be instantiated.
    Use this class as a direct parent for creating ready-to-use header object. Inspire yourself with already defined
    class bellow this one.
    Fbool
__squash__	list[str]__tags__N
str | None__override__ initial_contentstrkwargsc                   sb   | j tkr	tdt | j jst| j nt| j j| | D ]\}}|du r*q!|| |< q!dS )z
        :param initial_content: Initial content of the Header if any.
        :param kwargs: Provided args. Any key that associate a None value are just ignored.
        z\You can not instantiate CustomHeader class. You may create first your class that inherit it.N)		__class__r   NotImplementedErrorsuper__init__r   r   r   items)selfr   r   	attributevaluer    Z/home/thesage/.local/lib/python3.10/site-packages/niquests/_vendor/kiss_headers/builder.pyr   '   s   


zCustomHeader.__init__r   )r   r   r   r   )
__name__
__module____qualname____doc__r   __annotations__r   r   r   __classcell__r%   r%   r$   r&   r      s   
 
r   c                      s<   e Zd ZdZdgZd fddZddd	ZdddZ  ZS )ContentSecurityPolicya4  
    Content-Security-Policy is the name of a HTTP response header
    that modern browsers use to enhance the security of the document (or web page).
    The Content-Security-Policy header allows you to restrict how resources such as
    JavaScript, CSS, or pretty much anything that the browser loads.
    responsepoliciesr   c                   st   t  d |D ]/}t|dks|d dvr td|d  dt|dkr0td|d  d| d|7 } qd	S )
a  
        :param policies: One policy consist of a list of str like ["default-src", "'none'"].
        >>> header = ContentSecurityPolicy(["default-src", "'none'"], ["img-src", "'self'", "img.example.com"])
        >>> repr(header)
        "Content-Security-Policy: default-src 'none'; img-src 'self' img.example.com"
        >>> header.get_policies_names()
        ['default-src', 'img-src']
        >>> header.get_policy_args("img-src")
        ["'self'", 'img.example.com']
        r   r   >   img-srcbase-urifont-src	child-src	frame-src	media-src	report-to	style-src
object-src
report-uri
script-src
worker-srcconnect-srcdefault-srcform-actionnavigate-tomanifest-srcplugin-typesprefetch-srcframe-ancestorssandboxzPolicy zO is not a valid one. See https://content-security-policy.com/ for instructions.r   z' need at least one argument to proceed. N)r   r   len
ValueErrorjoin)r!   r0   policyr$   r%   r&   r   H   s   zContentSecurityPolicy.__init__returnc                 C  s   dd | j D S )z+Fetch a list of policy name set in content.c                 S  s   g | ]	}| d d qS )rF   r   )split).0memberr%   r%   r&   
<listcomp>y   s    z<ContentSecurityPolicy.get_policies_names.<locals>.<listcomp>attrsr!   r%   r%   r&   get_policies_namesw      z(ContentSecurityPolicy.get_policies_namespolicy_namer   list[str] | Nonec                 C  sB   |  }| jD ]}|d}|d   |kr|dd   S qdS )z&Retrieve given arguments for a policy.rF   r   r   N)lowerrQ   rL   )r!   rU   rN   partsr%   r%   r&   get_policy_args{   s   

z%ContentSecurityPolicy.get_policy_args)r0   r   rK   r   )rU   r   rK   rV   )	r(   r)   r*   r+   r   r   rS   rY   r-   r%   r%   r$   r&   r.   >   s    
/r.   c                      sZ   e Zd ZU dZdZded< dgZded< 			dd fddZdddZddddZ	  Z
S )Accepta(  
    The Accept request HTTP header advertises which content types, expressed as MIME types,
    the client is able to understand. Using content negotiation, the server then selects one of
    the proposals, uses it and informs the client of its choice with the Content-Type response header.
    Tr   r   requestr   r   */*      ?mimer   	qualifierfloatr   r   c                   sX   t |ddkrtd| dd|dk r|ndi}|| t j|fi | dS )a  
        :param mime: Describe the MIME using this syntax <MIME_type/MIME_subtype>
        :param qualifier: Any value used is placed in an order of preference expressed using relative quality value called the weight.
        :param kwargs:
        >>> header = Accept("text/html", qualifier=0.8)
        >>> header.content
        'text/html; q="0.8"'
        >>> repr(header)
        'Accept: text/html; q="0.8"'
        >>> header.get_qualifier()
        0.8
        >>> header.get_mime()
        'text/html'
        /   MThe MIME should be described using this syntax <MIME_type/MIME_subtype> not ''qr^   N)rG   rL   rH   updater   r   )r!   r_   r`   r   argsr$   r%   r&   r      s   


zAccept.__init__rK   c                 C      | j D ]
}d|v r|  S qdS )z-Return defined mime in current accept header.rb   NrP   r!   elr%   r%   r&   get_mime   
   
zAccept.get_mime_defaultfloat | Nonec                 C     |  drtt| d S |S )zDReturn defined qualifier for specified mime. If not set, output 1.0.rf   hasra   r   r!   rn   r%   r%   r&   get_qualifier      zAccept.get_qualifier)r]   r^   )r_   r   r`   ra   r   r   rK   r   r^   rn   ro   rK   ro   )r(   r)   r*   r+   r   r,   r   r   rl   rt   r-   r%   r%   r$   r&   r[      s   
 
"r[   c                      sR   e Zd ZU dZddgZded< 			dd fddZdddZddddZ  Z	S )ContentTypea  
    The Content-Type entity header is used to indicate the media type of the resource.

    In responses, a Content-Type header tells the client what the content type of the returned content actually is.
    Browsers will do MIME sniffing in some cases and will not necessarily follow the value of this header;
    to prevent this behavior, the header X-Content-Type-Options can be set to nosniff.
    r\   r/   r   r   Nr_   r   charsetr   format_boundaryr   c                   s\   t |ddkrtd| d|r| nd||d}|| t j|fi | dS )aL  
        :param mime_type: The MIME type of the resource or the data. Format <MIME_type>/<MIME_subtype>.
        :param charset: The character encoding standard. Should be an IANA name.
        :param format_: Mostly used in IMAP, could be one of : original or flowed.
        :param boundary: For multipart entities the boundary directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message.
        :param kwargs:
        >>> header = ContentType("text/html", charset="utf-8")
        >>> repr(header)
        'Content-Type: text/html; charset="UTF-8"'
        >>> header.get_charset()
        'UTF-8'
        >>> header.get_mime()
        'text/html'
        rb   rc   rd   re   N)rz   formatr|   )rG   rL   rH   upperrg   r   r   )r!   r_   rz   r{   r|   r   rh   r$   r%   r&   r      s   

zContentType.__init__rK   c                 C  ri   )z$Return defined mime in content type.rb   NrP   rj   r%   r%   r&   rl      rm   zContentType.get_mime
ISO-8859-1rn   c                 C  s   |  drt| d S |S )zLExtract defined charset, if not present will return 'ISO-8859-1' by default.rz   )rr   r   rs   r%   r%   r&   get_charset   s   zContentType.get_charsetNNN)
r_   r   rz   r   r{   r   r|   r   r   r   rv   )r   )rn   r   rK   r   )
r(   r)   r*   r+   r   r,   r   rl   r   r-   r%   r%   r$   r&   ry      s   
 
&ry   c                      4   e Zd ZU dZdgZded< dd fd
dZ  ZS )XContentTypeOptionsaV  
    The X-Content-Type-Options response HTTP header is a marker used by the server to indicate that
    the MIME types advertised in the Content-Type headers should not be changed and be followed.
    This allows to opt-out of MIME type sniffing, or, in other words, it is a way to say that
    the webmasters knew what they were doing.
    r/   r   r   Tnosniffr   r   r   c                       t  j|rdndfi | dS )z
        :param nosniff: see https://fetch.spec.whatwg.org/#x-content-type-options-header
        :param kwargs:
        >>> header = XContentTypeOptions(nosniff=True)
        >>> repr(header)
        'X-Content-Type-Options: nosniff'
        r   r   Nr   r   )r!   r   r   r$   r%   r&   r     s    zXContentTypeOptions.__init__T)r   r   r   r   r(   r)   r*   r+   r   r,   r   r-   r%   r%   r$   r&   r      s   
 r   c                      sT   e Zd ZU dZddgZded< 					dd fddZdddZdddZ  Z	S )ContentDispositiona  
    In a regular HTTP response, the Content-Disposition response header is a header indicating
    if the content is expected to be displayed inline in the browser, that is, as a Web page or
    as part of a Web page, or as an attachment, that is downloaded and saved locally.
    r\   r/   r   r   inlineNdispositionr   namer   filenamefallback_filenamer|   r   c                   s   |dvrt d|r!z|d W n ty    t d| dw |||r-dt|dd nd	|d
}|| t j|fi | d	S )u^  
        :param disposition: Could be either inline, form-data, attachment or empty. Choose one. Default to inline.
        :param name: Is a string containing the name of the HTML field in the form that the content of this subpart refers to.
        :param filename: Is a string containing the original name of the file transmitted. The filename is always optional and must not be used blindly by the application. ASCII-US Only.
        :param fallback_filename: Fallback filename if filename parameter does not uses the encoding defined in RFC 5987. Will be UTF-8 (url-quote) encoded.
        :param boundary: For multipart entities the boundary directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message.
        :param kwargs:
        >>> header = ContentDisposition("attachment", filename="hello-world.pdf", fallback_filename="こんにちは世界.pdf")
        >>> repr(header)
        'Content-Disposition: attachment; filename="hello-world.pdf"; filename*="UTF-8\'\'%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF%E4%B8%96%E7%95%8C.pdf"'
        >>> header.get_disposition()
        'attachment'
        >>> header.get_filename_decoded()
        'こんにちは世界.pdf'
        )
attachmentr   	form-datar   zPDisposition should be either inline, form-data, attachment or empty. Choose one.ASCIIz>The filename should only contain valid ASCII characters. Not 'z!'. Use fallback_filename instead.zUTF-8''zutf-8)encodingN)r   r   	filename*r|   )rH   encodeUnicodeEncodeError	url_quoterg   r   r   )r!   r   r   r   r   r|   r   rh   r$   r%   r&   r     s2   

	
zContentDisposition.__init__rK   c                 C  s$   | j D ]}| dv r|  S qdS )z0Extract set disposition from Content-Disposition)r   r   r   N)rQ   rW   )r!   attrr%   r%   r&   get_dispositionP  s
   
z"ContentDisposition.get_dispositionc                 C  sZ   d| v r!zt t| d d\}}t||W S  ty    Y nw d| v r+t| d S dS )z9Retrieve and decode if necessary the associated filename.r   z''r   N)tupler   rL   url_unquoterH   )r!   r   encoded_filenamer%   r%   r&   get_filename_decodedX  s   z'ContentDisposition.get_filename_decoded)r   NNNN)r   r   r   r   r   r   r   r   r|   r   r   r   rv   )
r(   r)   r*   r+   r   r,   r   r   r   r-   r%   r%   r$   r&   r     s   
 
5r   c                      sF   e Zd ZU dZdgZded< d fd
dZdddZdddZ  Z	S )Authorizationz
    The HTTP Authorization request header contains the credentials to authenticate a user agent with a server,
    usually, but not necessarily, after the server has responded with a 401 Unauthorized status
    and the WWW-Authenticate header.
    r\   r   r   type_r   credentialsr   r   c                   s6   |  dvr
tdt j| d| fi | dS )ab  
        :param type_: Authentication type. A common type is "Basic". See IANA registry of Authentication schemes for others.
        :param credentials: Associated credentials to use. Preferably Base-64 encoded.
        >>> header = Authorization("Bearer", "base64encoded")
        >>> repr(header)
        'Authorization: Bearer base64encoded'
        )basicbearerdigesthobamutual	negotiateoauthzscram-sha-1zscram-sha-256vapidzaws4-hmac-sha256ntlmzJAuthorization type should exist in IANA registry of Authentication schemesrF   NrW   rH   r   r   )r!   r   r   r   r$   r%   r&   r   m  s   
zAuthorization.__init__rK   c                 C  s   | j jdddd S )z+Return the auth type used in Authorization.rF   r   maxsplitr   contentrL   rR   r%   r%   r&   get_auth_type     zAuthorization.get_auth_typec                 C  s   | j jdddd S )zOutput the credentials.rF   r   r   r   rR   r%   r%   r&   get_credentials  r   zAuthorization.get_credentials)r   r   r   r   r   r   rK   r   )
r(   r)   r*   r+   r   r,   r   r   r   r-   r%   r%   r$   r&   r   d  s   
 
r   c                      sH   e Zd ZdZdZ	dd fd
dZdd fddZ	ddddZ  ZS )BasicAuthorizationzr
    Same as Authorization header but simplified for the Basic method. Also an example of __override__ usage.
    r   latin1usernamer   passwordrz   r   r   c                   sF   d|v rt dt|d | |d}t jd|fi | dS )a  
        :param username:
        :param password:
        :param charset: By default, credentials are encoded using latin1 charset. You may want to choose otherwise.
        :param kwargs:
        >>> header = BasicAuthorization("azerty", "qwerty")
        >>> header
        Authorization: Basic YXplcnR5OnF3ZXJ0eQ==
        >>> header.get_username_password()
        ('azerty', 'qwerty')
        :z1The username cannot contain a single colon in it.asciiBasicN)rH   r   r   decoder   r   )r!   r   r   rz   r   b64_auth_contentr$   r%   r&   r     s   zBasicAuthorization.__init__$_BasicAuthorization__default_charsetrK   c                   s8   |    dkrtd|    dtt  |S )z<Decode base64 encoded credentials from Authorization header.r   zQOnly Authorization using Basic method is supported by BasicAuthorization. Given 'z'.)r   rW   rH   r   r   r   r   r!   r   r$   r%   r&   r     s
   z"BasicAuthorization.get_credentialstuple[str, ...]c                 C  s   t | |jdddS )zBExtract username and password as a tuple from Basic Authorization.r   r   r   )r   r   rL   r   r%   r%   r&   get_username_password  s   z(BasicAuthorization.get_username_password)r   )r   r   r   r   rz   r   r   r   )r   r   rK   r   )r   r   rK   r   )	r(   r)   r*   r+   r   r   r   r   r-   r%   r%   r$   r&   r     s    
r   c                      s2   e Zd ZU dZdgZded< d
 fdd	Z  ZS )ProxyAuthorizationa   
    The HTTP Proxy-Authorization request header contains the credentials to authenticate a user agent to a proxy server,
    usually after the server has responded with a 407 Proxy Authentication Required status
    and the Proxy-Authenticate header.
    r\   r   r   r   r   r   c                   s   t  || dS )z
        :param type_: Authentication type. A common type is "Basic". See IANA registry of Authentication schemes for others.
        :param credentials: Associated credentials to use. Preferably Base-64 encoded.
        Nr   )r!   r   r   r$   r%   r&   r     s   zProxyAuthorization.__init__)r   r   r   r   r   r%   r%   r$   r&   r        
 r   c                      s4   e Zd ZU dZdgZded< dd fddZ  ZS )Hostz
    The Host request header specifies the domain name of the server (for virtual hosting),
    and (optionally) the TCP port number on which the server is listening.
    r\   r   r   Nhostr   port
int | Noner   r   c                   s,   t  j||rdt| nd fi | dS )ar  
        :param host: The domain name of the server (for virtual hosting).
        :param port: TCP port number on which the server is listening.
        >>> header = Host("www.python.org")
        >>> repr(header)
        'Host: www.python.org'
        >>> header = Host("www.python.org", port=8000)
        >>> repr(header)
        'Host: www.python.org:8000'
        r   r   Nr   r   r   )r!   r   r   r   r$   r%   r&   r     s   ,zHost.__init__N)r   r   r   r   r   r   r   r%   r%   r$   r&   r        
 r   c                      *   e Zd ZdZddgZd
 fdd	Z  ZS )
Connectiona  
    The Connection general header controls whether or not the network connection stays open after the current transaction finishes.
    If the value sent is keep-alive, the connection is persistent and not closed, allowing for subsequent requests to the same server to be done.
    r\   r/   should_keep_aliver   r   r   c                   r   )z
        :param should_keep_alive: Indicates that the client would like to keep the connection open or not.
        :param kwargs:
        z
keep-alivecloseNr   )r!   r   r   r$   r%   r&   r         zConnection.__init__)r   r   r   r   r(   r)   r*   r+   r   r   r-   r%   r%   r$   r&   r     s    r   c                      s4   e Zd ZU dZddgZded< d fd
dZ  ZS )ContentLengthzr
    The Content-Length entity header indicates the size of the entity-body, in bytes, sent to the recipient.
    r\   r/   r   r   lengthintr   r   c                      t  jt|fi | dS )zH
        :param length: The length in decimal number of octets.
        Nr   )r!   r   r   r$   r%   r&   r     s   zContentLength.__init__)r   r   r   r   r   r%   r%   r$   r&   r      s   
 r   c                      s<   e Zd ZU dZdgZded< d fd	d
ZdddZ  ZS )Datezf
    The Date general HTTP header contains the date and time at which the message was originated.
    r/   r   r   my_datedatetime | strr   r   c                   s8   t  jt|tstj|tjddn|fi | dS )z
        :param my_date: Can either be a datetime that will be automatically converted or a raw string.
        :param kwargs:
        TusegmtN)	r   r   
isinstancer   r   format_datetime
astimezoner   utcr!   r   r   r$   r%   r&   r     s   
zDate.__init__rK   r   c                 C  s   t t| S )z1Parse and return a datetime according to content.)r   parsedate_to_datetimer   rR   r%   r%   r&   get_datetime!  s   zDate.get_datetimer   r   r   r   )rK   r   )	r(   r)   r*   r+   r   r,   r   r   r-   r%   r%   r$   r&   r     s
   
 r   c                      2   e Zd ZU dZdgZded< d fd	d
Z  ZS )CrossOriginResourcePolicyz
    The HTTP Cross-Origin-Resource-Policy response header conveys a desire that
    the browser blocks no-cors cross-origin/cross-site requests to the given resource.
    r/   r   r   rJ   r   r   r   c                   0   |  }|dvrtdt j|fi | dS )zs
        :param policy: Accepted values are same-site, same-origin or cross-origin.
        :param kwargs:
        )z	same-sitesame-originzcross-originz'{policy}' is not a recognized policy for Cross-Origin-Resource-Policy. Accepted values are same-site, same-origin or cross-origin.Nr   r!   rJ   r   r$   r%   r&   r   .     z"CrossOriginResourcePolicy.__init__rJ   r   r   r   r   r%   r%   r$   r&   r   &     
 r   c                      s,   e Zd ZdZdgZdZd
 fdd	Z  ZS )AllowzL
    The Allow header lists the set of methods supported by a resource.
    r/   Tsupported_verbr   r   r   c                   r   )a  
        :param supported_verb: Choose exactly one of "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE", "PURGE", "CONNECT" or "TRACE" HTTP verbs.
        :param kwargs:
        >>> header = Allow("POST")
        >>> repr(header)
        'Allow: POST'
        )	HEADGETPOSTPUTPATCHDELETEPURGECONNECTTRACEzT'{verb}' is not a supported verb. Please choose only one HTTP verb per Allow header.Nr~   rH   r   r   )r!   r   r   r$   r%   r&   r   E  s   zAllow.__init__)r   r   r   r   r(   r)   r*   r+   r   r   r   r-   r%   r%   r$   r&   r   =  s
    r   c                      s(   e Zd ZdZdgZd
 fdd	Z  ZS )Digestz`
    The Digest response HTTP header provides a digest of the requested resource. RFC 7231.
    r/   	algorithmr   r#   r   r   c                   s(   ||i}| | t jdi | dS )a  
        :param algorithm: Supported digest algorithms are defined in RFC 3230 and RFC 5843, and include SHA-256 and SHA-512.
        :param value: The result of applying the digest algorithm to the resource representation and encoding the result.
        :param kwargs:
        r   Nr'   rg   r   r   )r!   r   r#   r   rh   r$   r%   r&   r   h  s   
zDigest.__init__)r   r   r#   r   r   r   r   r%   r%   r$   r&   r   a      r   c                      s@   e Zd ZdZdgZd fddZdd	d
Z	ddddZ  ZS )CookiezyThe Cookie HTTP request header contains stored HTTP cookies previously sent by
    the server with the Set-Cookie header.r\   r   r   c                   s   t  jdi | dS )zM
        :param kwargs: Pair of cookie name associated with a value.
        r   Nr'   r   r!   r   r$   r%   r&   r   z  s   zCookie.__init__rK   r   c                 C  s   | j S )z5Retrieve all defined cookie names from Cookie header.rP   rR   r%   r%   r&   get_cookies_names  s   zCookie.get_cookies_namesNcookie_namer   _Cookie__defaultc                 C  s    || v rt | | ddS |S )z3Retrieve associated value with a given cookie name.\"r   )r   replace)r!   r   r   r%   r%   r&   get_cookie_value  s
   zCookie.get_cookie_valuer   r   rZ   r   )r   r   r   r   rK   r   )	r(   r)   r*   r+   r   r   r   r   r-   r%   r%   r$   r&   r   t  s    
r   c                      s~   e Zd ZU dZdgZded< 							d'd( fddZd)ddZd)ddZd*dd Z	d+d!d"Z
d,d#d$Zd,d%d&Z  ZS )-	SetCookiez
    The Set-Cookie HTTP response header is used to send cookies from the server to the user agent,
    so the user agent can send them back to the server later.
    r/   r   r   NFTr   r   cookie_valueexpiresdatetime | str | Nonemax_ager   domainr   pathsamesite	is_securer   is_httponlyr   c
                   s   |D ]
}|dv rt dq|r| dvrt d||dt|tr,tj|tjddn|d|d	|d
|d|i}|	|
 t
 jdi | |rK| d7 } |	rS| d7 } dS dS )a  
        :param cookie_name: Can be any US-ASCII characters, except control characters, spaces, or tabs.
        :param cookie_value: Can include any US-ASCII characters excluding control characters, Whitespace, double quotes, comma, semicolon, and backslash.
        :param expires: The maximum lifetime of the cookie as an HTTP-date timestamp. Provided datetime will be converted automatically.
        :param max_age: Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
        :param domain: Hosts to where the cookie will be sent. If omitted, defaults to the host of the current document URL, not including subdomains.
        :param path: A path that must exist in the requested URL, or the browser won't send the Cookie header.
        :param samesite: Asserts that a cookie must not be sent with cross-origin requests, providing some protection against cross-site request forgery attacks.
        :param is_secure: A secure cookie is only sent to the server when a request is made with the https: scheme.
        :param is_httponly: Forbids JavaScript from accessing the cookie.
        :param kwargs:
        >   <>@,;:\"/[]?={}zJThe cookie name can not contains any of the following char: <>@,;:"/[]?={})strictlaxnonezISamesite attribute can only be one of the following: Strict, Lax or None.r  Tr   max-ager  r  r  r   SecureHttpOnlyNr'   )rH   rW   r   r   r   r   r   r   r   rg   r   r   )r!   r   r  r  r  r  r  r  r	  r
  r   letterrh   r$   r%   r&   r     s:   
zSetCookie.__init__rK   c                 C     d| v S )z<Determine if the cookie can only be accessed by the browser.r  r%   rR   r%   r%   r&   is_http_only     zSetCookie.is_http_onlyc                 C  r  )z(Determine if the cookie is TLS/SSL only.r  r%   rR   r%   r%   r&   r	    r  zSetCookie.is_securedatetime | Nonec                 C  s    |  drtt| d S dS )z$Retrieve the parsed expiration date.r  N)rr   r   r   r   rR   r%   r%   r&   
get_expire  s
   zSetCookie.get_expirec                 C     d| v rt t| d S dS )z/Getting the max-age value as an integer if set.r  Nr   r   rR   r%   r%   r&   get_max_age     zSetCookie.get_max_agec                 C  
   | j d S )zExtract the cookie name.r   rP   rR   r%   r%   r&   get_cookie_name     
zSetCookie.get_cookie_namec                 C  s   t | |   ddS )zExtract the cookie value.r   r   )r   r  r   rR   r%   r%   r&   r     s   zSetCookie.get_cookie_value)NNNNNFT)r   r   r  r   r  r  r  r   r  r   r  r   r  r   r	  r   r
  r   r   r   rK   r   )rK   r  rK   r   r   )r(   r)   r*   r+   r   r,   r   r  r	  r  r  r  r   r-   r%   r%   r$   r&   r    s"   
 
;



r  c                      sV   e Zd ZU dZdgZded< 		dd fddZdddZdddZdddZ	  Z
S )StrictTransportSecurityz
    The HTTP Strict-Transport-Security response header (often abbreviated as HSTS) lets a web site
    tell browsers that it should only be accessed using HTTPS, instead of using HTTP.
    r/   r   r   Fr  r   does_includesubdomainsr   
is_preloadr   r   c                   sD   d|i}| | t jdi | |r| d7 } |r | d7 } dS dS )a#  
        :param max_age: The time, in seconds, that the browser should remember that a site is only to be accessed using HTTPS.
        :param does_includesubdomains: If this optional parameter is specified, this rule applies to all of the site's subdomains as well.
        :param is_preload: Preloading Strict Transport Security. Google maintains an HSTS preload service. By following the guidelines and successfully submitting your domain, browsers will never connect to your domain using an insecure connection.
        :param kwargs:
        r  r   includeSubDomainspreloadNr'   r   )r!   r  r"  r#  r   rh   r$   r%   r&   r     s   
z StrictTransportSecurity.__init__rK   c                 C  r  )z<Verify if this rule applies to all of the site's subdomains.r$  r%   rR   r%   r%   r&   r"    r  z.StrictTransportSecurity.does_includesubdomainsc                 C  r  )z=Verify if Preloading Strict Transport Security should be set.r%  r%   rR   r%   r%   r&   should_preload  r  z&StrictTransportSecurity.should_preloadr   c                 C  s   |  drtt| d S dS )zCGet the time, in seconds, if set, that the browser should remember.r  N)rr   r   r   rR   r%   r%   r&   r    ru   z#StrictTransportSecurity.get_max_age)FF)r  r   r"  r   r#  r   r   r   r  r   )r(   r)   r*   r+   r   r,   r   r"  r&  r  r-   r%   r%   r$   r&   r!    s   
 

r!  c                      s4   e Zd ZU dZddgZded< d
 fdd	Z  ZS )UpgradeInsecureRequestsu  
    The HTTP Upgrade-Insecure-Requests request header sends a signal to the server expressing
    the client’s preference for an encrypted and authenticated response, and that it
    can successfully handle the upgrade-insecure-requests CSP directive.
    r\   r/   r   r   r   r   c                   s   t  jdi | d S )N1r(  r   r   r$   r%   r&   r   &  s   z UpgradeInsecureRequests.__init__r   r   r%   r%   r$   r&   r'    s   
 r'  c                      s>   e Zd ZU dZdgZded< dZded< d fddZ  ZS )TransferEncodingz{
    The Transfer-Encoding header specifies the form of encoding used to safely transfer the payload body to the user.
    r/   r   r   Tr   r   methodr   r   r   c                   r   )p
        :param method: Either chunked, compress, deflate, gzip, identity or br.
        :param kwargs:
        )chunkedcompressdeflategzipidentitybr*zoYou should choose between 'chunked', 'compress', 'deflate', 'gzip', 'identity' or 'br' for the encoding method.Nr   r!   r+  r   r$   r%   r&   r   2  s   
	zTransferEncoding.__init__r+  r   r   r   	r(   r)   r*   r+   r   r,   r   r   r-   r%   r%   r$   r&   r*  *  s
   
 r*  c                      r   )ContentEncodinga_  
    The Content-Encoding entity header is used to compress the media-type. When present,
    its value indicates which encodings were applied to the entity-body. It lets the client
    know how to decode in order to obtain the media-type referenced by the Content-Type header.

    If multiple, keep them in the order in which they were applied.
    r\   r/   r+  r   r   r   c                      t  j|fi | dS )r,  Nr   r4  r$   r%   r&   r   Y  s   zContentEncoding.__init__r5  r   r%   r%   r$   r&   r7  N  s    r7  c                      s6   e Zd ZdZdgZdd fd
dZddddZ  ZS )AcceptEncodinga;  
    The Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm,
    the client is able to understand. Using content negotiation, the server selects one of the proposals,
    uses it and informs the client of its choice with the Content-Encoding response header.
    r\   r^   r+  r   r`   ra   r   r   c                   s6   d|dkr|ndi}| | t j|fi | dS )a  
        :param method: Either chunked, compress, deflate, gzip, identity, br or a wildcard.
        :param qualifier: Any value used is placed in an order of preference expressed using relative quality value called the weight.
        :param kwargs:
        rf   r^   Nr   )r!   r+  r`   r   rh   r$   r%   r&   r   k  s   
zAcceptEncoding.__init__rn   ro   rK   c                 C  rp   )zHReturn defined qualifier for specified encoding. If not set, output 1.0.rf   rq   rs   r%   r%   r&   rt   w  ru   zAcceptEncoding.get_qualifierrw   )r+  r   r`   ra   r   r   rx   )r(   r)   r*   r+   r   r   rt   r-   r%   r%   r$   r&   r9  b  s
    r9  c                      r   )Dntz
    The DNT (Do Not Track) request header indicates the user's tracking preference.
    It lets users indicate whether they would prefer privacy rather than personalized content.
    r\   r   r   Ftracking_consentr   r   r   c                   r   )z
        :param tracking_consent: The user prefers to allow tracking on the target site or not.
        :param kwargs:
        0r(  Nr   )r!   r;  r   r$   r%   r&   r     r   zDnt.__init__F)r;  r   r   r   r   r%   r%   r$   r&   r:  |  r   r:  c                      r   )	UserAgentz
    The User-Agent request header is a characteristic string that lets servers and network
    peers identify the application, operating system, vendor, and/or version of the requesting user agent.
    r\   r   r   characteristicsr   r   r   c                      t  j|fi | d S r   r   )r!   r?  r   r$   r%   r&   r        zUserAgent.__init__)r?  r   r   r   r   r%   r%   r$   r&   r>    r   r>  c                      sx   e Zd ZU dZdgZded< dZded< 			d!d" fddZd#ddZd#ddZ	d$ddZ
d%ddZd&dd Z  ZS )'AltSvcz
    The Alt-Svc HTTP response header is used to advertise alternative services through which
    the same resource can be reached. An alternative service is defined by a protocol/host/port combination.
    r/   r   r   Tr   r   Nprotocol_idr   alt_authorityr  r   versionsrV   
do_persistbool | Noner   r   c              
     sJ   ||d|d|r	dndd|rd |ndi}|| t jdi | dS )a  
        :param protocol_id: The ALPN protocol identifier. Examples include h2 for HTTP/2 and h3-25 for draft 25 of the HTTP/3 protocol.
        :param alt_authority: The quoted string specifying the alternative authority which consists of an optional host override, a colon, and a mandatory port number.
        :param max_age: The number of seconds for which the alternative service is considered fresh. If omitted, it defaults to 24 hours.
        :param versions: List of supported versions of the protocol id if the protocol id can be ambiguous. (like QUIC)
        :param do_persist: Use the parameter to ensures that the entry is not deleted through network configuration changes.
        :param kwargs:
        mapersistr   Nv,r%   )rI   rg   r   r   )r!   rC  rD  r  rE  rF  r   rh   r$   r%   r&   r     s   
zAltSvc.__init__rK   c                 C  r  )z!Get the ALPN protocol identifier.r   rP   rR   r%   r%   r&   get_protocol_id  r  zAltSvc.get_protocol_idc                 C  s   t | |   S )ztExtract the alternative authority which consists of an optional host override, a colon, and a mandatory port number.)r   rL  rR   r%   r%   r&   get_alt_authority  rT   zAltSvc.get_alt_authorityc                 C  r  )zfOutput the number of seconds for which the alternative service is considered fresh. None if undefined.rH  Nr  rR   r%   r%   r&   r    r  zAltSvc.get_max_agec                 C  s   d| v rt | d dS dS )zMMay return, if available, a list of versions of the ALPN protocol identifier.rJ  rK  N)r   rL   rR   r%   r%   r&   get_versions  ru   zAltSvc.get_versionsc                 C  s   d| v rt | d dkS dS )zgVerify if the entry should not be deleted through network configuration changes. None if no indication.rI  r(  N)r   rR   r%   r%   r&   should_persist  r  zAltSvc.should_persistr   )rC  r   rD  r   r  r   rE  rV   rF  rG  r   r   r   r   )rK   rV   )rK   rG  )r(   r)   r*   r+   r   r,   r   r   rL  rM  r  rN  rO  r-   r%   r%   r$   r&   rB    s   
 



rB  c                      s8   e Zd ZU dZddgZded< 	dd fddZ  ZS )	Forwardedz
    The Forwarded header contains information from the client-facing side of proxy servers
    that is altered or lost when a proxy is involved in the path of the request.
    r\   r/   r   r   Nbyr   for_using_protor   r   r   c                   s.   ||||d}| | t jdi | dS )a  
        :param by: The interface where the request came in to the proxy server. Could be an IP address, an obfuscated identifier or "unknown".
        :param for_: The client that initiated the request and subsequent proxies in a chain of proxies.
        :param host: The Host request header field as received by the proxy.
        :param using_proto: Indicates which protocol was used to make the request (typically "http" or "https").
        :param kwargs:
        )rQ  forr   protor   Nr'   r   )r!   rQ  rR  rS  r   r   rh   r$   r%   r&   r     s   
zForwarded.__init__r   )
rQ  r   rR  r   rS  r   r   r   r   r   r   r%   r%   r$   r&   rP    s
   
 rP  c                      r   )LastModifiedz
    The Last-Modified response HTTP header contains the date and time at which the origin server
    believes the resource was last modified. It is used as a validator
    to determine if a resource received or stored is the same.
    r/   r   r   r   r   r   r   c                   r8  )z8
        :param my_date:
        :param kwargs:
        Nr   r   r$   r%   r&   r        zLastModified.__init__r   r   r%   r%   r$   r&   rV    r   rV  c                      r   )Referera  
    The Referer request header contains the address of the previous web page from which a link to the currently
    requested page was followed. The Referer header allows servers to identify where people are
    visiting them from and may use that data for analytics, logging, or optimized caching, for example.

    Note that referer is actually a misspelling of the word "referrer". See https://en.wikipedia.org/wiki/HTTP_referer
    r\   r   r   urlr   r   r   c                   r8  )z
        :param url: An absolute or partial address of the previous web page from which a link to the currently requested page was followed. URL fragments not included.
        :param kwargs:
        Nr   )r!   rY  r   r$   r%   r&   r     rW  zReferer.__init__)rY  r   r   r   r   r%   r%   r$   r&   rX    s   
 rX  c                      s6   e Zd ZU dZdgZded< dZd fd
dZ  ZS )ReferrerPolicyz
    The Referrer-Policy HTTP header controls how much referrer information
    (sent via the Referer header) should be included with requests.
    r/   r   r   TrJ   r   r   r   c                   s0   |dvrt d| dt j|fi | dS )z
        :param policy: Either "no-referrer", "no-referrer-when-downgrade", "origin", "origin-when-cross-origin", "same-origin", "strict-origin", "strict-origin-when-cross-origin", "unsafe-url"
        :param kwargs:
        )zno-referrerzno-referrer-when-downgradeoriginzorigin-when-cross-originr   zstrict-originzstrict-origin-when-cross-originz
unsafe-urlre   zT' is not a valid referrer policy. Please choose only one per ReferrerPolicy instanceN)rH   r   r   r   r$   r%   r&   r     s
   

zReferrerPolicy.__init__r   r6  r%   r%   r$   r&   rZ    s
   
 rZ  c                      r   )
RetryAfterz
    The Retry-After response HTTP header indicates how long the user agent should wait
    before making a follow-up request.
    r/   r   r   delay_or_datedatetime | intr   r   c                   s*   t  jt|tr
|nt|fi | d S r   )r   r   r   r   r   )r!   r]  r   r$   r%   r&   r   ;  s   
zRetryAfter.__init__)r]  r^  r   r   r   r%   r%   r$   r&   r\  3  r   r\  c                      sN   e Zd ZU dZdZded< dgZded< 		dd fddZddddZ  Z	S )AcceptLanguagez
    The Accept-Language request HTTP header advertises which languages the client is able to understand,
    and which locale variant is preferred. (By languages, we mean natural languages,
    such as English, and not programming languages.)
    Tr   r   r\   r   r   r3  r^   languager   r`   ra   r   r   c                   s6   d|dk r|ndi}| | t j|fi | dS )aK  
        :param language: A language tag (which is sometimes referred to as a "locale identifier"). This consists of a 2-3 letter base language tag representing the language.
        :param qualifier: Any value placed in an order of preference expressed using a relative quality value called weight.
        :param kwargs:
        rf   r^   Nr   )r!   r`  r`   r   rh   r$   r%   r&   r   N  s   

zAcceptLanguage.__init__rn   ro   rK   c                 C  rp   )zHReturn defined qualifier for specified language. If not set, output 1.0.rf   rq   rs   r%   r%   r&   rt   _  ru   zAcceptLanguage.get_qualifier)r3  r^   )r`  r   r`   ra   r   r   rw   rx   )
r(   r)   r*   r+   r   r,   r   r   rt   r-   r%   r%   r$   r&   r_  D  s   
 r_  c                      s6   e Zd ZU dZdgZded< 	dd fddZ  ZS )Etagz
    The ETag HTTP response header is an identifier for a specific version of a resource.
    It lets caches be more efficient and save bandwidth, as a web server does not need to
    resend a full response if the content has not changed.
    r/   r   r   F
etag_valuer   is_a_weak_validatorr   r   r   c                   s.   t  jdj|r	dndt|dfi | dS )a*  
        :param etag_value: Entity tag uniquely representing the requested resource. ASCII string only. Not quoted.
        :param is_a_weak_validator: Indicates that a weak validator is used. Weak etags are easy to generate, but are far less useful for comparisons.
        :param kwargs:
        z{weak_validation_cond}{etag}zW/r   )weak_validation_condetagN)r   r   r}   r
   )r!   rb  rc  r   r$   r%   r&   r   m  s   

zEtag.__init__r=  )rb  r   rc  r   r   r   r   r%   r%   r$   r&   ra  d  s
   
 ra  c                      r   )XFrameOptionsa.  
    The X-Frame-Options HTTP response header can be used to indicate whether or not a browser
    should be allowed to render a page in a <frame>, <iframe>, <embed> or <object>. Sites can use this to
    avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.
    r/   r   r   rJ   r   r   r   c                   r   )zY
        :param policy: Can be either DENY or SAMEORIGIN.
        :param kwargs:
        )DENY
SAMEORIGINzU'{policy}' is not a valid X-Frame-Options policy. Choose between DENY and SAMEORIGIN.Nr   r   r$   r%   r&   r     r   zXFrameOptions.__init__r   r   r%   r%   r$   r&   rf    r   rf  c                      s:   e Zd ZU dZdgZded< 			dd fddZ  ZS )XXssProtectionax  
    The HTTP X-XSS-Protection response header is a feature of Internet Explorer, Chrome and Safari that
    stops pages from loading when they detect reflected cross-site scripting (XSS) attacks.
    Although these protections are largely unnecessary in modern browsers when sites implement a strong
    Content-Security-Policy that disables the use of inline JavaScript
    r/   r   r   TFNenable_filteringr   enable_block_rendering
report_urir   r   c                   sP   |du rt  jdi | dS |rdnd|d}|| t  jdi | dS )	aW  
        :param enable_filtering: Enables XSS filtering (usually default in browsers). If a cross-site scripting attack is detected, the browser will sanitize the page (remove the unsafe parts).
        :param enable_block_rendering: Rather than sanitizing the page, the browser will prevent rendering of the page if an attack is detected.
        :param report_uri: (Chromium only) If a cross-site scripting attack is detected, the browser will sanitize the page and report the violation. This uses the functionality of the CSP report-uri directive to send a report.
        :param kwargs:
        Fr<  Nblock)modereportr(  )r<  r)  )r   r   rg   )r!   rj  rk  rl  r   rh   r$   r%   r&   r     s   

zXXssProtection.__init__)TFN)rj  r   rk  r   rl  r   r   r   r   r%   r%   r$   r&   ri    s   
 ri  c                      sR   e Zd ZU dZdgZded< dZ			dd fddZdddZdddZ	  Z
S )WwwAuthenticatez
    The HTTP WWW-Authenticate response header defines the authentication
    method that should be used to gain access to a resource.
    Fair-Warning : This header is like none other and is harder to parse. It need a specific case.
    r/   r   r   TNrealmSecured area	auth_typer   	challenger   r#   r   c                   s4   t  j|r	|d nd | d| dfi | dS )a  
        >>> www_authenticate = WwwAuthenticate("Basic", "realm", "Secured area")
        >>> repr(www_authenticate)
        'Www-Authenticate: Basic realm="Secured area"'
        >>> headers = www_authenticate + WwwAuthenticate(challenge="charset", value="UTF-8")
        >>> repr(headers)
        'Www-Authenticate: Basic realm="Secured area", charset="UTF-8"'
        >>> www_authenticate.get_challenge()
        ('realm', 'Secured area')
        >>> www_authenticate.get_auth_type()
        'Basic'
        rF   r   z=""Nr   )r!   rs  rt  r#   r   r$   r%   r&   r     s
   
zWwwAuthenticate.__init__rK   c                 C  s.   t t| d}t|dkrd|vr|d S dS )z0Retrieve given authentication method if defined.rF   r   =r   N)r   r   rG   )r!   rX   r%   r%   r&   r     s   zWwwAuthenticate.get_auth_typetuple[str, str]c                 C  sN   t t| d}|D ]}d|v r"t|jddd\}}|t|f  S q	td)zUOutput a tuple containing the challenge and the associated value. Raises :ValueError:rF   rv  r   r   zXWwwAuthenticate header does not seems to contain a valid content. No challenge detected.)r   r   r   rL   r   rH   )r!   rX   partrt  r#   r%   r%   r&   get_challenge  s   zWwwAuthenticate.get_challenge)Nrq  rr  )rs  r   rt  r   r#   r   r   r   rv   )rK   rw  )r(   r)   r*   r+   r   r,   r   r   r   ry  r-   r%   r%   r$   r&   rp    s   
 
	rp  c                      s*   e Zd ZdZdgZd
d fdd	Z  ZS )XDnsPrefetchControla:  
    The X-DNS-Prefetch-Control HTTP response header controls DNS prefetching, a feature by which browsers proactively
    perform domain name resolution on both links that the user may choose to follow as well as URLs
    for items referenced by the document, including images, CSS, JavaScript, and so forth.
    r/   Tenabler   r   r   c                   r   )zW
        :param enable: Toggle the specified behaviour.
        :param kwargs:
        onoffNr   )r!   r{  r   r$   r%   r&   r     r   zXDnsPrefetchControl.__init__r   )r{  r   r   r   r   r%   r%   r$   r&   rz    s    rz  c                      (   e Zd ZdZdgZd	 fddZ  ZS )
Locationz
    The Location response header indicates the URL to redirect a page to.
    It only provides a meaning when served with a 3xx (redirection) or 201 (created) status response.
    r/   urir   r   r   c                   r8  )ze
        :param uri: A relative (to the request URL) or absolute URL.
        :param kwargs:
        Nr   )r!   r  r   r$   r%   r&   r     rW  zLocation.__init__)r  r   r   r   r   r%   r%   r$   r&   r        r  c                      r   )Froma_  
    The From request header contains an Internet email address for a human user who controls the requesting user agent.
    If you are running a robotic user agent (e.g. a crawler), the From header should be sent, so you can be contacted
    if problems occur on servers, such as if the robot is sending excessive, unwanted, or invalid requests.
    r\   r   r   emailr   r   r   c                   s6   t d|du rtd| dt j|fi | dS )zd
        :param email: A machine-usable email address. See RFC 5322.
        :param kwargs:
        z2(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)Nre   z ' is not a valid RFC 5322 email.)r	   rH   r   r   )r!   r  r   r$   r%   r&   r      s   
zFrom.__init__)r  r   r   r   r   r%   r%   r$   r&   r    r   r  c                      sZ   e Zd ZdZdgZd fddZdddZdddZdddZdddZ	dddZ
  ZS )ContentRangezr
    The Content-Range response HTTP header indicates where in a full body message a partial message belongs.
    r/   unitr   startr   endsize	str | intr   r   c                   s.   t  j| d| d| d| fi | dS )af  
        :param unit: The unit in which ranges is specified. This is usually bytes.
        :param start: An integer in the given unit indicating the beginning of the request range.
        :param end: An integer in the given unit indicating the end of the requested range.
        :param size: The total size of the document (or '*' if unknown).
        :param kwargs:
        >>> header = ContentRange("bytes", 0, 1024, 4096)
        >>> repr(header)
        'Content-Range: bytes 0-1024/4096'
        >>> header.get_size()
        4096
        >>> header.unpack()
        ('bytes', '0', '1024', '4096')
        rF   -rb   Nr   )r!   r  r  r  r  r   r$   r%   r&   r   7  s   .zContentRange.__init__rK   tuple[str, str, str, str]c                 C  s   t dt| d S )z1Provide a basic way to parse ContentRange format.zA^([0-9a-zA-Z*]+) ([0-9a-zA-Z*]+)-([0-9a-zA-Z*]+)/([0-9a-zA-Z*]+)$r   )r   r   rR   r%   r%   r&   unpackO  s   zContentRange.unpackc                 C  s   |   d S )z/Retrieve the unit in which ranges is specified.r   )r  rR   r%   r%   r&   get_unitV  s   zContentRange.get_unitc                 C     t |  d S )z'Get the beginning of the request range.r   r   r  rR   r%   r%   r&   	get_startZ  rT   zContentRange.get_startc                 C  r  )z#Get the end of the requested range.rc   r  rR   r%   r%   r&   get_end^  rT   zContentRange.get_endc                 C  s    |   d }| rt|S |S )z7Get the total size of the document (or '*' if unknown).   )r  isdigitr   )r!   r  r%   r%   r&   get_sizeb  s   zContentRange.get_size)
r  r   r  r   r  r   r  r  r   r   )rK   r  r   )rK   r   )rK   r  )r(   r)   r*   r+   r   r   r  r  r  r  r  r-   r%   r%   r$   r&   r  0  s    



r  c                      s:   e Zd ZdZddgZdZ					dd fddZ  ZS )CacheControlz
    The Cache-Control HTTP header holds directives (instructions) for caching in
    both requests and responses. A given directive in a request does not mean the
    same directive should be in the response.
    r\   r/   TN	directiver   r  r   	max_stale	min_freshs_maxager   c                   sp   |du|du|du|du|dug ddkrtd||||d}|| t j|dur/|ndfi | dS )aL  
        Pass only one parameter per CacheControl instance.
        :param directive: Could be one of must-revalidate, no-cache, no-store, no-transform, public, private, proxy-revalidate, only-if-cached, no-transform.
        :param max_age: The maximum amount of time a resource is considered fresh. Unlike Expires, this directive is relative to the time of the request.
        :param max_stale: Indicates the client will accept a stale response. An optional value in seconds indicates the upper limit of staleness the client will accept.
        :param min_fresh: Indicates the client wants a response that will still be fresh for at least the specified number of seconds.
        :param s_maxage: Overrides max-age or the Expires header, but only for shared caches (e.g., proxies). Ignored by private caches.
        :param kwargs:
        NTr   zEYou should only pass one parameter to a single CacheControl instance.)r  z	max-stalez	min-freshzs-maxager   )countrH   rg   r   r   )r!   r  r  r  r  r  r   rh   r$   r%   r&   r   r  s$   
$zCacheControl.__init__)NNNNN)r  r   r  r   r  r   r  r   r  r   r   r   r   r%   r%   r$   r&   r  h  s    r  c                      r~  )
Expiresz
    The Expires header contains the date/time after which the response is considered stale.
    Invalid dates, like the value 0, represent a date in the past and mean that the resource is already expired.
    r/   datetime_or_customr   r   r   c                   r@  r   r   )r!   r  r   r$   r%   r&   r     rA  zExpires.__init__)r  r   r   r   r   r%   r%   r$   r&   r    r  r  c                      r~  )
IfModifiedSincezQ
    The If-Modified-Since request HTTP header makes the request conditional
    r\   dtr   r   r   c                   r8  z3
        :param dt:
        :param kwargs:
        Nr   r!   r  r   r$   r%   r&   r     rW  zIfModifiedSince.__init__r  r   r   r   r   r%   r%   r$   r&   r    r   r  c                      "   e Zd ZdZd fddZ  ZS )	IfUnmodifiedSincezS
    The If-Unmodified-Since request HTTP header makes the request conditional
    r  r   r   r   c                   r8  r  r   r  r$   r%   r&   r     rW  zIfUnmodifiedSince.__init__r  r(   r)   r*   r+   r   r-   r%   r%   r$   r&   r    s    r  c                      s4   e Zd ZdZdZddgZ		dd fddZ  ZS )	KeepAlivez
    The Keep-Alive general header allows the sender to hint about how the connection may be used to
    set a timeout and a maximum amount of requests.
    Tr\   r/   Ntimeoutr   max_r   r   c                   sB   |dur|durt d||d}|| t jdi | dS )a
  
        :param timeout: indicating the minimum amount of time an idle connection has to be kept opened (in seconds).
        :param max: indicating the maximum number of requests that can be sent on this connection before closing it.
        :param kwargs:
        NzWCan only provide one parameter per KeepAlive instance, either timeout or max, not both.)r  maxr   r'   )rH   rg   r   r   )r!   r  r  r   rh   r$   r%   r&   r     s   

zKeepAlive.__init__)NN)r  r   r  r   r   r   r(   r)   r*   r+   r   r   r   r-   r%   r%   r$   r&   r    s    r  c                      ,   e Zd ZdZdZdgZd
 fdd	Z  ZS )IfMatcha  
    The If-Match HTTP request header makes the request conditional. For GET and HEAD methods,
    the server will send back the requested resource only if it matches one of the listed ETags.
    For PUT and other non-safe methods, it will only upload the resource in this case.
    Tr\   rb  r   r   r   c                   r   )z
        :param etag_value: Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (like "675af34563dc-tr34").
        :param kwargs:
        N)r   r   r
   r!   rb  r   r$   r%   r&   r        zIfMatch.__init__rb  r   r   r   r  r%   r%   r$   r&   r    s
    r  c                      r  )	IfNoneMatcha{  
    The If-None-Match HTTP request header makes the request conditional. For GET and HEAD methods,
    the server will send back the requested resource, with a 200 status, only if it doesn't have an ETag matching
    the given ones. For other methods, the request will be processed only if the eventually existing resource's
    ETag doesn't match any of the values listed.
    rb  r   r   r   c                   r@  r   r   r  r$   r%   r&   r     rA  zIfNoneMatch.__init__r  r  r%   r%   r$   r&   r    s    r  c                      r~  )
Serveru   The Server header describes the software used by the origin server that handled the request —
    that is, the server that generated the response.r/   productr   r   r   c                   r8  )z
        :param product: The name of the software or product that handled the request. Usually in a format similar to User-Agent.
        :param kwargs:
        Nr   )r!   r  r   r$   r%   r&   r     rW  zServer.__init__)r  r   r   r   r   r%   r%   r$   r&   r    s    r  c                      r  )VaryzThe Vary HTTP response header determines how to match future request headers to decide whether a cached response
    can be used rather than requesting a fresh one from the origin server.Tr/   header_namer   r   r   c                   r   )z
        :param header_name: An header name to take into account when deciding whether or not a cached response can be used.
        :param kwargs:
        N)r   r   r   )r!   r  r   r$   r%   r&   r     r  zVary.__init__)r  r   r   r   r  r%   r%   r$   r&   r    s
    r  N)G
__future__r   base64r   r   r   r   r  r   rer   r	   urllib.parser
   r   r   r   modelsr   r   r   r   r   r.   r[   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r!  r'  r*  r7  r9  r:  r>  rB  rP  rV  rX  rZ  r\  r_  ra  rf  ri  rp  rz  r  r  r  r  r  r  r  r  r  r  r  r  r%   r%   r%   r&   <module>   sv    &J8=R14$`.$: %883 