ó
Ñ7ec           @  sj  d  d l  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 Z d  d l 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 m Z m Z d  d
 l m Z d  d l m Z m Z m Z m  Z  m! Z" e j# rXd  d l$ m% Z% m& Z& m' Z' m( Z( m) Z) m* Z* d Z, n4 d  d l- m% Z% m& Z& m, Z, m' Z' m( Z( m) Z) m* Z* e j. d e j/ ƒ Z0 d j1 ƒ  Z2 d Z3 d Z4 d Z5 d Z6 d Z7 d Z8 e j. d e3 e5 e6 e8 f ƒ Z9 e j. d e3 e5 e7 e8 f ƒ Z: e j. d e5 e4 e8 e6 f ƒ Z; e< d ƒ Z= e< d ƒ Z> e j. d ƒ Z? e d d „ ƒ Z@ e d d „ ƒ ZA e d  „  ƒ ZB e d! „  ƒ ZC d" d# „ Z! d d$ „ ZD d d% „ ZE d& „  ZF d' „  ZG d( „  ZH d) „  ZI d* „  ZJ d+ „  ZK d, „  ZL d- „  ZM d. „  ZN d d eO d/ „ ZP d eQ d0 „ ZR d eQ d1 „ ZS eO d2 „ ZT eO d3 d4 d d5 „ ZU d6 „  ZV d S(7   iÿÿÿÿ(   t   unicode_literalsN(   t   Error(   t
   formatdate(   t   TooManyFieldsSent(   t   six(   t   MultiValueDict(   t   RemovedInDjango21Warning(   t   force_bytest	   force_strt
   force_text(   t   keep_lazy_text(   t   quotet
   quote_plust   unquotet   unquote_plust	   urlencode(   t   ParseResultt   SplitResultt   _splitnetloct   _splitparamst   scheme_charst   uses_params(   R   R   t   _coerce_argsR   R   R   R   uò   
    \A(      # start of string and capture group
    (?:W/)?  # optional weak indicator
    "        # opening quote
    [^"]*    # any sequence of non-quote characters
    "        # end quote
    )\Z      # end of string and capture group
u/   jan feb mar apr may jun jul aug sep oct nov decu   (?P<day>\d{2})u   (?P<day>[ \d]\d)u   (?P<mon>\w{3})u   (?P<year>\d{4})u   (?P<year>\d{2})u-   (?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2})u   ^\w{3}, %s %s %s %s GMT$u   ^\w{6,9}, %s-%s-%s %s GMT$u   ^\w{3} %s %s %s %s$u   :/?#[]@u   !$&'()*+,;=u   [&;]u   /c         C  s   t  t t |  ƒ t | ƒ ƒ ƒ S(   u  
    A version of Python's urllib.quote() function that can operate on unicode
    strings. The url is first UTF-8 encoded before quoting. The returned string
    can safely be used as part of an argument to a subsequent iri_to_uri() call
    without double-quoting occurring.
    (   R	   R   R   (   t   urlt   safe(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   urlquote>   s    u    c         C  s   t  t t |  ƒ t | ƒ ƒ ƒ S(   u  
    A version of Python's urllib.quote_plus() function that can operate on
    unicode strings. The url is first UTF-8 encoded before quoting. The
    returned string can safely be used as part of an argument to a subsequent
    iri_to_uri() call without double-quoting occurring.
    (   R	   R   R   (   R   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   urlquote_plusI   s    c         C  s   t  t t |  ƒ ƒ ƒ S(   u~   
    A wrapper for Python's urllib.unquote() function that can operate on
    the result of django.utils.http.urlquote().
    (   R	   R   R   (   t
   quoted_url(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt
   urlunquoteT   s    c         C  s   t  t t |  ƒ ƒ ƒ S(   uˆ   
    A wrapper for Python's urllib.unquote_plus() function that can operate on
    the result of django.utils.http.urlquote_plus().
    (   R	   R   R   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   urlunquote_plus]   s    i    c         C  s¨   t  |  t ƒ r |  j ƒ  }  n t |  d ƒ r< |  j ƒ  }  n  t g  |  D]X \ } } t | ƒ t  | t t f ƒ r g  | D] } t | ƒ ^ qw n	 t | ƒ f ^ qF | ƒ S(   u¿   
    A version of Python's urllib.urlencode() function that can operate on
    unicode strings. The parameters are first cast to UTF-8 encoded strings and
    then encoded as per normal.
    u   items(	   t
   isinstanceR   t   listst   hasattrt   itemst   original_urlencodeR   t   listt   tuple(   t   queryt   doseqt   kt   vt   i(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyR   f   s    _c         C  s/   t  |  ƒ } d | d  | d d !| d d !f S(   uI  
    Formats the time to ensure compatibility with Netscape's cookie standard.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
    u   %s-%s-%s GMTi   i   i   i   i   (   R   (   t   epoch_secondst   rfcdate(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   cookie_datew   s    
c         C  s   t  |  d t ƒS(   uc  
    Formats the time to match the RFC1123 date format as specified by HTTP
    RFC7231 section 7.1.1.1.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
    t   usegmt(   R   t   True(   R*   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt	   http_date…   s    c   
      C  sz  xF t  t t f D]% } | j |  ƒ } | d k	 r Pq q Wt d |  ƒ ‚ yò t | j d ƒ ƒ } | d k  r“ | d k  r† | d 7} q“ | d 7} n  t j	 | j d ƒ j
 ƒ  ƒ d } t | j d	 ƒ ƒ } t | j d
 ƒ ƒ } t | j d ƒ ƒ } t | j d ƒ ƒ } t j | | | | | | ƒ }	 t j |	 j ƒ  ƒ SWn8 t k
 rut j t t d |  ƒ t j ƒ  d ƒ n Xd S(   u  
    Parses a date format as specified by HTTP RFC7231 section 7.1.1.1.

    The three formats allowed by the RFC are accepted, even if only the first
    one is still in widespread use.

    Returns an integer expressed in seconds since the epoch, in UTC.
    u%   %r is not in a valid HTTP date formatu   yearid   iF   iÐ  il  u   moni   u   dayu   houru   minu   secu   %r is not a valid datei   N(   t   RFC1123_DATEt   RFC850_DATEt   ASCTIME_DATEt   matcht   Nonet
   ValueErrort   intt   groupt   MONTHSt   indext   lowert   datetimet   calendart   timegmt   utctimetuplet	   ExceptionR   t   reraiset   syst   exc_info(
   t   datet   regext   mt   yeart   montht   dayt   hourt   mint   sect   result(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   parse_http_date“   s(    "c         C  s&   y t  |  ƒ SWn t k
 r! n Xd S(   uL   
    Same as parse_http_date, but returns None if the input is invalid.
    N(   RM   R?   (   RC   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   parse_http_date_safe·   s    c         C  s[   t  |  ƒ d k r! t d ƒ ‚ n  t |  d ƒ } t j rW | t j k rW t d ƒ ‚ n  | S(   uo   
    Converts a base 36 string to an ``int``. Raises ``ValueError` if the
    input won't fit into an int.
    i   u   Base36 input too largei$   (   t   lenR5   R6   R   t   PY2RA   t   maxint(   t   st   value(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   base36_to_intÃ   s    c         C  sÀ   d } |  d k  r! t  d ƒ ‚ n  t j rl t |  t j ƒ sK t d ƒ ‚ n  |  t j k rl t  d ƒ ‚ ql n  |  d k  r€ | |  Sd } x3 |  d k r» t |  d ƒ \ }  } | | | } q‰ W| S(   u0   
    Converts an integer to a base36 string
    u$   0123456789abcdefghijklmnopqrstuvwxyzi    u!   Negative base36 conversion input.u$   Non-integer base36 conversion input.u"   Base36 conversion input too large.i$   u    (	   R5   R   RP   R   t   integer_typest	   TypeErrorRA   RQ   t   divmod(   R)   t   char_sett   b36t   n(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   int_to_base36Õ   s    	c         C  s   t  j |  ƒ j d ƒ S(   ua   
    Encodes a bytestring in base64 for use in URLs, stripping any trailing
    equal signs.
    s   
=(   t   base64t   urlsafe_b64encodet   rstrip(   RR   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   urlsafe_base64_encodeê   s    c         C  si   t  |  ƒ }  y1 t j |  j t |  ƒ t |  ƒ d d ƒ ƒ SWn% t t f k
 rd } t | ƒ ‚ n Xd S(   ur   
    Decodes a base64 encoded string, adding back any trailing equal signs that
    might have been stripped.
    i   t   =N(   R   R\   t   urlsafe_b64decodet   ljustRO   t   LookupErrort   BinasciiErrorR5   (   RR   t   e(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   urlsafe_base64_decodeò   s
    1c         C  s\   |  j  ƒ  d k r d g Sd „  |  j d ƒ Dƒ } g  | D] } | r9 | j d ƒ ^ q9 Sd S(   u¶   
    Parse a string of ETags given in an If-None-Match or If-Match header as
    defined by RFC 7232. Return a list of quoted ETags, or ['*'] if all ETags
    should be matched.
    u   *c         s  s$   |  ] } t  j | j ƒ  ƒ Vq d  S(   N(   t
   ETAG_MATCHR3   t   strip(   t   .0t   etag(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pys	   <genexpr>  s    u   ,i   N(   Rh   t   splitR7   (   t   etag_strt   etag_matchesR3   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   parse_etagsþ   s    c         C  s   t  j |  ƒ r |  Sd |  Sd S(   uˆ   
    If the provided string is already a quoted ETag, return it. Otherwise, wrap
    the string in quotes, making it a strong ETag.
    u   "%s"N(   Rg   R3   (   Rl   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt
   quote_etag  s    c         C  sO   | s
 t  S| j ƒ  } | d d k rE |  j | ƒ pN |  | d k pN | |  k S(   u4  
    Return ``True`` if the host is either an exact match or a match
    to the wildcard pattern.

    Any pattern beginning with a period matches a domain and all of its
    subdomains. (e.g. ``.example.com`` matches ``example.com`` and
    ``foo.example.com``). Anything else is an exact string match.
    i    u   .i   (   t   FalseR:   t   endswith(   t   hostt   pattern(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   is_same_domain  s
    	/c         C  sÎ   |  d k	 r |  j ƒ  }  n  |  s% t St j rV y t |  ƒ }  WqV t k
 rR t SXn  | d k rn t ƒ  } n  | rš t j	 d t
 d d ƒ| | h B} n  t |  | d | ƒoÍ t |  j d d ƒ | d | ƒS(   uJ  
    Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
    a different host and uses a safe scheme).

    Always returns ``False`` on an empty url.

    If ``require_https`` is ``True``, only 'https' will be considered a valid
    scheme, as opposed to 'http' and 'https' with the default, ``False``.
    u;   The host argument is deprecated, use allowed_hosts instead.t
   stackleveli   t   require_httpsu   \u   /N(   R4   Rh   Rp   R   RP   R	   t   UnicodeDecodeErrort   sett   warningst   warnR   t   _is_safe_urlt   replace(   R   Rr   t   allowed_hostsRv   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   is_safe_url*  s&    
	c   
      C  sª   t  r! t  |  | ƒ \ }  } } n  t |  | | ƒ } | \ } } }  } } | t k ru d |  k ru t |  ƒ \ }  } n d } t | | |  | | | ƒ }	 t  r¦ | |	 ƒ S|	 S(   u#  Parse a URL into 6 components:
    <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
    Return a 6-tuple: (scheme, netloc, path, params, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.u   ;u    (   R   t	   _urlsplitR   R   R   (
   R   t   schemet   allow_fragmentst   _coerce_resultt   splitresultt   netlocR%   t   fragmentt   paramsRL   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt	   _urlparseN  s    c   
      C  s„  t  r! t  |  | ƒ \ }  } } n  t | ƒ } d } } } |  j d ƒ } | d k r xD |  |  D] } | t k ra Pqa qa W|  |  j ƒ  |  | d } }  n  |  d  d k rt |  d ƒ \ } }  d | k rÚ d | k sò d | k rd | k rt d	 ƒ ‚ qn  | r1d
 |  k r1|  j d
 d ƒ \ }  } n  d |  k rX|  j d d ƒ \ }  } n  t | | |  | | ƒ }	 t  r€| |	 ƒ S|	 S(   u  Parse a URL into 5 components:
    <scheme>://<netloc>/<path>?<query>#<fragment>
    Return a 5-tuple: (scheme, netloc, path, query, fragment).
    Note that we don't break the components up in smaller bits
    (e.g. netloc is a single string) and we don't expand % escapes.u    u   :i    i   i   u   //u   [u   ]u   Invalid IPv6 URLu   #u   ?(	   R   t   boolt   findR   R:   R   R5   Rk   R   (
   R   R€   R   R‚   R„   R%   R…   R)   t   cR(   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyR   b  s*    "c         C  sÚ   |  j  d ƒ r t Sy t |  ƒ } Wn t k
 r7 t SX| j rO | j rO t St j |  d ƒ d d k rp t S| j } | j r• | j r• d } n  | r¤ d g n	 d d g } | j sÉ | j | k oÙ | pÙ | | k S(   Nu   ///i    u   Cu   httpu   https(   t
   startswithRp   R‡   R5   R„   R€   t   unicodedatat   category(   R   R}   Rv   t   url_infoR€   t   valid_schemes(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyR{     s     		u   utf-8u   replacec         C  s„  | r< t  j |  | ƒ } t | ƒ | k rK t d ƒ ‚ qK n t  j |  ƒ } g  } x,| D]$} | sj qX n  | j t d ƒ d ƒ } t | ƒ d k r° | rX | j d ƒ q° qX n  t | d ƒ sÆ | rX t j r.| d j d d ƒ }	 t	 |	 d	 | d
 | ƒ}	 | d j d d ƒ }
 t	 |
 d	 | d
 | ƒ}
 n8 t	 | d j d d ƒ ƒ }	 t	 | d j d d ƒ ƒ }
 | j |	 |
 f ƒ qX qX W| S(   u~  
    Return a list of key/value tuples parsed from query string.

    Copied from urlparse with an additional "fields_limit" argument.
    Copyright (C) 2013 Python Software Foundation (see LICENSE.python).

    Arguments:

    qs: percent-encoded query string to be parsed

    keep_blank_values: flag indicating whether blank values in
        percent-encoded queries should be treated as blank strings. A
        true value indicates that blanks should be retained as blank
        strings. The default false value indicates that blank values
        are to be ignored and treated as if they were  not included.

    encoding and errors: specify how to decode percent-encoded sequences
        into Unicode characters, as accepted by the bytes.decode() method.

    fields_limit: maximum number of fields parsed or an exception
        is raised. None means no limit and is the default.
    uR   The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_NUMBER_FIELDS.u   =i   i   u    i    u   +u    t   encodingt   errorst   +t    (
   t   FIELDS_MATCHRk   RO   R   t   strt   appendR   t   PY3R|   R   (   t   qst   keep_blank_valuesR   R‘   t   fields_limitt   pairst   rt
   name_valuet   nvt   nameRS   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   limited_parse_qslž  s2    	c         C  s)   |  j  d ƒ r% d j |  d ƒ }  n  |  S(   u½   
    If redirecting to an absolute path (two leading slashes), a slash must be
    escaped to prevent browsers from handling the path as schemaless and
    redirecting to another host.
    u   //u   /%2F{}i   (   R‹   t   format(   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   escape_leading_slashes×  s    (W   t
   __future__R    R\   R<   R;   t   reRA   RŒ   Ry   t   binasciiR   Rd   t   email.utilsR   t   django.core.exceptionsR   t   django.utilsR   t   django.utils.datastructuresR   t   django.utils.deprecationR   t   django.utils.encodingR   R   R	   t   django.utils.functionalR
   t#   django.utils.six.moves.urllib.parseR   R   R   R   R   R"   RP   t   urlparseR   R   R   R   R   R   R4   R   t   urllib.parset   compilet   XRg   Rk   R8   t   __Dt   __D2t   __Mt   __Yt   __Y2t   __TR0   R1   R2   R•   t   RFC3986_GENDELIMSt   RFC3986_SUBDELIMSR”   R   R   R   R   R,   R/   RM   RN   RT   R[   R_   Rf   Rn   Ro   Rt   Rp   R~   R.   R‡   R   R{   R    R¢   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/http.pyt   <module>   sx   (	.	4

			$								$8