ó
ù¢TQc           @@ s…  d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d  d l m Z y d  d l m	 Z	 Wn! e
 k
 r d  d l	 m	 Z	 n Xd  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 m Z d  d l m Z m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ d e j  f d „  ƒ  YZ! d e! f d „  ƒ  YZ" d e! f d „  ƒ  YZ# d e# f d „  ƒ  YZ$ d e" f d „  ƒ  YZ% d e% f d „  ƒ  YZ& d e% f d „  ƒ  YZ' d e" f d „  ƒ  YZ( d  e" f d! „  ƒ  YZ) d" e" f d# „  ƒ  YZ* d$ e" f d% „  ƒ  YZ+ d& e" f d' „  ƒ  YZ, d( e" f d) „  ƒ  YZ- d* e" f d+ „  ƒ  YZ. d, e/ f d- „  ƒ  YZ0 d S(.   i    (   t   absolute_importt   unicode_literalsN(   t   Header(   t   urlparse(   t   settings(   t   signals(   t   signing(   t   SuspiciousOperation(   t   SimpleCookie(   t   sixt   timezone(   t   force_bytest
   iri_to_uri(   t   cookie_date(   t   mapt   BadHeaderErrorc           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s-   ../Django//lib/python/django/http/response.pyR      s   t   HttpResponseBasec           B@ s  e  Z d  Z d Z d d d d „ Z d „  Z e j r? e Z	 n e Z
 e d „ Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z e Z d „  Z d d „ Z d d d d d e e d „ Z d d „ Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   uÖ   
    An HTTP response base class with dictionary-accessed headers.

    This class doesn't handle content. It should not be used directly.
    Use the HttpResponse and StreamingHttpResponse subclasses instead.
    iÈ   c         C@ s‘   i  |  _  t j |  _ g  |  _ d  |  _ | rF t j d t	 ƒ | } n  | se d t j
 |  j f } n  t ƒ  |  _ | rƒ | |  _ n  | |  d <d  S(   NuG   Using mimetype keyword argument is deprecated, use content_type insteadu   %s; charset=%su   Content-Type(   t   _headersR   t   DEFAULT_CHARSETt   _charsett   _closable_objectst   Nonet   _handler_classt   warningst   warnt   PendingDeprecationWarningt   DEFAULT_CONTENT_TYPER   t   cookiest   status_code(   t   selft   content_typet   statust   mimetype(    (    s-   ../Django//lib/python/django/http/response.pyt   __init__%   s    						c         C@ sH   g  |  j  j ƒ  D]% \ } } d | | f j d ƒ ^ q } d j | ƒ S(   u   HTTP headers as a bytestring.u   %s: %su   us-asciis   
(   R   t   valuest   encodet   join(   R   t   keyt   valuet   headers(    (    s-   ../Django//lib/python/django/http/response.pyt   serialize_headers<   s    8c         C@ s  t  | t t j f ƒ s' t | ƒ } n  yl t j rd t  | t ƒ rR | j | ƒ q’ | j | ƒ } n. t  | t ƒ rƒ | j | ƒ n | j | ƒ } WnM t k
 râ } | rÉ t t	 | d ƒ j ƒ  ƒ } qã | j
 d | 7_
 ‚  n Xt d ƒ | k st d ƒ | k rt d | ƒ ‚ n  | S(   uô   Converts headers key/value to ascii/latin1 native strings.

        `charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
        `value` value can't be represented in the given charset, MIME-encoding
        is applied.
        u   utf-8u,   , HTTP response headers must be in %s formatu   
u   u-   Header values can't contain newlines (got %r)(   t
   isinstancet   bytesR	   t	   text_typet   strt   PY3R%   t   decodet   UnicodeErrorR   t   reasonR   (   R   R(   t   charsett   mime_encodet   e(    (    s-   ../Django//lib/python/django/http/response.pyt   _convert_to_charsetI   s$    	$c         C@ sG   |  j  | d ƒ } |  j  | d d t ƒ} | | f |  j | j ƒ  <d  S(   Nu   asciiu   latin1R4   (   R6   t   TrueR   t   lower(   R   t   headerR(   (    (    s-   ../Django//lib/python/django/http/response.pyt   __setitem__l   s    c         C@ s,   y |  j  | j ƒ  =Wn t k
 r' n Xd  S(   N(   R   R8   t   KeyError(   R   R9   (    (    s-   ../Django//lib/python/django/http/response.pyt   __delitem__q   s    c         C@ s   |  j  | j ƒ  d S(   Ni   (   R   R8   (   R   R9   (    (    s-   ../Django//lib/python/django/http/response.pyt   __getitem__w   s    c         C@ s'   |  j  j ƒ  } t | d ƒ | d <| S(   Nu   cookies(   t   __dict__t   copyR.   (   R   t   state(    (    s-   ../Django//lib/python/django/http/response.pyt   __getstate__z   s    c         C@ s&   |  j  j | ƒ t |  j ƒ |  _ d  S(   N(   R>   t   updateR   R   (   R   R@   (    (    s-   ../Django//lib/python/django/http/response.pyt   __setstate__   s    c         C@ s   | j  ƒ  |  j k S(   u$   Case-insensitive check for a header.(   R8   R   (   R   R9   (    (    s-   ../Django//lib/python/django/http/response.pyt
   has_header…   s    c         C@ s   |  j  j ƒ  S(   N(   R   R$   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyt   items‹   s    c         C@ s#   |  j  j | j ƒ  d  | f ƒ d S(   Ni   (   R   t   getR8   R   (   R   R9   t	   alternate(    (    s-   ../Django//lib/python/django/http/response.pyRF   Ž   s    u    u   /c	   
      C@ st  | |  j  | <| d k	 r² t | t j ƒ rž t j | ƒ rR t j | t j ƒ } n  | | j ƒ  }	 |	 t j	 d d ƒ }	 d } t
 d |	 j d |	 j ƒ } q² | |  j  | d <n  | d k	 rü | |  j  | d <| sü t t j ƒ  | ƒ |  j  | d <qü n  | d k	 r| |  j  | d <n  | d k	 r<| |  j  | d <n  | rVt |  j  | d	 <n  | rpt |  j  | d
 <n  d S(   u6  
        Sets a cookie.

        ``expires`` can be:
        - a string in the correct format,
        - a naive ``datetime.datetime`` object in UTC,
        - an aware ``datetime.datetime`` object in any time zone.
        If it is a ``datetime.datetime`` object then ``max_age`` will be calculated.

        t   secondsi   i    i€Q u   expiresu   max-ageu   pathu   domainu   secureu   httponlyN(   R   R   R+   t   datetimeR
   t   is_awaret
   make_naivet   utct   utcnowt	   timedeltat   maxt   daysRH   R   t   timeR7   (
   R   R'   R(   t   max_aget   expirest   patht   domaint   securet   httponlyt   delta(    (    s-   ../Django//lib/python/django/http/response.pyt
   set_cookie‘   s.     c         K@ s2   t  j d | | ƒ j | ƒ } |  j | | |  S(   Nt   salt(   R   t   get_cookie_signert   signRY   (   R   R'   R(   RZ   t   kwargs(    (    s-   ../Django//lib/python/django/http/response.pyt   set_signed_cookie»   s    c      
   C@ s)   |  j  | d d d | d | d d ƒd  S(   NRR   i    RT   RU   RS   u   Thu, 01-Jan-1970 00:00:00 GMT(   RY   (   R   R'   RT   RU   (    (    s-   ../Django//lib/python/django/http/response.pyt   delete_cookie¿   s    c         C@ sj   |  j  d ƒ r t | ƒ St | t ƒ r2 t | ƒ St | t j ƒ rZ t | j |  j ƒ ƒ St | |  j ƒ S(   u=   Turn a value into a bytestring encoded in the output charset.u   Content-Encoding(   RD   R,   R+   R	   R-   R%   R   R   (   R   R(   (    (    s-   ../Django//lib/python/django/http/response.pyt
   make_bytesÅ   s    

c         C@ s   |  S(   N(    (   R   (    (    s-   ../Django//lib/python/django/http/response.pyt   __iter__Ú   s    c         C@ s   |  j  t |  j ƒ ƒ S(   N(   R`   t   nextt	   _iterator(   R   (    (    s-   ../Django//lib/python/django/http/response.pyt   __next__Ý   s    c         C@ sP   x3 |  j  D]( } y | j ƒ  Wq
 t k
 r1 q
 Xq
 Wt j j d |  j ƒ d  S(   Nt   sender(   R   t   closet	   ExceptionR   t   request_finishedt   sendR   (   R   t   closable(    (    s-   ../Django//lib/python/django/http/response.pyRf   æ   s    c         C@ s   t  d |  j j ƒ ‚ d  S(   Nu    This %s instance is not writable(   Rg   t	   __class__R   (   R   t   content(    (    s-   ../Django//lib/python/django/http/response.pyt   writeî   s    c         C@ s   d  S(   N(    (   R   (    (    s-   ../Django//lib/python/django/http/response.pyt   flushñ   s    c         C@ s   t  d |  j j ƒ ‚ d  S(   Nu)   This %s instance cannot tell its position(   Rg   Rk   R   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyt   tellô   s    N(    R   R   t   __doc__R   R   R#   R*   R	   R/   t	   __bytes__t   __str__t   FalseR6   R:   R<   R=   RA   RC   RD   t   __contains__RE   RF   RY   R^   R_   R`   Ra   Rd   Rf   Rm   Rn   Ro   (    (    (    s-   ../Django//lib/python/django/http/response.pyR      s8   			#							)							t   HttpResponsec           B@ s†   e  Z d  Z e Z d d „ Z d „  Z e j r9 e Z	 n e Z
 d „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z d	 „  Z RS(
   uw   
    An HTTP response class with a string as content.

    This content that can be read, appended to or replaced.
    u    c         O@ s&   t  t |  ƒ j | | Ž  | |  _ d  S(   N(   t   superRu   R#   Rl   (   R   Rl   t   argsR]   (    (    s-   ../Django//lib/python/django/http/response.pyR#     s    c         C@ s   |  j  ƒ  d |  j S(   u6   Full HTTP message, including headers, as a bytestring.s   

(   R*   Rl   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyt	   serialize  s    c         @ s5   ˆ  j  r1 d j ‡  f d †  ˆ  j Dƒ ƒ ˆ  _ n  d  S(   Nt    c         3@ s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R`   (   t   .0R5   (   R   (    s-   ../Django//lib/python/django/http/response.pys	   <genexpr>  s    (   t   _base_content_is_iterR&   t
   _containerRl   (   R   (    (   R   s-   ../Django//lib/python/django/http/response.pyt   _consume_content  s    	c         @ s*   ˆ  j  ƒ  d j ‡  f d †  ˆ  j Dƒ ƒ S(   NRy   c         3@ s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R`   (   Rz   R5   (   R   (    s-   ../Django//lib/python/django/http/response.pys	   <genexpr>  s    (   R}   R&   R|   (   R   (    (   R   s-   ../Django//lib/python/django/http/response.pyRl     s    
c         C@ sx   t  | d ƒ r_ t | t t j f ƒ r_ | |  _ t |  _ t  | d ƒ rt |  j j	 | ƒ qt n | g |  _ t
 |  _ d  S(   Nu   __iter__u   close(   t   hasattrR+   R,   R	   t   string_typesR|   R7   R{   R   t   appendRs   (   R   R(   (    (    s-   ../Django//lib/python/django/http/response.pyRl     s    (		c         C@ sJ   |  j  r" t j d t d d ƒn  t |  d ƒ sF t |  j ƒ |  _ n  |  S(   Nu‡   Creating streaming responses with `HttpResponse` is deprecated. Use `StreamingHttpResponse` instead if you need the streaming behavior.t
   stackleveli   u	   _iterator(   R{   R   R   R   R~   t   iterR|   Rc   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyRa   (  s    	c         C@ s   |  j  ƒ  |  j j | ƒ d  S(   N(   R}   R|   R€   (   R   Rl   (    (    s-   ../Django//lib/python/django/http/response.pyRm   8  s    
c         C@ s   |  j  ƒ  t |  j ƒ S(   N(   R}   t   lenRl   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyRo   <  s    
(   R   R   Rp   Rs   t	   streamingR#   Rx   R	   R/   Rq   Rr   R}   t   propertyRl   t   setterRa   Rm   Ro   (    (    (    s-   ../Django//lib/python/django/http/response.pyRu   ø   s   							t   StreamingHttpResponsec           B@ sP   e  Z d  Z e Z d d „ Z e d „  ƒ Z e d „  ƒ Z e j	 d „  ƒ Z RS(   u$  
    A streaming HTTP response class with an iterator as content.

    This should only be iterated once, when the response is streamed to the
    client. However, it can be appended to or replaced with a new iterator
    that wraps the original content (or yields entirely new content).
    c         O@ s&   t  t |  ƒ j | | Ž  | |  _ d  S(   N(   Rv   R‡   R#   t   streaming_content(   R   Rˆ   Rw   R]   (    (    s-   ../Django//lib/python/django/http/response.pyR#   L  s    c         C@ s   t  d |  j j ƒ ‚ d  S(   NuM   This %s instance has no `content` attribute. Use `streaming_content` instead.(   t   AttributeErrorRk   R   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyRl   R  s    c         C@ s   t  |  j |  j ƒ S(   N(   R   R`   Rc   (   R   (    (    s-   ../Django//lib/python/django/http/response.pyRˆ   W  s    c         C@ s5   t  | ƒ |  _ t | d ƒ r1 |  j j | ƒ n  d  S(   Nu   close(   R‚   Rc   R~   R   R€   (   R   R(   (    (    s-   ../Django//lib/python/django/http/response.pyRˆ   [  s    (    (
   R   R   Rp   R7   R„   R#   R…   Rl   Rˆ   R†   (    (    (    s-   ../Django//lib/python/django/http/response.pyR‡   A  s   t   CompatibleStreamingHttpResponsec           B@ s/   e  Z d  Z e d „  ƒ Z e j d „  ƒ Z RS(   u³  
    This class maintains compatibility with middleware that doesn't know how
    to handle the content of a streaming response by exposing a `content`
    attribute that will consume and cache the content iterator when accessed.

    These responses will stream only if no middleware attempts to access the
    `content` attribute. Otherwise, they will behave like a regular response,
    and raise a `PendingDeprecationWarning`.
    c         C@ s/   t  j d t ƒ d j |  ƒ } | g |  _ | S(   Nuw   Accessing the `content` attribute on a streaming response is deprecated. Use the `streaming_content` attribute instead.Ry   (   R   R   R   R&   Rˆ   (   R   Rl   (    (    s-   ../Django//lib/python/django/http/response.pyRl   m  s    c         C@ s    t  j d t ƒ | g |  _ d  S(   Nuw   Accessing the `content` attribute on a streaming response is deprecated. Use the `streaming_content` attribute instead.(   R   R   R   Rˆ   (   R   Rl   (    (    s-   ../Django//lib/python/django/http/response.pyRl   w  s    (   R   R   Rp   R…   Rl   R†   (    (    (    s-   ../Django//lib/python/django/http/response.pyRŠ   c  s   	
t   HttpResponseRedirectBasec           B@ s    e  Z d  d d g Z d „  Z RS(   u   httpu   httpsu   ftpc         O@ sj   t  | ƒ } | j r= | j |  j k r= t d | j ƒ ‚ n  t t |  ƒ j | | Ž  t | ƒ |  d <d  S(   Nu)   Unsafe redirect to URL with protocol '%s'u   Location(   R   t   schemet   allowed_schemesR   Rv   R‹   R#   R   (   R   t   redirect_toRw   R]   t   parsed(    (    s-   ../Django//lib/python/django/http/response.pyR#   ƒ  s
    (   R   R   R   R#   (    (    (    s-   ../Django//lib/python/django/http/response.pyR‹   €  s   t   HttpResponseRedirectc           B@ s   e  Z d  Z RS(   i.  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR   ‹  s   t   HttpResponsePermanentRedirectc           B@ s   e  Z d  Z RS(   i-  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR‘     s   t   HttpResponseNotModifiedc           B@ s,   e  Z d  Z d „  Z e j j d „  ƒ Z RS(   i0  c         O@ s$   t  t |  ƒ j | | Ž  |  d =d  S(   Nu   content-type(   Rv   R’   R#   (   R   Rw   R]   (    (    s-   ../Django//lib/python/django/http/response.pyR#   –  s    c         C@ s+   | r t  d ƒ ‚ n  g  |  _ t |  _ d  S(   Nu7   You cannot set content to a 304 (Not Modified) response(   R‰   R|   Rs   R{   (   R   R(   (    (    s-   ../Django//lib/python/django/http/response.pyRl   š  s    	(   R   R   R   R#   Ru   Rl   R†   (    (    (    s-   ../Django//lib/python/django/http/response.pyR’   “  s   	t   HttpResponseBadRequestc           B@ s   e  Z d  Z RS(   i  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR“   ¢  s   t   HttpResponseNotFoundc           B@ s   e  Z d  Z RS(   i”  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR”   ¦  s   t   HttpResponseForbiddenc           B@ s   e  Z d  Z RS(   i“  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR•   ª  s   t   HttpResponseNotAllowedc           B@ s   e  Z d  Z d „  Z RS(   i•  c         O@ s0   t  t |  ƒ j | | Ž  d j | ƒ |  d <d  S(   Nu   , u   Allow(   Rv   R–   R#   R&   (   R   t   permitted_methodsRw   R]   (    (    s-   ../Django//lib/python/django/http/response.pyR#   ±  s    (   R   R   R   R#   (    (    (    s-   ../Django//lib/python/django/http/response.pyR–   ®  s   t   HttpResponseGonec           B@ s   e  Z d  Z RS(   iš  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR˜   ¶  s   t   HttpResponseServerErrorc           B@ s   e  Z d  Z RS(   iô  (   R   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyR™   º  s   t   Http404c           B@ s   e  Z RS(    (   R   R   (    (    (    s-   ../Django//lib/python/django/http/response.pyRš   ¾  s   (1   t
   __future__R    R   RI   RQ   R   t   email.headerR   t   urllib.parseR   t   ImportErrort   django.confR   t   django.coreR   R   t   django.core.exceptionsR   t   django.http.cookieR   t   django.utilsR	   R
   t   django.utils.encodingR   R   t   django.utils.httpR   t   django.utils.six.movesR   t
   ValueErrorR   t   IteratorR   Ru   R‡   RŠ   R‹   R   R‘   R’   R“   R”   R•   R–   R˜   R™   Rg   Rš   (    (    (    s-   ../Django//lib/python/django/http/response.pyt   <module>   sB   ÝI"