
Á«‘_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 Gd d „  d e ƒ Z Gd 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)ÚCommonRequestDescriptorsMixinzÜA 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_TYPEÚdoczçThe 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.c             C   s   t  |  j ƒ S)zìThe 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   úH/tmp/pip-build-5gj8f0j9/Werkzeug/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.9ZHTTP_REFERERzúThe 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_DATENz¢The 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_FORWARDSzÙThe 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   s1   t  |  d ƒ s- t |  j j d d ƒ ƒ |  _ d  S)NÚ_parsed_content_typer   Ú )Úhasattrr   r   Úgetr   )r   r   r   r   Ú_parse_content_type_   s    z1CommonRequestDescriptorsMixin._parse_content_typec             C   s   |  j  ƒ  |  j d j ƒ  S)zñLike :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   Úlower)r   r   r   r   Úmimetypee   s    
z&CommonRequestDescriptorsMixin.mimetypec             C   s   |  j  ƒ  |  j d S)z¨The 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 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      s8   							
	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),ÚCommonResponseDescriptorsMixinzÃA 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   s3   |  j  j d ƒ } | r/ | j d ƒ d j ƒ  Sd S)z0The mimetype (content type without charset etc.)zcontent-typeú;r   N)Úheadersr!   ÚsplitÚstrip)r   Úctr   r   r   r$   ‰   s    z'CommonResponseDescriptorsMixin.mimetypec             C   s   t  | |  j ƒ |  j d <d  S)NzContent-Type)r   Úcharsetr4   )r   Úvaluer   r   r   r$   �   s    c                s>   ‡  f d d †  } t  ˆ  j j d d ƒ ƒ d } t | | ƒ S)zÆThe 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)NzContent-Type)r
   r$   r4   )Úd)r   r   r   Ú	on_update�   s    zACommonResponseDescriptorsMixin.mimetype_params.<locals>.on_updatezcontent-typer   r%   )r   r4   r!   r   )r   r;   r:   r   )r   r   r&   ”   s    	z.CommonResponseDescriptorsMixin.mimetype_paramsÚLocationr   zÈThe 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.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.zContent-TypezçThe 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.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-LocationzîThe 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-Policyz…The Content-Security-Policy header adds an additional layer of
        security to help detect and mitigate certain types of attacks.z#Content-Security-Policy-Report-Onlyz¦The Content-Security-Policy-Report-Only header adds a csp policy
        that is not enforced but is reported thereby helping detect
        certain types of attacks.ÚDatez¢The 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Expiresz®The 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-Modifiedz”The Last-Modified entity-header field indicates the date
        and time at which the origin server believes the variant was
        last modified.c             C   sU   |  j  j d ƒ } | d k r" d S| j ƒ  rK t j ƒ  t d t | ƒ ƒ St | ƒ 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.
        zretry-afterNÚseconds)r4   r!   Úisdigitr   Úutcnowr   r0   r   )r   r9   r   r   r   Úretry_after  s    z*CommonResponseDescriptorsMixin.retry_afterc             C   sd   | d  k r) d |  j  k r% |  j  d =d  St | t ƒ rG t | ƒ } n t | ƒ } | |  j  d <d  S)Nzretry-afterzRetry-After)r4   Ú
isinstancer   r   Ústr)r   r9   r   r   r   rA     s    
c                s7   ‡  f d d †  } ‡  f d d †  } t  | | d | ƒS)Nc                s.   ‡ ‡  f d d †  } t  ˆ  j j ˆ ƒ | ƒ S)Nc                s@   |  r# ˆ  ˆ j  k r# ˆ j  ˆ  =n |  r< |  j ƒ  ˆ j  ˆ  <d  S)N)r4   Z	to_header)Z
header_set)Únamer   r   r   r;   +  s    zMCommonResponseDescriptorsMixin._set_property.<locals>.fget.<locals>.on_update)r   r4   r!   )r   r;   )rD   )r   r   Úfget*  s    z:CommonResponseDescriptorsMixin._set_property.<locals>.fgetc                sI   | s |  j  ˆ  =n2 t | t ƒ r2 | |  j  ˆ  <n t | ƒ |  j  ˆ  <d  S)N)r4   rB   r   r	   )r   r9   )rD   r   r   Úfset3  s
    z:CommonResponseDescriptorsMixin._set_property.<locals>.fsetr   )r1   )rD   r   rE   rF   r   )rD   r   Ú_set_property)  s    	z,CommonResponseDescriptorsMixin._set_propertyZVaryzóThe 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-LanguagezíThe 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.Z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.)"r(   r)   r*   r+   r1   r$   Úsetterr&   r   Úlocationr   r   Zager,   r0   rC   r   Úcontent_locationr-   r.   r   r   Zcontent_security_policyZ#content_security_policy_report_onlyr   r   r/   ÚexpiresZlast_modifiedrA   rG   ÚvaryZcontent_languageZallowr   r   r   r   r2   ƒ   s”   															r2   N)r   r   Ú_compatr   Zdatastructuresr   Úhttpr   r   r	   r
   r   r   r   r   r   r   Úutilsr   r   r   r   Zwsgir   Úobjectr   r2   r   r   r   r   Ú<module>   s(   l