o
    #H_2                     @   s  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 deZG d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                   @   s   e Zd ZdZedddZedd ZedddZed	d
dZ	edddZ
eddeddZeddeddZdd Zedd Zedd Zed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                 C   s
   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self r   l/var/www/mymoneyjar/AispApp/AispApp/venv/lib/python2.7/site-packages/werkzeug/wrappers/common_descriptors.pycontent_length'   s   
z,CommonRequestDescriptorsMixin.content_lengthZ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.9Z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).Z	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.Z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                 C   s&   t | dst| jdd| _d S d S )N_parsed_content_typer    )hasattrr   r   getr#   r   r   r   r   _parse_content_type_   s
   

z1CommonRequestDescriptorsMixin._parse_content_typec                 C   s   |    | 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   r   r   r   mimetypee   s   z&CommonRequestDescriptorsMixin.mimetypec                 C   s   |    | 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   r   r   r   mimetype_paramso   s   
z-CommonRequestDescriptorsMixin.mimetype_paramsc                 C   s   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.
        ZHTTP_PRAGMAr$   )r   r   r&   r   r   r   r   pragmax   s   z$CommonRequestDescriptorsMixin.pragma)__name__
__module____qualname____doc__r   content_typer   r    content_encodingcontent_md5Zreferrerr   dateintZmax_forwardsr'   propertyr)   r+   r,   r   r   r   r   r      sN    


	
r   c                   @   s:  e Zd ZdZedd Zejdd Zedd Zeddd	Z	ed
de
edd	Zeddd	Zeddeedd	Zeddd	Zeddd	Zeddd	Zeddeedd	Zeddeedd	Zeddeedd	Zeddeedd	Zeddeed d	Zed!d" Zejd#d" Zd,d$d%Zed&d'd	Zed(d)d	Z ed*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                 C   s&   | j d}|r|dd  S dS )z0The mimetype (content type without charset etc.)content-type;r   N)headersr&   splitstrip)r   ctr   r   r   r)      s   z'CommonResponseDescriptorsMixin.mimetypec                 C   s   t || j| jd< d S NContent-Type)r   charsetr:   r   valuer   r   r   r)      s   c                    s,    fd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                    s   t  j|  jd< d S r>   )r
   r)   r:   )dr   r   r   	on_update   s   zACommonResponseDescriptorsMixin.mimetype_params.<locals>.on_updater8   r$   r*   )r   r:   r&   r   )r   rD   rC   r   r   r   r+      s   	
z.CommonResponseDescriptorsMixin.mimetype_params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   Z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.r?   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"   Z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                 C   s>   | j d}|du rdS | rt tt|d 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)r:   r&   isdigitr   utcnowr   r5   r   rA   r   r   r   retry_after  s   z*CommonResponseDescriptorsMixin.retry_afterc                 C   sH   |d u rd| j v r| j d= d S t|trt|}nt|}|| j d< d S )NrG   zRetry-After)r:   
isinstancer   r   strrA   r   r   r   rK     s   


c                    s&    fdd} fdd}t |||dS )Nc                    s     fdd}t  j|S )Nc                    s4   | s j v rj  = d S | r|  j  < d S d S N)r:   	to_header)
header_set)namer   r   r   rD   +  s
   zMCommonResponseDescriptorsMixin._set_property.<locals>.fget.<locals>.on_update)r   r:   r&   )r   rD   rQ   r   r   fget*  s   z:CommonResponseDescriptorsMixin._set_property.<locals>.fgetc                    s:   |s| j  = d S t|tr|| j  < d S t|| j  < d S rN   )r:   rL   r   r	   rA   rR   r   r   fset3  s
   
z:CommonResponseDescriptorsMixin._set_property.<locals>.fsetr   )r6   )rQ   r   rS   rT   r   rR   r   _set_property)  s   	z,CommonResponseDescriptorsMixin._set_propertyZ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.rN   )"r-   r.   r/   r0   r6   r)   setterr+   r   locationr   r   ager1   r5   rM   r    content_locationr2   r3   r   r   Zcontent_security_policyZ#content_security_policy_report_onlyr   r   r4   expireslast_modifiedrK   rU   ZvaryZcontent_languageallowr   r   r   r   r7      s    


					




r7   N)r   r   _compatr   datastructuresr   httpr   r   r	   r
   r   r   r   r   r   r   utilsr   r   r   r   wsgir   objectr   r7   r   r   r   r   <module>   s*    l