ó
ù¢TQc           @  sc  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l m Z Wn5 e	 k
 r‹ d  d l Z d  d l
 Z
 e
 j
 e _
 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 e j d	 ƒ Z d
 j ƒ  Z d Z d Z d Z d Z d Z d Z e j d e e e e f ƒ Z  e j d e e e e f ƒ Z! e j d e e e e f ƒ Z" d d „ Z# e e# e j$ ƒ Z# d d „ Z% e e% e j$ ƒ Z% d „  Z& e e& e j$ ƒ Z& d „  Z' e e' e j$ ƒ Z' d d „ Z( d d „ Z* d d „ Z+ d „  Z, d „  Z- d  „  Z. d! „  Z/ d" „  Z0 d# „  Z1 d$ „  Z2 d d% „ Z3 d S(&   iÿÿÿÿ(   t   unicode_literalsN(   t   parse(   t
   formatdate(   t   MultiValueDict(   t	   force_strt
   force_text(   t
   allow_lazy(   t   sixu   (?:W/)?"((?:\\.|[^"])*)"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   /c         C  s"   t  t j 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   t   urllib_parset   quoteR   (   t   urlt   safe(    (    s*   ../Django//lib/python/django/utils/http.pyt   urlquote#   s    u    c         C  s"   t  t j 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   t
   quote_plusR   (   R
   R   (    (    s*   ../Django//lib/python/django/utils/http.pyt   urlquote_plus-   s    c         C  s   t  t j t |  ƒ ƒ ƒ S(   u~   
    A wrapper for Python's urllib.unquote() function that can operate on
    the result of django.utils.http.urlquote().
    (   R   R   t   unquoteR   (   t
   quoted_url(    (    s*   ../Django//lib/python/django/utils/http.pyt
   urlunquote7   s    c         C  s   t  t j 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   t   unquote_plusR   (   R   (    (    s*   ../Django//lib/python/django/utils/http.pyt   urlunquote_plus?   s    i    c         C  s«   t  |  t ƒ r |  j ƒ  }  n t |  d ƒ r< |  j ƒ  }  n  t j g  |  D]X \ } } t | ƒ t  | t t	 f ƒ r’ g  | D] } t | ƒ ^ qz n	 t | ƒ f ^ qI | ƒ S(   u¿   
    A version of Python's urllib.urlencode() function that can operate on
    unicode strings. The parameters are first case to UTF-8 encoded strings and
    then encoded as per normal.
    u   items(
   t
   isinstanceR   t   listst   hasattrt   itemsR   t	   urlencodeR   t   listt   tuple(   t   queryt   doseqt   kt   vt   i(    (    s*   ../Django//lib/python/django/utils/http.pyR   G   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*   ../Django//lib/python/django/utils/http.pyt   cookie_dateW   s    
c         C  s   t  |  ƒ } d | d  S(   ua  
    Formats the time to match the RFC1123 date format as specified by HTTP
    RFC2616 section 3.3.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'.
    u   %s GMTi   (   R   (   R    R!   (    (    s*   ../Django//lib/python/django/utils/http.pyt	   http_dated   s    c   
      C  sc  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 ƒ  ƒ SWn! t k
 r^t d |  ƒ ‚ n Xd S(   u  
    Parses a date format as specified by HTTP RFC2616 section 3.3.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 dateN(   t   RFC1123_DATEt   RFC850_DATEt   ASCTIME_DATEt   matcht   Nonet
   ValueErrort   intt   groupt   MONTHSt   indext   lowert   datetimet   calendart   timegmt   utctimetuplet	   Exception(
   t   datet   regext   mt   yeart   montht   dayt   hourt   mint   sect   result(    (    s*   ../Django//lib/python/django/utils/http.pyt   parse_http_dater   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(   R>   R3   (   R4   (    (    s*   ../Django//lib/python/django/utils/http.pyt   parse_http_date_safe•   s    c         C  s\   t  |  ƒ d k r! t d ƒ ‚ n  t |  d ƒ } t j rX | t j k rX 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   lenR)   R*   R   t   PY3t   syst   maxint(   t   st   value(    (    s*   ../Django//lib/python/django/utils/http.pyt   base36_to_int    s    c         C  s   d } d } |  d k  r' t  d ƒ ‚ n  t j sr t |  t j ƒ sQ t d ƒ ‚ n  |  t j k rr t  d ƒ ‚ qr n  x2 t r¦ | d 7} |  d | k  ru | d 8} Pqu qu Wg  } xC | d k rò d | } | j	 | |  | ƒ |  | }  | d 8} q° Wd j
 | ƒ 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   i$   u    (   R)   R   RA   R   t   integer_typest	   TypeErrorRB   RC   t   Truet   appendt   join(   R   t   digitst   factort   base36t   j(    (    s*   ../Django//lib/python/django/utils/http.pyt   int_to_base36±   s*    		



c         C  sK   t  j |  ƒ } | s |  g Sg  | D] } | j d ƒ j d ƒ ^ q# } | S(   uÜ   
    Parses a string with one or several etags passed in If-None-Match and
    If-Match headers by the rules in RFC 2616. Returns a list of etags
    without surrounding double quotes (") and unescaped from \<CHAR>.
    u   asciiu   unicode_escape(   t
   ETAG_MATCHt   findallt   encodet   decode(   t   etag_strt   etagst   e(    (    s*   ../Django//lib/python/django/utils/http.pyt   parse_etagsÍ   s
    +c         C  s    d |  j  d d ƒ j  d d ƒ S(   uH   
    Wraps a string in double quotes escaping contents as necesary.
    u   "%s"u   \u   \\u   "u   \"(   t   replace(   t   etag(    (    s*   ../Django//lib/python/django/utils/http.pyt
   quote_etagÚ   s    c         C  sM   t  j |  ƒ t  j | ƒ } } | j | j | j f | j | j | j f k S(   u.   
    Checks if two URLs are 'same-origin'
    (   R   t   urlparset   schemet   hostnamet   port(   t   url1t   url2t   p1t   p2(    (    s*   ../Django//lib/python/django/utils/http.pyt   same_originà   s    c         C  s.   |  s
 t  St j |  ƒ d } | p- | | k S(   uš   
    Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
    a different host).

    Always returns ``False`` on an empty url.
    i   (   t   FalseR   R\   (   R
   t   hostt   netloc(    (    s*   ../Django//lib/python/django/utils/http.pyt   is_safe_urlç   s    (4   t
   __future__R    R0   R/   t   reRB   t   urllibR   R   t   ImportErrorR\   t   email.utilsR   t   django.utils.datastructuresR   t   django.utils.encodingR   R   t   django.utils.functionalR   t   django.utilsR   t   compileRQ   t   splitR,   t   __Dt   __D2t   __Mt   __Yt   __Y2t   __TR$   R%   R&   R   t	   text_typeR   R   R   R   R(   R"   R#   R>   R?   RF   RP   RX   R[   Rd   Rh   (    (    (    s*   ../Django//lib/python/django/utils/http.pyt   <module>   sZ   			#						