ó
ù¢TQc           @@ s  d  d l  m Z m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d  d l
 m Z y& d  d l m Z m Z m Z m Z Wn= e k
 r× d  d l m Z m Z d  d l m Z m Z n Xd  d l m Z d  d	 l m Z d  d
 l m Z 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& m' Z' m( Z( e) ƒ  Z* e j+ d e j, ƒ Z- e j+ d ƒ Z. d e/ f d „  ƒ  YZ0 d e) f d „  ƒ  YZ1 d e" f d „  ƒ  YZ2 d d d d d d „ Z4 d „  Z5 d „  Z6 d S(   i    (   t   absolute_importt   unicode_literalsN(   t   BytesIO(   t   pformat(   t	   parse_qslt	   urlencodet   quotet   urljoin(   R   R   (   R   R   (   t   settings(   t   signing(   t   SuspiciousOperationt   ImproperlyConfigured(   t   uploadhandler(   t   MultiPartParser(   t   six(   t   MultiValueDictt   ImmutableList(   t   force_bytest
   force_textt	   force_strt
   iri_to_uriu
   ^https?://u/   ^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9:]+\])(:\d+)?$t   UnreadablePostErrorc           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   ../Django//lib/python/django/http/request.pyR      s   t   HttpRequestc           B@ s%  e  Z d  Z d Z g  Z d „  Z d „  Z d „  Z d „  Z	 e
 d d d „ Z d d „ Z d „  Z d	 „  Z d
 „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z e d „  ƒ Z e j d „  ƒ Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z e Z d „  Z RS(   u   A basic HTTP request.c         C@ s[   i  i  i  i  i  f \ |  _  |  _ |  _ |  _ |  _ d |  _ d |  _ d  |  _ t	 |  _
 d  S(   Nu    (   t   GETt   POSTt   COOKIESt   METAt   FILESt   patht	   path_infot   Nonet   methodt   Falset   _post_parse_error(   t   self(    (    s,   ../Django//lib/python/django/http/request.pyt   __init__*   s
    3			c         C@ s
   t  |  ƒ S(   N(   t   build_request_repr(   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   __repr__1   s    c         C@ sÚ   t  j r( d |  j k r( |  j d } np d |  j k rG |  j d } nQ |  j d } t |  j d ƒ } | |  j ƒ  r| d n d k r˜ d | | f } n  t  j rª d g n t  j } t | | ƒ rÆ | St d	 | ƒ ‚ d
 S(   u?   Returns the HTTP host using the environment or request headers.u   HTTP_X_FORWARDED_HOSTu	   HTTP_HOSTu   SERVER_NAMEu   SERVER_PORTu   443u   80u   %s:%su   *u@   Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %sN(	   R   t   USE_X_FORWARDED_HOSTR   t   strt	   is_securet   DEBUGt   ALLOWED_HOSTSt   validate_hostR
   (   R$   t   hostt   server_portt   allowed_hosts(    (    s,   ../Django//lib/python/django/http/request.pyt   get_host4   s    	c         C@ sE   d |  j  |  j j d d ƒ r= d t |  j j d d ƒ ƒ n d f S(   Nu   %s%su   QUERY_STRINGu    u   ?(   R   R   t   getR   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   get_full_pathJ   s    u    c         C@ s   y |  j  | } Wn$ t k
 r7 | t k	 r1 | S‚  n Xy) t j d | | ƒ j | d | ƒ} Wn' t j k
 rŠ | t k	 r„ | S‚  n X| S(   ué   
        Attempts to return a signed cookie. If the signature fails or the
        cookie has expired, raises an exception... unless you provide the
        default argument in which case that value will be returned instead.
        t   saltt   max_age(   R   t   KeyErrort   RAISE_ERRORR	   t   get_cookie_signert   unsignt   BadSignature(   R$   t   keyt   defaultR4   R5   t   cookie_valuet   value(    (    s,   ../Django//lib/python/django/http/request.pyt   get_signed_cookieO   s    c         C@ sn   | s |  j  ƒ  } n  t j | ƒ sd d |  j ƒ  r9 d n d |  j ƒ  |  j f } t | | ƒ } n  t | ƒ S(   uÎ   
        Builds an absolute URI from the location and the variables available in
        this request. If no location is specified, the absolute URI is built on
        ``request.get_full_path()``.
        u	   %s://%s%su   httpsu   http(   R3   t   absolute_http_url_ret   matchR*   R1   R   R   R   (   R$   t   locationt   current_uri(    (    s,   ../Django//lib/python/django/http/request.pyt   build_absolute_urif   s    c         C@ s   t  j j d ƒ d k S(   Nu   HTTPSu   on(   t   ost   environR2   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt
   _is_securet   s    c         C@ sh   t  j r^ y t  j \ } } Wn t k
 r; t d ƒ ‚ n X|  j j | d  ƒ | k r^ t Sn  |  j ƒ  S(   NuJ   The SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.(	   R   t   SECURE_PROXY_SSL_HEADERt
   ValueErrorR   R   R2   R    t   TrueRG   (   R$   t   headerR>   (    (    s,   ../Django//lib/python/django/http/request.pyR*   w   s    	c         C@ s   |  j  j d ƒ d k S(   Nu   HTTP_X_REQUESTED_WITHu   XMLHttpRequest(   R   R2   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   is_ajax…   s    c         C@ s   |  j  S(   N(   t	   _encoding(   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   encodingˆ   s    c         C@ s=   | |  _  t |  d ƒ r! |  ` n  t |  d ƒ r9 |  ` n  d S(   uÙ   
        Sets the encoding used for GET/POST accesses. If the GET or POST
        dictionary has already been created, it is removed and recreated on the
        next access (so that it is decoded correctly).
        u   _getu   _postN(   RM   t   hasattrt   _gett   _post(   R$   t   val(    (    s,   ../Django//lib/python/django/http/request.pyRN   Œ   s
    		c         C@ s/   g  t  j D] } t j | |  ƒ ^ q
 |  _ d  S(   N(   R   t   FILE_UPLOAD_HANDLERSR   t   load_handlert   _upload_handlers(   R$   t   handler(    (    s,   ../Django//lib/python/django/http/request.pyt   _initialize_handlers™   s    c         C@ s   |  j  s |  j ƒ  n  |  j  S(   N(   RU   RW   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   upload_handlers   s    	c         C@ s+   t  |  d ƒ r t d ƒ ‚ n  | |  _ d  S(   Nu   _filesuG   You cannot set the upload handlers after the upload has been processed.(   RO   t   AttributeErrorRU   (   R$   RX   (    (    s,   ../Django//lib/python/django/http/request.pyRX   ¤   s    c         C@ s=   t  |  j d d ƒ|  _ t | | |  j |  j ƒ } | j ƒ  S(   u:   Returns a tuple of (POST QueryDict, FILES MultiValueDict).t   warninguE   You cannot alter upload handlers after the upload has been processed.(   R   RX   R   RN   t   parse(   R$   R   t	   post_datat   parser(    (    s,   ../Django//lib/python/django/http/request.pyt   parse_file_uploadª   s
    	c         C@ s’   t  |  d ƒ s‹ |  j r' t d ƒ ‚ n  y |  j ƒ  |  _ Wn9 t k
 ru } t j t t | j	 Œ  t
 j ƒ  d ƒ n Xt |  j ƒ |  _ n  |  j S(   Nu   _bodyu?   You cannot access body after reading from request's data streami   (   RO   t   _read_startedt	   Exceptiont   readt   _bodyt   IOErrorR   t   reraiseR   t   argst   syst   exc_infoR   t   _stream(   R$   t   e(    (    s,   ../Django//lib/python/django/http/request.pyt   body³   s    	*c         C@ s   t  j d t ƒ |  j S(   NuL   HttpRequest.raw_post_data has been deprecated. Use HttpRequest.body instead.(   t   warningst   warnt   DeprecationWarningRj   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   raw_post_data¿   s    c         C@ s(   t  d ƒ |  _ t ƒ  |  _ t |  _ d  S(   Nu    (   t	   QueryDictRQ   R   t   _filesRJ   R#   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   _mark_post_parse_errorÄ   s    c         C@ sU  |  j  d k r8 t d d |  j ƒt ƒ  |  _ |  _ d S|  j r_ t |  d ƒ r_ |  j ƒ  d S|  j	 j
 d d ƒ j d ƒ rã t |  d ƒ rž t |  j ƒ } n |  } y% |  j |  j	 | ƒ \ |  _ |  _ WqQ|  j ƒ  ‚  qQXnn |  j	 j
 d d ƒ j d ƒ r,t |  j d |  j ƒt ƒ  |  _ |  _ n% t d d |  j ƒt ƒ  |  _ |  _ d S(	   uF   Populate self._post and self._files if the content-type is a form typeu   POSTu    RN   Nu   _bodyu   CONTENT_TYPEu   multipart/form-datau!   application/x-www-form-urlencoded(   R!   Ro   RM   R   RQ   Rp   R_   RO   Rq   R   R2   t
   startswithR   Rb   R^   Rj   (   R$   t   data(    (    s,   ../Django//lib/python/django/http/request.pyt   _load_post_and_filesÉ   s$    %
%

+c         O@ s   t  |  _ |  j j | | Ž  S(   N(   RJ   R_   Rh   Ra   (   R$   Re   t   kwargs(    (    s,   ../Django//lib/python/django/http/request.pyRa   ñ   s    	c         O@ s   t  |  _ |  j j | | Ž  S(   N(   RJ   R_   Rh   t   readline(   R$   Re   Ru   (    (    s,   ../Django//lib/python/django/http/request.pyRv   õ   s    	c         c@ s,   x% t  r' |  j ƒ  } | s Pn  | Vq Wd  S(   N(   RJ   Rv   (   R$   t   buf(    (    s,   ../Django//lib/python/django/http/request.pyt
   xreadlinesù   s
    	c         C@ s   t  t |  ƒ ƒ S(   N(   t   listt   iter(   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt	   readlines  s    N(   R   R   t   __doc__R    RM   RU   R%   R'   R1   R3   R7   R?   RD   RG   R*   RL   t   propertyRN   t   setterRW   RX   R^   Rj   Rn   Rq   Rt   Ra   Rv   Rx   t   __iter__R{   (    (    (    s,   ../Django//lib/python/django/http/request.pyR   #   s6   												(			Ro   c           B@ sÑ   e  Z d  Z e Z d Z e d d „ Z e	 d „  ƒ Z
 e
 j d „  ƒ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d d
 „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d d „ Z RS(   u  
    A specialized MultiValueDict that takes a query string when initialized.
    This is immutable unless you create a copy of it.

    Values retrieved from this class are converted from the given encoding
    (DEFAULT_CHARSET by default) to unicode.
    c      	   C@ sû   t  t |  ƒ j ƒ  | s% t j } n  | |  _ t j r— t | t	 ƒ rU | j
 ƒ  } n  x– t | pd d d t d | ƒD] \ } } |  j | | ƒ qt WnW xT t | p¦ d d t ƒD]: \ } } |  j t | | d d ƒt | | d d ƒƒ q° W| |  _ d  S(   Nu    t   keep_blank_valuesRN   t   errorsu   replace(   t   superRo   R%   R   t   DEFAULT_CHARSETRN   R   t   PY3t
   isinstancet   bytest   decodeR   RJ   t
   appendlistR   t   _mutable(   R$   t   query_stringt   mutableRN   R;   R>   (    (    s,   ../Django//lib/python/django/http/request.pyR%     s     		c         C@ s%   |  j  d  k r t j |  _  n  |  j  S(   N(   RM   R    R   Rƒ   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyRN   '  s    c         C@ s   | |  _  d  S(   N(   RM   (   R$   R>   (    (    s,   ../Django//lib/python/django/http/request.pyRN   -  s    c         C@ s   |  j  s t d ƒ ‚ n  d  S(   Nu$   This QueryDict instance is immutable(   R‰   RY   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyt   _assert_mutable1  s    	c         C@ sK   |  j  ƒ  t | |  j ƒ } t | |  j ƒ } t t |  ƒ j | | ƒ d  S(   N(   RŒ   t   bytes_to_textRN   R‚   Ro   t   __setitem__(   R$   R;   R>   (    (    s,   ../Django//lib/python/django/http/request.pyRŽ   5  s    
c         C@ s$   |  j  ƒ  t t |  ƒ j | ƒ d  S(   N(   RŒ   R‚   Ro   t   __delitem__(   R$   R;   (    (    s,   ../Django//lib/python/django/http/request.pyR   ;  s    
c         C@ sR   |  j  d d t d |  j ƒ} x- t j |  ƒ D] \ } } | j | | ƒ q. W| S(   Nu    R‹   RN   (   t	   __class__RJ   RN   R   t	   iterlistst   setlist(   R$   t   resultR;   R>   (    (    s,   ../Django//lib/python/django/http/request.pyt   __copy__?  s    c         C@ sz   |  j  d d t d |  j ƒ} | | t |  ƒ <xE t j |  ƒ D]4 \ } } | j t j | | ƒ t j | | ƒ ƒ q> W| S(   Nu    R‹   RN   (	   R   RJ   RN   t   idR   R‘   R’   t   copyt   deepcopy(   R$   t   memoR“   R;   R>   (    (    s,   ../Django//lib/python/django/http/request.pyt   __deepcopy__E  s
    ,c         C@ s^   |  j  ƒ  t | |  j ƒ } g  | D] } t | |  j ƒ ^ q# } t t |  ƒ j | | ƒ d  S(   N(   RŒ   R   RN   R‚   Ro   R’   (   R$   R;   t   list_t   elt(    (    s,   ../Django//lib/python/django/http/request.pyR’   L  s    
%c         C@ s#   |  j  ƒ  t t |  ƒ j | | ƒ S(   N(   RŒ   R‚   Ro   t   setlistdefault(   R$   R;   t   default_list(    (    s,   ../Django//lib/python/django/http/request.pyRœ   R  s    
c         C@ sK   |  j  ƒ  t | |  j ƒ } t | |  j ƒ } t t |  ƒ j | | ƒ d  S(   N(   RŒ   R   RN   R‚   Ro   Rˆ   (   R$   R;   R>   (    (    s,   ../Django//lib/python/django/http/request.pyRˆ   V  s    
c         G@ s#   |  j  ƒ  t t |  ƒ j | | Œ S(   N(   RŒ   R‚   Ro   t   pop(   R$   R;   Re   (    (    s,   ../Django//lib/python/django/http/request.pyRž   \  s    
c         C@ s   |  j  ƒ  t t |  ƒ j ƒ  S(   N(   RŒ   R‚   Ro   t   popitem(   R$   (    (    s,   ../Django//lib/python/django/http/request.pyRŸ   `  s    
c         C@ s!   |  j  ƒ  t t |  ƒ j ƒ  d  S(   N(   RŒ   R‚   Ro   t   clear(   R$   (    (    s,   ../Django//lib/python/django/http/request.pyR    d  s    
c         C@ sG   |  j  ƒ  t | |  j ƒ } t | |  j ƒ } t t |  ƒ j | | ƒ S(   N(   RŒ   R   RN   R‚   Ro   t
   setdefault(   R$   R;   R<   (    (    s,   ../Django//lib/python/django/http/request.pyR¡   h  s    
c         C@ s   |  j  i  ƒ S(   u&   Returns a mutable copy of this object.(   R™   (   R$   (    (    s,   ../Django//lib/python/django/http/request.pyR–   n  s    c      	   @ sª   g  } ˆ  r0 t  ˆ  |  j ƒ ‰  ‡  f d †  } n	 d „  } xa |  j ƒ  D]S \ } } t  | |  j ƒ } | j g  | D]! } | | t  | |  j ƒ ƒ ^ qq ƒ qF Wd j | ƒ S(   u  
        Returns an encoded string of all query string arguments.

        :arg safe: Used to specify characters which do not require quoting, for
            example::

                >>> q = QueryDict('', mutable=True)
                >>> q['next'] = '/a&b/'
                >>> q.urlencode()
                'next=%2Fa%26b%2F'
                >>> q.urlencode(safe='/')
                'next=/a%26b/'

        c         @ s    d t  |  ˆ  ƒ t  | ˆ  ƒ f S(   Nu   %s=%s(   R   (   t   kt   v(   t   safe(    s,   ../Django//lib/python/django/http/request.pyt   <lambda>„  s    c         S@ s   t  i | |  6ƒ S(   N(   R   (   R¢   R£   (    (    s,   ../Django//lib/python/django/http/request.pyR¥   †  s    u   &(   R   RN   t   listst   extendt   join(   R$   R¤   t   outputt   encodeR¢   Rš   R£   (    (   R¤   s,   ../Django//lib/python/django/http/request.pyR   r  s    		0N(   R   R   R|   RJ   R‰   R    RM   R"   R%   R}   RN   R~   RŒ   RŽ   R   R”   R™   R’   Rœ   Rˆ   Rž   RŸ   R    R¡   R–   R   (    (    (    s,   ../Django//lib/python/django/http/request.pyRo     s(   											c      	   C@ s‹  y+ | d k	 r t | ƒ n t |  j ƒ } Wn t k
 rD d } n X|  j rW d } nE y+ | d k	 rr t | ƒ n t |  j ƒ } Wn t k
 r› d } n Xy+ | d k	 r· t | ƒ n t |  j ƒ } Wn t k
 rà d } n Xy+ | d k	 rü t | ƒ n t |  j ƒ }	 Wn t k
 r%d }	 n X| d k	 r8| n |  j }
 t	 d |  j
 j |
 t j | ƒ t j | ƒ t j | ƒ t j |	 ƒ f ƒ S(   u‰   
    Builds and returns the request's representation string. The request's
    attributes may be overridden by pre-processed values.
    u   <could not parse>u2   <%s
path:%s,
GET:%s,
POST:%s,
COOKIES:%s,
META:%s>N(   R    R   R   R`   R#   R   R   R   R   R   R   R   R   t	   text_type(   t   requestt   path_overridet   GET_overridet   POST_overridet   COOKIES_overridet   META_overrideR2   t   postt   cookiest   metaR   (    (    s,   ../Django//lib/python/django/http/request.pyR&   Ž  s<    	
		


	c         C@ s*   t  |  t ƒ r" t j |  | d ƒ S|  Sd S(   uã   
    Converts basestring objects to unicode, using the given encoding. Illegally
    encoded input characters are replaced with Unicode "unknown" codepoint
    (ï¿½).

    Returns any non-basestring objects without change.
    u   replaceN(   R…   R†   R   R«   (   t   sRN   (    (    s,   ../Django//lib/python/django/http/request.pyR   ¿  s    c         C@ s¿   |  j  ƒ  }  t j |  ƒ s t S|  d d k r8 |  } n |  j d d ƒ d } xj | D]b } | j  ƒ  } | d k pª | j d ƒ r¡ | j | ƒ pª | | d k pª | | k } | rU t SqU Wt S(   uÇ  
    Validate the given host header value for this site.

    Check that the host looks valid and matches a host or host pattern in the
    given list of ``allowed_hosts``. Any pattern beginning with a period
    matches a domain and all its subdomains (e.g. ``.example.com`` matches
    ``example.com`` and any subdomain), ``*`` matches anything, and anything
    else must match exactly.

    Return ``True`` for a valid host, ``False`` otherwise.

    iÿÿÿÿu   ]u   :i   i    u   *u   .(   t   lowert   host_validation_reRA   R"   t   rsplitRr   t   endswithRJ   (   R.   R0   t   domaint   patternRA   (    (    s,   ../Django//lib/python/django/http/request.pyR-   Í  s    	(7   t
   __future__R    R   R–   RE   t   reRf   Rk   t   ioR   t   pprintR   t   urllib.parseR   R   R   R   t   ImportErrort   urllibt   urlparset   django.confR   t   django.coreR	   t   django.core.exceptionsR
   R   t   django.core.filesR   t   django.http.multipartparserR   t   django.utilsR   t   django.utils.datastructuresR   R   t   django.utils.encodingR   R   R   R   t   objectR7   t   compilet   IR@   R·   Rc   R   R   Ro   R    R&   R   R-   (    (    (    s,   ../Django//lib/python/django/http/request.pyt   <module>   s>   &"	ãˆ/	