
	Q[c           @` sz  d  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	 m
 Z
 d d l m Z m Z d d l Z d e _ d d l Z d	 d
 d g Z d j Z d j Z d j Z d e f d     YZ e j e j d Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6dP dQ 6dR dS 6dT dU 6dV dW 6dX dY 6dZ d[ 6d\ d] 6d^ d_ 6d` da 6db dc 6dd de 6df dg 6dh di 6dj dk 6dl dm 6dn do 6dp dq 6dr ds 6dt du 6dv dw 6dx dy 6dz d{ 6d| d} 6d~ d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d6dd6dd6dd6dd	6d
d6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6d d!6d"d#6d$d%6d&d'6d(d)6d*d+6d,d-6d.d/6d0d16d2d36d4d56d6d76d8d96d:d;6d<d=6d>d?6d@dA6dBdC6dDdE6dFdG6dHdI6dJdK6dLdM6dNdO6dPdQ6dRdS6dTdU6dVdW6dXdY6dZd[6Z e d\ Z e j d] Z e j d^ Z d_  Z  d`dadbdcdddedfg Z! d dgdhdidjdkdldmdndodpdqdrg Z# d e! e# ds Z$ dte f du    YZ% dvZ& e j dwe& dxe& dye j  Z' dze f d{    YZ( d|e( f d}    YZ) d S(~  uf
  
http.cookies module ported to python-future from Py3.3

Here's a sample session to show how to use this module.
At the moment, this is the only documentation.

The Basics
----------

Importing is easy...

   >>> from http import cookies

Most of the time you start by creating a cookie.

   >>> C = cookies.SimpleCookie()

Once you've created your Cookie, you can add values just as if it were
a dictionary.

   >>> C = cookies.SimpleCookie()
   >>> C["fig"] = "newton"
   >>> C["sugar"] = "wafer"
   >>> C.output()
   'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'

Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header.  This is the
default behavior.  You can change the header and printed
attributes by using the .output() function

   >>> C = cookies.SimpleCookie()
   >>> C["rocky"] = "road"
   >>> C["rocky"]["path"] = "/cookie"
   >>> print(C.output(header="Cookie:"))
   Cookie: rocky=road; Path=/cookie
   >>> print(C.output(attrs=[], header="Cookie:"))
   Cookie: rocky=road

The load() method of a Cookie extracts cookies from a string.  In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.

   >>> C = cookies.SimpleCookie()
   >>> C.load("chips=ahoy; vienna=finger")
   >>> C.output()
   'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'

The load() method is darn-tootin smart about identifying cookies
within a string.  Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.

   >>> C = cookies.SimpleCookie()
   >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
   >>> print(C)
   Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"

Each element of the Cookie also supports all of the RFC 2109
Cookie attributes.  Here's an example which sets the Path
attribute.

   >>> C = cookies.SimpleCookie()
   >>> C["oreo"] = "doublestuff"
   >>> C["oreo"]["path"] = "/"
   >>> print(C)
   Set-Cookie: oreo=doublestuff; Path=/

Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.

   >>> C = cookies.SimpleCookie()
   >>> C["twix"] = "none for you"
   >>> C["twix"].value
   'none for you'

The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.

   >>> C = cookies.SimpleCookie()
   >>> C["number"] = 7
   >>> C["string"] = "seven"
   >>> C["number"].value
   '7'
   >>> C["string"].value
   'seven'
   >>> C.output()
   'Set-Cookie: number=7\r\nSet-Cookie: string=seven'

Finis.
i    (   t   unicode_literals(   t   print_function(   t   division(   t   absolute_import(   t   chrt   dictt   intt   str(   t   PY2t   as_native_strNu   CookieErroru
   BaseCookieu   SimpleCookieu    u   ; u    t   CookieErrorc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR
      s   u   !#$%&'*+-.^_`|~:u   \000u    u   \001u   u   \002u   u   \003u   u   \004u   u   \005u   u   \006u   u   \007u   u   \010u   u   \011u   	u   \012u   
u   \013u   u   \014u   u   \015u   u   \016u   u   \017u   u   \020u   u   \021u   u   \022u   u   \023u   u   \024u   u   \025u   u   \026u   u   \027u   u   \030u   u   \031u   u   \032u   u   \033u   u   \034u   u   \035u   u   \036u   u   \037u   u   \054u   ,u   \073u   ;u   \"u   "u   \\u   \u   \177u   u   \200u   u   \201u   u   \202u   u   \203u   u   \204u   u   \205u   u   \206u   u   \207u   u   \210u   u   \211u   u   \212u   u   \213u   u   \214u   u   \215u   u   \216u   u   \217u   u   \220u   u   \221u   u   \222u   u   \223u   u   \224u   u   \225u   u   \226u   u   \227u   u   \230u   u   \231u   u   \232u   u   \233u   u   \234u   u   \235u   u   \236u   u   \237u   u   \240u    u   \241u   ¡u   \242u   ¢u   \243u   £u   \244u   ¤u   \245u   ¥u   \246u   ¦u   \247u   §u   \250u   ¨u   \251u   ©u   \252u   ªu   \253u   «u   \254u   ¬u   \255u   ­u   \256u   ®u   \257u   ¯u   \260u   °u   \261u   ±u   \262u   ²u   \263u   ³u   \264u   ´u   \265u   µu   \266u   ¶u   \267u   ·u   \270u   ¸u   \271u   ¹u   \272u   ºu   \273u   »u   \274u   ¼u   \275u   ½u   \276u   ¾u   \277u   ¿u   \300u   Àu   \301u   Áu   \302u   Âu   \303u   Ãu   \304u   Äu   \305u   Åu   \306u   Æu   \307u   Çu   \310u   Èu   \311u   Éu   \312u   Êu   \313u   Ëu   \314u   Ìu   \315u   Íu   \316u   Îu   \317u   Ïu   \320u   Ðu   \321u   Ñu   \322u   Òu   \323u   Óu   \324u   Ôu   \325u   Õu   \326u   Öu   \327u   ×u   \330u   Øu   \331u   Ùu   \332u   Úu   \333u   Ûu   \334u   Üu   \335u   Ýu   \336u   Þu   \337u   ßu   \340u   àu   \341u   áu   \342u   âu   \343u   ãu   \344u   äu   \345u   åu   \346u   æu   \347u   çu   \350u   èu   \351u   éu   \352u   êu   \353u   ëu   \354u   ìu   \355u   íu   \356u   îu   \357u   ïu   \360u   ðu   \361u   ñu   \362u   òu   \363u   óu   \364u   ôu   \365u   õu   \366u   öu   \367u   ÷u   \370u   øu   \371u   ùu   \372u   úu   \373u   ûu   \374u   üu   \375u   ýu   \376u   þu   \377u   ÿc         ` s@   t    f d   |  D  r  |  Sd t d   |  D  d Sd S(   u   Quote a string for use in a cookie header.

    If the string does not need to be double-quoted, then just return the
    string.  Otherwise, surround the string in doublequotes and quote
    (with a \) special characters.
    c         3` s   |  ] } |   k Vq d  S(   N(    (   t   .0t   c(   t
   LegalChars(    s<   lib/python2.7/site-packages/future/backports/http/cookies.pys	   <genexpr>   s    u   "c         s` s!   |  ] } t  j | |  Vq d  S(   N(   t   _Translatort   get(   R   t   s(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pys	   <genexpr>   s    N(   t   allt	   _nulljoin(   R   R   (    (   R   s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   _quote   s    u   \\[0-3][0-7][0-7]u   [\\].c         C` s  t  |   d k  r |  S|  d d k s6 |  d d k r: |  S|  d d !}  d } t  |   } g  } x9d | k oy | k  n rt j |  |  } t j |  |  } | r | r | j |  |  Pn  d } } | r | j d  } n  | r | j d  } n  | rN| s| | k  rN| j |  | | ! | j |  | d  | d } qb | j |  | | ! | j t t |  | d | d !d    | d } qb Wt |  S(   Ni   i    u   "ii   i   i   (	   t   lent
   _OctalPattt   searcht
   _QuotePattt   appendt   startR   R   R   (   t   mystrt   it   nt   rest   o_matcht   q_matcht   jt   k(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   _unquote   s6     
+u   Monu   Tueu   Wedu   Thuu   Friu   Satu   Sunu   Janu   Febu   Maru   Apru   Mayu   Junu   Julu   Augu   Sepu   Octu   Novu   Decc      	   C` so   d d l  m } m  } |   } | | |   \	 } } } }	 }
 } } } } d | | | | | | |	 |
 | f S(   Ni    (   t   gmtimet   timeu#   %s, %02d %3s %4d %02d:%02d:%02d GMT(   R&   R%   (   t   futuret   weekdaynamet	   monthnameR%   R&   t   nowt   yeart   montht   dayt   hht   mmt   sst   wdt   yt   z(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   _getdate2  s
    	+t   Morselc           B` s   e  Z d  Z i d d 6d d 6d d 6d d 6d d	 6d
 d
 6d d 6d d 6Z e d
 d g  Z d   Z d   Z d   Z e	 d  Z d d d  Z e Z e   d    Z d d  Z d d  Z RS(   u  A class to hold ONE (key, value) pair.

    In a cookie, each such pair may have several attributes, so this class is
    used to keep the attributes associated with the appropriate key,value pair.
    This class also includes a coded_value attribute, which is used to hold
    the network representation of the value.  This is most useful when Python
    objects are pickled for network transit.
    u   expiresu   Pathu   pathu   Commentu   commentu   Domainu   domainu   Max-Ageu   max-ageu   secureu   httponlyu   Versionu   versionc         C` sB   d  |  _ |  _ |  _ x$ |  j D] } t j |  | d  q! Wd  S(   Nu    (   t   Nonet   keyt   valuet   coded_valuet	   _reservedR   t   __setitem__(   t   selfR7   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   __init__]  s    c         C` sE   | j    } | |  j k r. t d |   n  t j |  | |  d  S(   Nu   Invalid Attribute %s(   t   lowerR:   R
   R   R;   (   R<   t   Kt   V(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR;   e  s    c         C` s   | j    |  j k S(   N(   R>   R:   (   R<   R?   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   isReservedKeyk  s    c         ` sv   | j    |  j k r( t d |   n  t   f d   | D  rW t d |   n  | |  _ | |  _ | |  _ d  S(   Nu!   Attempt to set a reserved key: %sc         3` s   |  ] } |   k Vq d  S(   N(    (   R   R   (   R   (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pys	   <genexpr>s  s    u   Illegal key value: %s(   R>   R:   R
   t   anyR7   R8   R9   (   R<   R7   t   valt	   coded_valR   (    (   R   s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   setn  s    		u   Set-Cookie:c         C` s   d | |  j  |  f S(   Nu   %s %s(   t   OutputString(   R<   t   attrst   header(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   output{  s    c         C` sY   t  r* t |  j t  r* t |  j  } n	 |  j } d |  j j t |  j  t |  f S(   Nu   <%s: %s=%s>(	   R   t
   isinstanceR8   t   unicodeR   t	   __class__R   R7   t   repr(   R<   RC   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   __repr__  s
    	c         C` s   d |  j  |  j d d  S(   Nu   
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        u   "u   \"(   RF   t   replace(   R<   RG   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt	   js_output  s    c         C` sw  g  } | j  } | d |  j |  j f  | d  k rA |  j } n  t |  j    } x| D]\ } } | d k rx qZ n  | | k r qZ n  | d k r t | t  r | d |  j | t	 |  f  qZ | d k rt | t  r| d |  j | | f  qZ | d k r(| t
 |  j |   qZ | d k rN| t
 |  j |   qZ | d |  j | | f  qZ Wt |  S(   Nu   %s=%su    u   expiresu   max-ageu   %s=%du   secureu   httponly(   R   R7   R9   R6   R:   t   sortedt   itemsRJ   R   R4   R   t   _semispacejoin(   R<   RG   t   resultR   RR   R7   R8   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRF     s*    	$N(   R   R   t   __doc__R:   RE   t   _flagsR=   R;   RA   t   _LegalCharsR6   RI   t   __str__R	   RN   RP   RF   (    (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR5   :  s(   
				
u.   [\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]u~   
    (?x)                           # This is a verbose pattern
    (?P<key>                       # Start of group 'key'
    u  +?   # Any word of at least one letter
    )                              # End of group 'key'
    (                              # Optional group: there may not be a value.
    \s*=\s*                          # Equal Sign
    (?P<val>                         # Start of group 'val'
    "(?:[^\\"]|\\.)*"                  # Any doublequoted string
    |                                  # or
    \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT  # Special case for "expires" attr
    |                                  # or
    u,  *      # Any word or empty string
    )                                # End of group 'val'
    )?                             # End of optional value group
    \s*                            # Any number of spaces.
    (\s+|;|$)                      # Ending either at space, semicolon, or EOS.
    t
   BaseCookiec           B` s   e  Z d  Z d   Z d   Z d d  Z d   Z d   Z d d d d  Z	 e	 Z
 e   d	    Z d d
  Z d   Z e d  Z RS(   u'   A container class for a set of Morsels.c         C` s
   | | f S(   u
  real_value, coded_value = value_decode(STRING)
        Called prior to setting a cookie's value from the network
        representation.  The VALUE is the value read from HTTP
        header.
        Override this function to modify the behavior of cookies.
        (    (   R<   RC   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   value_decode  s    c         C` s   t  |  } | | f S(   u   real_value, coded_value = value_encode(VALUE)
        Called prior to setting a cookie's value from the dictionary
        representation.  The VALUE is the value being assigned.
        Override this function to modify the behavior of cookies.
        (   R   (   R<   RC   t   strval(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   value_encode  s    c         C` s   | r |  j  |  n  d  S(   N(   t   load(   R<   t   input(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR=     s    c         C` s?   |  j  | t    } | j | | |  t j |  | |  d S(   u+   Private method for setting a cookie's valueN(   R   R5   RE   R   R;   (   R<   R7   t
   real_valueR9   t   M(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   __set  s    c         C` s,   |  j  |  \ } } |  j | | |  d S(   u   Dictionary style assignment.N(   R\   t   _BaseCookie__set(   R<   R7   R8   t   rvalt   cval(    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR;     s    u   Set-Cookie:u   
c         C` sU   g  } t  |  j    } x- | D]% \ } } | j | j | |   q W| j |  S(   u"   Return a string suitable for HTTP.(   RQ   RR   R   RI   t   join(   R<   RG   RH   t   sepRT   RR   R7   R8   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRI     s
    c         C` s   g  } t  |  j    } xj | D]b \ } } t rU t | j t  rU t | j  } n	 | j } | j d t |  t |  f  q Wd |  j	 j
 t |  f S(   Nu   %s=%su   <%s: %s>(   RQ   RR   R   RJ   R8   RK   R   R   RM   RL   R   t
   _spacejoin(   R<   t   lRR   R7   R8   RC   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRN     s    	'c         C` sO   g  } t  |  j    } x* | D]" \ } } | j | j |   q Wt |  S(   u(   Return a string suitable for JavaScript.(   RQ   RR   R   RP   R   (   R<   RG   RT   RR   R7   R8   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRP     s
    c         C` sJ   t  | t  r |  j |  n' x$ | j   D] \ } } | |  | <q, Wd S(   u   Load cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        N(   RJ   R   t   _BaseCookie__parse_stringRR   (   R<   t   rawdataR7   R8   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR]     s
    c         C` sV  d } t  |  } d  } x7d | k o2 | k  n rQ| j | |  } | sS Pn  | j d  | j d  } } | j d  } | d d k r | rN| | | d <qNq | j   t j k r| rN| d  k r | j   t j k rt	 | | <qq
t
 |  | | <qNq | d  k	 r |  j |  \ }	 }
 |  j | |	 |
  |  | } q q Wd  S(   Ni    u   keyu   valu   $i   (   R   R6   R   t   groupt   endR>   R5   R:   RV   t   TrueR$   RZ   Rb   (   R<   R   t   pattR   R   R`   t   matchR7   R8   Rc   Rd   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   __parse_string%  s,    N(   R   R   RU   RZ   R\   R6   R=   Rb   R;   RI   RX   R	   RN   RP   R]   t   _CookiePatternRi   (    (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRY     s   							t   SimpleCookiec           B` s    e  Z d  Z d   Z d   Z RS(   u   
    SimpleCookie supports strings as cookie values.  When setting
    the value using the dictionary assignment notation, SimpleCookie
    calls the builtin str() to convert the value to a string.  Values
    received from HTTP are kept as strings.
    c         C` s   t  |  | f S(   N(   R$   (   R<   RC   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRZ   P  s    c         C` s   t  |  } | t |  f S(   N(   R   R   (   R<   RC   R[   (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyR\   S  s    (   R   R   RU   RZ   R\   (    (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyRr   I  s   	(*   RU   t
   __future__R    R   R   R   t   future.builtinsR   R   R   R   t   future.utilsR   R	   t   ret   ASCIIt   stringt   __all__Re   R   RS   Rg   t	   ExceptionR
   t   ascii_letterst   digitsRW   R   R   t   compileR   R   R$   t   _weekdaynameR6   t
   _monthnameR4   R5   t   _LegalCharsPattRq   RY   Rr   (    (    (    s<   lib/python2.7/site-packages/future/backports/http/cookies.pyt   <module>   s   "					2t