U
    (Q^9/                     @   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 G dd deZG dd deZdS )    )datetime)	timedelta   )string_types)CallbackDict)dump_age)dump_header)dump_options_header)	http_date)	parse_age)
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   J/tmp/pip-install-bd4o36v9/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_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 )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   mimetypec   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_paramsm   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   pragmav   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      sL   


	
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 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   charsetr7   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&   r7   )dr   r   r   	on_update   s    zACommonResponseDescriptorsMixin.mimetype_params.<locals>.on_updater5   r!   r'   )r   r7   r#   r   )r   rA   r@   r   r   r   r(      s    	z.CommonResponseDescriptorsMixin.mimetype_paramsZ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.)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krdS | r6t 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)r7   r#   isdigitr   utcnowr   r2   r   r>   r   r   r   retry_after   s    z*CommonResponseDescriptorsMixin.retry_afterc                 C   sH   |d krd| j kr| j d= d S t|tr2t|}nt|}|| j d< d S )NrC   zRetry-After)r7   
isinstancer   r
   strr>   r   r   r   rG   
  s    


c                    s&    fdd} fdd}t |||dS )Nc                    s     fdd}t  j|S )Nc                    s.   | s j krj  = n| r*|  j  < d S N)r7   Z	to_header)Z
header_set)namer   r   r   rA     s    
zMCommonResponseDescriptorsMixin._set_property.<locals>.fget.<locals>.on_update)r   r7   r#   )r   rA   rK   r   r   fget  s    z:CommonResponseDescriptorsMixin._set_property.<locals>.fgetc                    s6   |s| j  = n$t|tr$|| j  < nt|| j  < d S rJ   )r7   rH   r   r   r>   rL   r   r   fset   s
    

z:CommonResponseDescriptorsMixin._set_property.<locals>.fsetr   )r3   )rK   r   rM   rN   r   rL   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.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.)N)r*   r+   r,   r-   r3   r&   setterr(   r   locationr   r   Zager.   r2   rI   r   content_locationr/   r0   r   r
   r1   expiresZlast_modifiedrG   rO   varyZcontent_languageZallowr   r   r   r   r4      s   


				




r4   N)r   r   _compatr   Zdatastructuresr   httpr   r   r	   r
   r   r   r   r   utilsr   r   r   r   Zwsgir   objectr   r4   r   r   r   r   <module>   s$   l