
    wdf2                     "   d dl m Z  d dl mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d de          Z G d de          ZdS )    )datetime)	timedelta   )string_types)CallbackDict)dump_age)dump_csp_header)dump_header)dump_options_header)	http_date)	parse_age)parse_csp_header)
parse_date)parse_options_header)parse_set_header)cached_property)environ_property)get_content_type)header_property)get_content_lengthc                      e Zd ZdZ edd          Zed             Z edd          Z edd	          Z	 ed
d          Z
 edded          Z edded          Zd Zed             Zed             Zed             ZdS )CommonRequestDescriptorsMixinzA mixin for :class:`BaseRequest` subclasses.  Request objects that
    mix this class in will automatically get descriptors for a couple of
    HTTP headers with automatic type conversion.

    .. versionadded:: 0.5
    CONTENT_TYPEThe Content-Type entity-header field indicates the media
        type of the entity-body sent to the recipient or, in the case of
        the HEAD method, the media type that would have been sent had
        the request been a GET.docc                 *    t          | j                  S )zThe Content-Length entity-header field indicates the size of the
        entity-body in bytes or, in the case of the HEAD method, the size of
        the entity-body that would have been sent had the request been a
        GET.
        )r   environselfs    i/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/werkzeug/wrappers/common_descriptors.pycontent_lengthz,CommonRequestDescriptorsMixin.content_length'   s     "$,///    HTTP_CONTENT_ENCODINGa  The Content-Encoding entity-header field is used as a
        modifier to the media-type. When present, its value indicates
        what additional content codings have been applied to the
        entity-body, and thus what decoding mechanisms must be applied
        in order to obtain the media-type referenced by the Content-Type
        header field.

        .. versionadded:: 0.9HTTP_CONTENT_MD5a  The Content-MD5 entity-header field, as defined in
        RFC 1864, is an MD5 digest of the entity-body for the purpose of
        providing an end-to-end message integrity check (MIC) of the
        entity-body. (Note: a MIC is good for detecting accidental
        modification of the entity-body in transit, but is not proof
        against malicious attacks.)

        .. versionadded:: 0.9HTTP_REFERERzThe Referer[sic] request-header field allows the client
        to specify, for the server's benefit, the address (URI) of the
        resource from which the Request-URI was obtained (the
        "referrer", although the header field is misspelled).	HTTP_DATENThe Date general-header field represents the date and
        time at which the message was originated, having the same
        semantics as orig-date in RFC 822.HTTP_MAX_FORWARDSzThe Max-Forwards request-header field provides a
        mechanism with the TRACE and OPTIONS methods to limit the number
        of proxies or gateways that can forward the request to the next
        inbound server.c                     t          | d          s/t          | j                            dd                    | _        d S d S )N_parsed_content_typer    )hasattrr   r   getr+   r   s    r!   _parse_content_typez1CommonRequestDescriptorsMixin._parse_content_type_   sL    t344 	(<  44) )D%%%	 	r#   c                 h    |                                   | j        d                                         S )zLike :attr:`content_type`, but without parameters (eg, without
        charset, type etc.) and always lowercase.  For example if the content
        type is ``text/HTML; charset=utf-8`` the mimetype would be
        ``'text/html'``.
        r   )r/   r+   lowerr   s    r!   mimetypez&CommonRequestDescriptorsMixin.mimetypee   s0     	  """(+11333r#   c                 D    |                                   | j        d         S )zThe mimetype parameters as dict.  For example if the content
        type is ``text/html; charset=utf-8`` the params would be
        ``{'charset': 'utf-8'}``.
           )r/   r+   r   s    r!   mimetype_paramsz-CommonRequestDescriptorsMixin.mimetype_paramso   s$     	  """(++r#   c                 R    t          | j                            dd                    S )aj  The Pragma general-header field is used to include
        implementation-specific directives that might apply to any recipient
        along the request/response chain.  All pragma directives specify
        optional behavior from the viewpoint of the protocol; however, some
        systems MAY require that behavior be consistent with the directives.
        HTTP_PRAGMAr,   )r   r   r.   r   s    r!   pragmaz$CommonRequestDescriptorsMixin.pragmax   s$       0 0 C CDDDr#   )__name__
__module____qualname____doc__r   content_typer   r"   content_encodingcontent_md5referrerr   dateintmax_forwardsr/   propertyr2   r5   r8    r#   r!   r   r      sr         $##  L 0 0 _0 ('!
 
 
 #"!
 
 
K  A  H .	  D $#	  L   4 4 X4 , , X, E E _E E Er#   r   c                   N   e Zd ZdZed             Zej        d             Zed             Z edd          Z	 edd	e
ed
          Z edd          Z edd	eed          Z edd          Z edd          Z edd          Z edd	eed          Z edd	eed          Z edd	eed          Z edd	eed          Z edd	eed          Zed             Zej        d              Zd(d!Z ed"d#          Z ed$d%          Z  ed&d'          Z![d	S ))CommonResponseDescriptorsMixinzA mixin for :class:`BaseResponse` subclasses.  Response objects that
    mix this class in will automatically get descriptors for a couple of
    HTTP headers with automatic type conversion.
    c                     | j                             d          }|r-|                    d          d                                         S dS )z0The mimetype (content type without charset etc.)content-type;r   N)headersr.   splitstrip)r    cts     r!   r2   z'CommonResponseDescriptorsMixin.mimetype   sL     \n-- 	,88C==#))+++	, 	,r#   c                 @    t          || j                  | j        d<   d S NContent-Type)r   charsetrK   r    values     r!   r2   z'CommonResponseDescriptorsMixin.mimetype   s     '7t|'L'L^$$$r#   c                       fd}t           j                            dd                    d         }t          ||          S )zThe mimetype parameters as dict. For example if the
        content type is ``text/html; charset=utf-8`` the params would be
        ``{'charset': 'utf-8'}``.

        .. versionadded:: 0.5
        c                 B    t          j        |           j        d<   d S rP   )r   r2   rK   )dr    s    r!   	on_updatezACommonResponseDescriptorsMixin.mimetype_params.<locals>.on_update   s!    +>t}a+P+PDL(((r#   rI   r,   r4   )r   rK   r.   r   )r    rX   rW   s   `  r!   r5   z.CommonResponseDescriptorsMixin.mimetype_params   sW    	Q 	Q 	Q 	Q 	Q !!1!1."!E!EFFqIAy)))r#   LocationzThe Location response-header field is used to redirect
        the recipient to a location other than the Request-URI for
        completion of the request or identification of a new
        resource.r   AgeNa  The Age response-header field conveys the sender's
        estimate of the amount of time since the response (or its
        revalidation) was generated at the origin server.

        Age values are non-negative decimal integers, representing time
        in seconds.rQ   r   zContent-Lengtha  The Content-Length entity-header field indicates the size
        of the entity-body, in decimal number of OCTETs, sent to the
        recipient or, in the case of the HEAD method, the size of the
        entity-body that would have been sent had the request been a
        GET.zContent-LocationzThe Content-Location entity-header field MAY be used to
        supply the resource location for the entity enclosed in the
        message when that entity is accessible from a location separate
        from the requested resource's URI.zContent-Encodingab  The Content-Encoding entity-header field is used as a
        modifier to the media-type. When present, its value indicates
        what additional content codings have been applied to the
        entity-body, and thus what decoding mechanisms must be applied
        in order to obtain the media-type referenced by the Content-Type
        header field.zContent-MD5al  The Content-MD5 entity-header field, as defined in
        RFC 1864, is an MD5 digest of the entity-body for the purpose of
        providing an end-to-end message integrity check (MIC) of the
        entity-body. (Note: a MIC is good for detecting accidental
        modification of the entity-body in transit, but is not proof
        against malicious attacks.)zContent-Security-PolicyzThe Content-Security-Policy header adds an additional layer of
        security to help detect and mitigate certain types of attacks.z#Content-Security-Policy-Report-OnlyzThe Content-Security-Policy-Report-Only header adds a csp policy
        that is not enforced but is reported thereby helping detect
        certain types of attacks.Dater(   ExpireszThe Expires entity-header field gives the date/time after
        which the response is considered stale. A stale cache entry may
        not normally be returned by a cache.zLast-ModifiedzThe Last-Modified entity-header field indicates the date
        and time at which the origin server believes the variant was
        last modified.c                     | j                             d          }|dS |                                r1t          j                    t          t          |                    z   S t          |          S )a   The Retry-After response-header field can be used with a
        503 (Service Unavailable) response to indicate how long the
        service is expected to be unavailable to the requesting client.

        Time in seconds until expiration or date.
        retry-afterN)seconds)rK   r.   isdigitr   utcnowr   rB   r   rS   s     r!   retry_afterz*CommonResponseDescriptorsMixin.retry_after  sf       //=F]]__ 	E?$$yU'D'D'DDD%   r#   c                     |d| j         v r| j         d= d S t          |t                    rt          |          }nt	          |          }|| j         d<   d S )Nr^   zRetry-After)rK   
isinstancer   r   strrS   s     r!   rb   z*CommonResponseDescriptorsMixin.retry_after  sa    =,,L/Fx(( 	e$$EEJJE&+]###r#   c                 <      fd} fd}t          |||          S )Nc                 b      fd}t           j                                      |          S )Nc                 r    | sj         v r
j         = d S | r|                                 j         <   d S d S N)rK   	to_header)
header_setnamer    s    r!   rX   zMCommonResponseDescriptorsMixin._set_property.<locals>.fget.<locals>.on_update+  s[    ! @ddl&:&:T*** @)3)=)=)?)?DL&&&@ @r#   )r   rK   r.   )r    rX   rl   s   ` r!   fgetz:CommonResponseDescriptorsMixin._set_property.<locals>.fget*  sJ    @ @ @ @ @ @ $DL$4$4T$:$:IFFFr#   c                     |s
| j         = d S t          |t                    r|| j         <   d S t          |          | j         <   d S ri   )rK   rd   r   r
   )r    rT   rl   s     r!   fsetz:CommonResponseDescriptorsMixin._set_property.<locals>.fset3  sY     8L&&&E<00 8%*T"""%0%7%7T"""r#   r   )rD   )rl   r   rm   ro   s   `   r!   _set_propertyz,CommonResponseDescriptorsMixin._set_property)  sQ    	G 	G 	G 	G 	G	8 	8 	8 	8 	8 d,,,,r#   VaryzThe Vary field value indicates the set of request-header
        fields that fully determines, while the response is fresh,
        whether a cache is permitted to use the response to reply to a
        subsequent request without revalidation.zContent-LanguagezThe Content-Language entity-header field describes the
        natural language(s) of the intended audience for the enclosed
        entity. Note that this might not be equivalent to all the
        languages used within the entity-body.AllowaR  The Allow entity-header field lists the set of methods
        supported by the resource identified by the Request-URI. The
        purpose of this field is strictly to inform the recipient of
        valid methods associated with the resource. An Allow header
        field MUST be present in a 405 (Method Not Allowed)
        response.ri   )"r9   r:   r;   r<   rD   r2   setterr5   r   locationr   r   ager=   rB   re   r"   content_locationr>   r?   r   r	   content_security_policy#content_security_policy_report_onlyr   r   rA   expireslast_modifiedrb   rp   varycontent_languageallowrE   r#   r!   rG   rG      s        
 , , X, _M M _M * * X*   H /  C #?#  L %_
 
 
N '.   '   "/'  K .o!J   +:/-%+ + +' ?.  D o0  G $O  M ! ! X! 	, 	, 	,- - - -( =4  D %}2   M  E 	r#   rG   N)r   r   _compatr   datastructuresr   httpr   r	   r
   r   r   r   r   r   r   r   utilsr   r   r   r   wsgir   objectr   rG   rE   r#   r!   <module>r      s               " " " " " " ) ) ) ) ) )       " " " " " "       & & & & & &             # # # # # #       ' ' ' ' ' ' # # # # # # # # # # # # $ $ $ $ $ $ $ $ $ $ $ $ # # # # # # % % % % % %iE iE iE iE iEF iE iE iEXR R R R RV R R R R Rr#   