
`Tc           @   s  d  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
 y d d l m Z Wn! e k
 r d d l m Z n Xy d d	 l m Z Wn! e k
 r d d	 l m Z n Xd d
 l m Z m Z m Z m Z m Z m Z m Z m Z m Z d d l m Z m Z d d l  m! Z! d d l" m# Z# m$ Z$ m% Z% m& Z& m' Z' m( Z( d d l) m* Z* m+ Z+ m, Z, d d l- m. Z. d d l/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 e5 d d e6 d d  Z7 e6 d d  Z8 e6 e6 d  Z9 d e: f d     YZ; d e: f d     YZ< d e f d     YZ= d   Z> d e: f d     YZ? d  e@ f d!     YZA d" e: f d#     YZB d$   ZC eD d%  ZE d S(&   s   
    werkzeug.test
    ~~~~~~~~~~~~~

    This module implements a client to WSGI applications for testing.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iN(   t   time(   t   random(   t   chain(   t   TemporaryFile(   t   BytesIO(   t   Request(   t	   CookieJar(	   t	   iterlistst	   iteritemst
   itervaluest   to_bytest   string_typest	   text_typet   reraiset   wsgi_encoding_dancet   make_literal_wrapper(   t   _empty_streamt   _get_environ(   t   BaseRequest(   t
   url_encodet   url_fixt
   iri_to_urit   url_unquotet   url_unparset	   url_parse(   t   get_hostt   get_current_urlt   ClosingIterator(   t   dump_cookie(   t   FileMultiDictt	   MultiDictt   CombinedMultiDictt   Headerst   FileStoragei   i  s   utf-8c      	      s<  | d k r% d t   t   f } n  t   d t g  | rR   f d     n  d j      f d   } t |  t  s t |   }  n  xdt |   D]V\ } }  xG|  D]?} | d | | f  t	 | d d  } | d k	 rt	 | d t	 | d d   }	 t	 | d	 d  }
 |
 d k rE|	 r<t
 j |	  d p?d
 }
 n  |	 d k	 rb| d |	  n
 | d  | d |
  xg | d  } | sPn    |  q}nA t | t  st |  } n t |   } | d    |  | d  q Wq W| d |  t  d j    }  d j d   d | | f S(   s   Encode a dict of values (either strings or file descriptors or
    :class:`FileStorage` objects.) into a multipart encoded string stored
    in a file descriptor.
    s$   ---------------WerkzeugFormPart_%s%si    c            s     \ } } } | r% | j  |   n~ t |   } |   d  k rU | j  |   n@ t d  } | j  | j    | j  |   |   d <t   d <| |   d <d  S(   Ni   s   wb+i    i   (   t   writet   lenR   t   getvaluet   True(   t   stringt   streamt   total_lengtht   on_diskt   lengtht
   new_stream(   t   _closuret	   threshold(    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   write_binary4   s    

c            s     |  j     d  S(   N(   t   encode(   R&   (   R.   t   charset(    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR"   F   s    s/   --%s
Content-Disposition: form-data; name="%s"t   readt   filenamet   namet   content_types   application/octet-streams   ; filename="%s"
s   
s   Content-Type: %s

i @  s   

s   --%s--
N(   t   NoneR    R   R   t   FalseR"   t
   isinstanceR   R   t   getattrt	   mimetypest
   guess_typeR   t   strR
   t   intt   tellt   seek(   t   valuest   use_tempfileR-   t   boundaryR0   R"   t   keyt   valuet   readerR2   R4   t   chunkR*   (    (   R.   R-   R0   R,   sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   stream_encode_multipart)   sR    		


c         C   s7   t  |  d t d | d | \ } } } | | j   f S(   s|   Like `stream_encode_multipart` but returns a tuple in the form
    (``boundary``, ``data``) where data is a bytestring.
    R@   RA   R0   (   RF   R6   R1   (   R?   RA   R0   R'   R*   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   encode_multipartr   s    $c         C   s6   d d l  m } | t d   t |  d | d | S(   s   Backwards compat.i(   t   warnsO   werkzeug.test.File is deprecated, use the EnvironBuilder or FileStorage insteadR2   R4   (   t   warningsRH   t   DeprecationWarningR!   (   t   fdR2   t   mimetypeRH   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   File{   s    t   _TestCookieHeadersc           B   s,   e  Z d  Z d   Z d   Z d d  Z RS(   s$   A headers adapter for cookielib
    c         C   s   | |  _  d  S(   N(   t   headers(   t   selfRO   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   __init__   s    c         C   sR   g  } | j    } x9 |  j D]. \ } } | j    | k r | j |  q q W| S(   N(   t   lowerRO   t   append(   RP   R3   RO   t   kt   v(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt
   getheaders   s    c         C   sX   g  } x? |  j  D]4 \ } } | j   | j   k r | j |  q q W| pW | pW g  S(   N(   RO   RR   RS   (   RP   R3   t   defaultt   rvRT   RU   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   get_all   s
    N(   t   __name__t
   __module__t   __doc__RQ   RV   R5   RY   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyRN      s   		t   _TestCookieResponsec           B   s    e  Z d  Z d   Z d   Z RS(   s   Something that looks like a httplib.HTTPResponse, but is actually just an
    adapter for our test responses to make them available for cookielib.
    c         C   s   t  |  |  _ d  S(   N(   RN   RO   (   RP   RO   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyRQ      s    c         C   s   |  j  S(   N(   RO   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   info   s    (   RZ   R[   R\   RQ   R^   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR]      s   	t   _TestCookieJarc           B   s    e  Z d  Z d   Z d   Z RS(   s   A cookielib.CookieJar modified to inject and read cookie headers from
    and to wsgi environments, and wsgi application responses.
    c         C   sT   g  } x+ |  D]# } | j  d | j | j f  q W| rP d j |  | d <n  d S(   sY   Inject the cookies as client headers into the server's wsgi
        environment.
        s   %s=%ss   ; t   HTTP_COOKIEN(   RS   R3   RC   t   join(   RP   t   environt   cvalst   cookie(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   inject_wsgi   s
    !c         C   s&   |  j  t |  t t |    d S(   sX   Extract the server's set-cookie headers as cookies into the
        cookie jar.
        N(   t   extract_cookiesR]   t	   U2RequestR   (   RP   Rb   RO   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   extract_wsgi   s    	(   RZ   R[   R\   Re   Rh   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR_      s   	
c         c   s   t  |  t  rK x t |   D]( \ } } x | D] } | | f Vq/ Wq WnV xS t |   D]E \ } } t  | t  r x' | D] } | | f Vqz WqX | | f VqX Wd S(   s   Iterates over a dict or multidict yielding all keys and values.
    This is used to iterate over the data passed to the
    :class:`EnvironBuilder`.
    N(   R7   R   R   R   t   list(   t   dataRB   R?   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt
   _iter_data   s    t   EnvironBuilderc           B   s  e  Z d  Z d Z d' Z e Z d d( d( d d( d( d( d( e e e d( d( d( d( d d  Z	 d   Z
 d	   Z d
   Z e e e d d Z [ [ d   Z d   Z e e e d d Z [ [ d   Z d   Z e e e d d Z [ [ d   Z e d e d d Z e d e d d Z [ d   Z d   Z e e e d d Z [ [ d   Z d   Z e e e d d Z [ [ d   Z  d   Z! e e  e! d d  Z" [  [! e d!    Z# e d"    Z$ d#   Z% d$   Z& d%   Z' d( d&  Z( RS()   sF  This class can be used to conveniently create a WSGI environment
    for testing purposes.  It can be used to quickly create WSGI environments
    or request objects from arbitrary data.

    The signature of this class is also used in some other places as of
    Werkzeug 0.5 (:func:`create_environ`, :meth:`BaseResponse.from_values`,
    :meth:`Client.open`).  Because of this most of the functionality is
    available through the constructor alone.

    Files and regular form data can be manipulated independently of each
    other with the :attr:`form` and :attr:`files` attributes, but are
    passed with the same argument to the constructor: `data`.

    `data` can be any of these values:

    -   a `str`: If it's a string it is converted into a :attr:`input_stream`,
        the :attr:`content_length` is set and you have to provide a
        :attr:`content_type`.
    -   a `dict`: If it's a dict the keys have to be strings and the values
        any of the following objects:

        -   a :class:`file`-like object.  These are converted into
            :class:`FileStorage` objects automatically.
        -   a tuple.  The :meth:`~FileMultiDict.add_file` method is called
            with the tuple items as positional arguments.

    .. versionadded:: 0.6
       `path` and `base_url` can now be unicode strings that are encoded using
       the :func:`iri_to_uri` function.

    :param path: the path of the request.  In the WSGI environment this will
                 end up as `PATH_INFO`.  If the `query_string` is not defined
                 and there is a question mark in the `path` everything after
                 it is used as query string.
    :param base_url: the base URL is a URL that is used to extract the WSGI
                     URL scheme, host (server name + server port) and the
                     script root (`SCRIPT_NAME`).
    :param query_string: an optional string or dict with URL parameters.
    :param method: the HTTP method to use, defaults to `GET`.
    :param input_stream: an optional input stream.  Do not specify this and
                         `data`.  As soon as an input stream is set you can't
                         modify :attr:`args` and :attr:`files` unless you
                         set the :attr:`input_stream` to `None` again.
    :param content_type: The content type for the request.  As of 0.5 you
                         don't have to provide this when specifying files
                         and form data via `data`.
    :param content_length: The content length for the request.  You don't
                           have to specify this when providing data via
                           `data`.
    :param errors_stream: an optional error stream that is used for
                          `wsgi.errors`.  Defaults to :data:`stderr`.
    :param multithread: controls `wsgi.multithread`.  Defaults to `False`.
    :param multiprocess: controls `wsgi.multiprocess`.  Defaults to `False`.
    :param run_once: controls `wsgi.run_once`.  Defaults to `False`.
    :param headers: an optional list or :class:`Headers` object of headers.
    :param data: a string or dict of form data.  See explanation above.
    :param environ_base: an optional dict of environment defaults.
    :param environ_overrides: an optional dict of environment overrides.
    :param charset: the charset used to encode unicode data.
    s   HTTP/1.1i   i    t   /t   GETs   utf-8c         C   s  t  |  } | d  k rK | d  | k rK | j | d  d  \ } } n  | |  _ t |  |  _ | d  k	 r t t | |  |  } n  | |  _ t | t	 t
 f  r | |  _ n? | d  k r t   } n t | t  s t |  } n  | |  _ | |  _ | d  k rt   } n t | t  s2t |  } n  | |  _ | d  k	 rS| |  _ n  | d  k rkt j } n  | |  _ |	 |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ t |  _ | r| d  k	 rt d   n  t | t
  r| j |  j  } n  t | t	  rCt  |  |  _ |  j d  k rt! |  |  _ qqxm t" |  D]\ \ } } t | t# t$ f  st% | d  r|  j& | |  qP|  j' j( |  j) |  qPWn  d  S(   Nt   ?i   s#   can't provide input stream and dataR1   (*   R   R5   t   splitR0   R   t   pathR   t   base_urlR7   t   bytesR   t   query_stringR   t   argst   methodR    RO   R4   t   syst   stderrt   errors_streamt   multithreadt   multiprocesst   run_oncet   environ_baset   environ_overridest   input_streamt   content_lengthR6   t   closedt	   TypeErrorR/   R   R#   Rk   t   tuplet   dictt   hasattrt   _add_file_from_datat   formt   setlistdefaultRS   (   RP   Rq   Rr   Rt   Rv   R   R4   R   Ry   Rz   R{   R|   RO   Rj   R}   R~   R0   t   path_sRB   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyRQ     s`    !														c         C   s   t  | t  r% |  j j | |  n t  | t  r d d l m } | t d  d d t |  } | j d d  } | d k	 r | | d <n  |  j j | |  n |  j j | |  d S(	   s=   Called in the EnvironBuilder to add files from the data dict.i(   RH   s[   it's no longer possible to pass dicts as `data`.  Use tuples or FileStorage objects insteadt
   stackleveli   RL   R4   N(
   R7   R   t   filest   add_fileR   RI   RH   RJ   t   popR5   (   RP   RB   RC   RH   RL   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR   R  s    c         C   s/   t  |  j |  j |  j d d f  j d  d S(   Nt    Rm   (   R   t
   url_schemet   hostt   script_roott   rstrip(   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _get_base_urlc  s    c         C   s   | d  k r! d } d } d } n6 t |  \ } } } } } | sH | rW t d   n  | j d  |  _ | |  _ | |  _ d  S(   Nt   httpt	   localhostR   s4   base url must not contain a query string or fragmentRm   (   R5   R   t
   ValueErrorR   R   R   R   (   RP   RC   t   schemet   netlocR   t   qst   anchor(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _set_base_urlg  s    		t   docs   
        The base URL is a URL that is used to extract the WSGI
        URL scheme, host (server name + server port) and the
        script root (`SCRIPT_NAME`).c         C   sP   |  j  j d  } | d  k rL |  j rL |  j d k rH |  j rD d Sd Sd  S| S(   Ns   Content-Typet   POSTt   PUTt   PATCHs   multipart/form-datas!   application/x-www-form-urlencoded(   R   R   R   (   RO   t   getR5   t   _input_streamRv   t   _files(   RP   t   ct(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _get_content_type{  s    	c         C   s3   | d  k r" |  j j d d   n | |  j d <d  S(   Ns   Content-Type(   R5   RO   R   (   RP   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _set_content_type  s    s   
        The content type for the request.  Reflected from and to the
        :attr:`headers`.  Do not set if you set :attr:`files` or
        :attr:`form` for auto detection.c         C   s   |  j  j d d t S(   Ns   Content-Lengtht   type(   RO   R   R<   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _get_content_length  s    c         C   s9   | d  k r" |  j j d d   n t |  |  j d <d  S(   Ns   Content-Length(   R5   RO   R   R;   (   RP   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _set_content_length  s    s   
        The content length as integer.  Reflected from and to the
        :attr:`headers`.  Do not set if you set :attr:`files` or
        :attr:`form` for auto detection.c            s;   d |      f d   }  f d   } t  | | |  S(   Nt   _c            sY   |  j  d  k	 r t d   n  t |    } | d  k rU     } t |   |  n  | S(   Ns   an input stream is defined(   R   R5   t   AttributeErrorR8   t   setattr(   RP   RX   (   t   storageRB   (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   getter  s    	c            s   d  |  _ t |    |  d  S(   N(   R5   R   R   (   RP   RC   (   RB   (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   setter  s    	(   t   property(   R3   R   R   R   R   (    (   R   RB   sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   form_property  s    
R   s-   
        A :class:`MultiDict` of form values.R   s   
        A :class:`FileMultiDict` of uploaded files.  You can use the
        :meth:`~FileMultiDict.add_file` method to add new files to the
        dict.c         C   s   |  j  S(   N(   R   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _get_input_stream  s    c         C   s   | |  _  d  |  _ |  _ d  S(   N(   R   R5   t   _formR   (   RP   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _set_input_stream  s    	si   
        An optional input stream.  If you set this it will clear
        :attr:`form` and :attr:`files`.c         C   s?   |  j  d  k r8 |  j d  k	 r4 t |  j d |  j Sd S|  j  S(   NR0   R   (   t   _query_stringR5   t   _argsR   R0   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _get_query_string  s
    c         C   s   | |  _  d  |  _ d  S(   N(   R   R5   R   (   RP   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _set_query_string  s    	si   
        The query string.  If you set this to a string :attr:`args` will
        no longer be available.c         C   sC   |  j  d  k	 r t d   n  |  j d  k r< t   |  _ n  |  j S(   Ns   a query string is defined(   R   R5   R   R   R   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt	   _get_args  s
    c         C   s   d  |  _ | |  _ d  S(   N(   R5   R   R   (   RP   RC   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt	   _set_args  s    	s1   
        The URL arguments as :class:`MultiDict`.c         C   s   |  j  j d d  d S(   s4   The server name (read-only, use :attr:`host` to set)t   :i   i    (   R   Rp   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   server_name  s    c         C   s\   |  j  j d d  } t |  d k rE | d j   rE t | d  S|  j d k rX d Sd S(   s?   The server port as integer (read-only, use :attr:`host` to set)R   i   i   t   httpsi  iP   (   R   Rp   R#   t   isdigitR<   R   (   RP   t   pieces(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   server_port  s    "c         C   s&   y |  j    Wn t k
 r! n Xd  S(   N(   t   closet	   Exception(   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   __del__  s    c         C   sz   |  j  r d Sy t |  j  } Wn t k
 r9 d } n Xx0 | D]( } y | j   WqA t k
 rh qA XqA Wt |  _  d S(   s   Closes all files.  If you put real :class:`file` objects into the
        :attr:`files` dict you can call this method to automatically close
        them all in one go.
        N(    (   R   R	   R   R   R   R   R%   (   RP   R   t   f(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR     s    	
c      	      s    j  }   j }   j } | d k	 ri | j   } | j d d  | j   } | j |  | | } n | d k r t   j   j g  } t	 | d   j
 \ } } } | d | 7} nT | d k r
t   j d   j
 } | j d  } t |  } t |  } n t } i  }   j r2| j   j  n    f d   }	 t   j  }
 | j i   j d	 6|	   j  d
 6|	   j  d 6|
 d 6  j d 6t   j  d 6  j d 6  j d 6| pd d 6t | pd  d 6  j d 6  j d 6| d 6  j d 6  j d 6  j  d 6  j! d 6 x=   j" j#   D], \ } } | | d | j$   j% d d  <q/W  j& r{| j   j&  n  | S(    s   Return the built environ.i    i   s   multipart/form-dataR0   s   ; boundary="%s"s!   application/x-www-form-urlencodedt   asciic            s   t  t |    j    j  S(   N(   R   R   R0   (   t   x(   RP   (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   _path_encode'  s    t   REQUEST_METHODt   SCRIPT_NAMEt	   PATH_INFOt   QUERY_STRINGt   SERVER_NAMEt   SERVER_PORTt	   HTTP_HOSTt   SERVER_PROTOCOLR   t   CONTENT_TYPEt   0t   CONTENT_LENGTHs   wsgi.versions   wsgi.url_schemes
   wsgi.inputs   wsgi.errorss   wsgi.multithreads   wsgi.multiprocesss   wsgi.run_onces   HTTP_%st   -R   N('   R   R   R4   R5   R=   R>   R   R   R   RF   R0   R   R/   R#   R   R   R}   t   updateR   Rt   Rv   R   Rq   R   R;   R   R   t   server_protocolt   wsgi_versionR   Ry   Rz   R{   R|   RO   t   to_wsgi_listt   uppert   replaceR~   (   RP   R   R   R4   t	   start_post   end_posR?   RA   t   resultR   R   RB   RC   (    (   RP   sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   get_environ	  s^    					








$	c         C   s(   | d k r |  j } n  | |  j    S(   s   Returns a request with the data.  If the request class is not
        specified :attr:`request_class` is used.

        :param cls: The request wrapper to use.
        N(   R5   t   request_classR   (   RP   t   cls(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   get_requestE  s    (   i   i    N()   RZ   R[   R\   R   R   R   R   R5   R6   RQ   R   R   R   R   Rr   R   R   R4   R   R   R   R   R   R   R   R   R   R   R   R   R   Rt   R   R   Ru   R   R   R   R   R   R   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyRl      sh   <			6					
																	
			<t   ClientRedirectErrorc           B   s   e  Z d  Z RS(   s   
    If a redirect loop is detected when using follow_redirects=True with
    the :cls:`Client`, then this exception is raised.
    (   RZ   R[   R\   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR   P  s   t   Clientc        	   B   s   e  Z d  Z d e e d  Z d d d d d d e d d  Z d d d  Z e d  Z	 e d  Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   st  This class allows to send requests to a wrapped application.

    The response wrapper can be a class or factory function that takes
    three arguments: app_iter, status and headers.  The default response
    wrapper just returns a tuple.

    Example::

        class ClientResponse(BaseResponse):
            ...

        client = Client(MyApplication(), response_wrapper=ClientResponse)

    The use_cookies parameter indicates whether cookies should be stored and
    sent for subsequent requests. This is True by default, but passing False
    will disable this behaviour.

    If you want to request some subdomain of your application you may set
    `allow_subdomain_redirects` to `True` as if not no external redirects
    are allowed.

    .. versionadded:: 0.5
       `use_cookies` is new in this version.  Older versions did not provide
       builtin cookie support.
    c         C   s=   | |  _  | |  _ | r' t   |  _ n	 d  |  _ | |  _ d  S(   N(   t   applicationt   response_wrapperR_   t
   cookie_jarR5   t   allow_subdomain_redirects(   RP   R   R   t   use_cookiesR   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyRQ   r  s    			R   Rm   s   utf-8c      
   C   s{   |  j  d k	 s t d   t | | | | | | | |	 |
 	 } t | d d | } d | f g } |  j  j | |  d S(   s   Sets a cookie in the client's cookie jar.  The server name
        is required and has to match the one that is also passed to
        the open call.
        s   cookies disabledRr   s   http://s
   Set-CookieN(   R   R5   t   AssertionErrorR   t   create_environRh   (   RP   R   RB   RC   t   max_aget   expiresRq   t   domaint   securet   httponlyR0   t   headerRb   RO   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt
   set_cookie|  s    c         C   s,   |  j  | | d d d d d | d | d S(   s$   Deletes a cookie in the test client.R   i    R   Rq   R   N(   R   (   RP   R   RB   Rq   R   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   delete_cookie  s    c         C   sg   |  j  d k	 r" |  j  j |  n  t |  j | d | } |  j  d k	 rc |  j  j | | d  n  | S(   s5   Runs the wrapped WSGI app with the given environment.t   bufferedi   N(   R   R5   Re   t   run_wsgi_appR   Rh   (   RP   Rb   R   RX   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR     s    c         C   s!  t  |  \ } } } } }	 t | | d d d f  j d  d }
 | j d d  d j d  } t |  j d d  d j d  } |  j r | t |  | k } n | | k } | s t d |  j	   n  |  j
 } d |  _
 z, |  j d | d	 |
 d
 | d t d |  SWd | |  _
 Xd S(   sl   Resolves a single redirect and triggers the request again
        directly on this redirect client.
        R   Rm   R   i   i    t   .s0   %r does not support redirect to external targetsRq   Rr   Rt   t   as_tupleR   N(   R   R   R   Rp   R   t   rsplitR   R#   t   RuntimeErrort	   __class__R   R5   t   openR%   (   RP   t   responset   new_locationRb   R   R   R   R   R   R   Rr   t   cur_server_namet   real_server_namet   allowedt   old_response_wrapper(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   resolve_redirect  s"    (%			c         O   s  | j  d t  } | j  d t  } | j  d t  } d } | r t |  d k r t | d t  r{ | d j   } q t | d t  r | d } q n  | d k r t | |   } z | j   } Wd | j   Xn  |  j	 | d | } g  }	 x t
 | d j d d  d  }
 |
 d k s+| r/Pn  | d d } | |
 f } | |	 k rdt d   n  |	 j |  |  j | | | d | \ } } q |  j d k	 r|  j |   } n  | r| | f S| S(   s  Takes the same arguments as the :class:`EnvironBuilder` class with
        some additions:  You can provide a :class:`EnvironBuilder` or a WSGI
        environment as only argument instead of the :class:`EnvironBuilder`
        arguments and two optional keyword arguments (`as_tuple`, `buffered`)
        that change the type of the return value or the way the application is
        executed.

        .. versionchanged:: 0.5
           If a dict is provided as file in the dict for the `data` parameter
           the content type has to be called `content_type` now instead of
           `mimetype`.  This change was made for consistency with
           :class:`werkzeug.FileWrapper`.

            The `follow_redirects` parameter was added to :func:`open`.

        Additional parameters:

        :param as_tuple: Returns a tuple in the form ``(environ, result)``
        :param buffered: Set this to True to buffer the application run.
                         This will automatically close the application for
                         you as well.
        :param follow_redirects: Set this to True if the `Client` should
                                 follow HTTP redirects.
        R   R   t   follow_redirectsi   i    Ni-  i.  i/  i1  i3  i   t   locations   loop detected(   i-  i.  i/  i1  i3  (   R   R6   R5   R#   R7   Rl   R   R   R   R   R<   Rp   R   RS   R   R   (   RP   Ru   t   kwargsR   R   R   Rb   t   builderR   t   redirect_chaint   status_codeR   t   new_redirect_entry(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR     sB     
c         O   s   d | d <|  j  | |   S(   s(   Like open but method is enforced to GET.Rn   Rv   (   R   (   RP   Ru   t   kw(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR     s    
c         O   s   d | d <|  j  | |   S(   s*   Like open but method is enforced to PATCH.R   Rv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   patch  s    
c         O   s   d | d <|  j  | |   S(   s)   Like open but method is enforced to POST.R   Rv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   post  s    
c         O   s   d | d <|  j  | |   S(   s)   Like open but method is enforced to HEAD.t   HEADRv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   head  s    
c         O   s   d | d <|  j  | |   S(   s(   Like open but method is enforced to PUT.R   Rv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   put  s    
c         O   s   d | d <|  j  | |   S(   s+   Like open but method is enforced to DELETE.t   DELETERv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   delete  s    
c         O   s   d | d <|  j  | |   S(   s,   Like open but method is enforced to OPTIONS.t   OPTIONSRv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   options  s    
c         O   s   d | d <|  j  | |   S(   s*   Like open but method is enforced to TRACE.t   TRACERv   (   R   (   RP   Ru   R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   trace  s    
c         C   s   d |  j  j |  j f S(   Ns   <%s %r>(   R   RZ   R   (   RP   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   __repr__  s    	N(   RZ   R[   R\   R5   R%   R6   RQ   R   R   R   R   R   R   R  R	  R  R  R  R  R  R  (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR   W  s&   			@								c          O   s/   t  |  |   } z | j   SWd | j   Xd S(   s  Create a new WSGI environ dict based on the values passed.  The first
    parameter should be the path of the request which defaults to '/'.  The
    second one can either be an absolute path (in that case the host is
    localhost:80) or a full path to the request with scheme, netloc port and
    the path to the script.

    This accepts the same arguments as the :class:`EnvironBuilder`
    constructor.

    .. versionchanged:: 0.5
       This function is now a thin wrapper over :class:`EnvironBuilder` which
       was added in 0.5.  The `headers`, `environ_base`, `environ_overrides`
       and `charset` parameters were added.
    N(   Rl   R   R   (   Ru   R  R  (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR   &  s    c            s  t  |  } g   g    d    f d  } |  | |  } | r t | d d  } z t |  } Wd | d k	 r} |   n  Xnh x  s   j t |   q W  r t | d d  } t   |  } | d k	 r t | |  } q n  |  d t  d  f S(   s  Return a tuple in the form (app_iter, status, headers) of the
    application output.  This works best if you pass it an application that
    returns an iterator all the time.

    Sometimes applications may use the `write()` callable returned
    by the `start_response` function.  This tries to resolve such edge
    cases automatically.  But if you don't get the expected output you
    should set `buffered` to `True` which enforces buffering.

    If passed an invalid WSGI application the behavior of this function is
    undefined.  Never pass non-conforming WSGI applications to this function.

    :param app: the application to execute.
    :param buffered: set to `True` to enforce buffering.
    :return: tuple in the form ``(app_iter, status, headers)``
    c            s-   | d  k	 r t |   n  |  | g  (  j S(   N(   R5   R   RS   (   t   statusRO   t   exc_info(   t   bufferR   (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   start_responseQ  s    R   Ni    i   (	   R   R5   R8   Ri   RS   t   nextR   R   R    (   t   appRb   R   R  t   app_itert
   close_func(    (   R  R   sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyR   <  s&    	(F   R\   Rw   R9   R    R   t	   itertoolsR   t   tempfileR   t   ioR   t   urllib2R   Rg   t   ImportErrort   urllib.requestt   http.cookiejarR   t	   cookielibt   werkzeug._compatR   R   R	   R
   R   R   R   R   R   t   werkzeug._internalR   R   t   werkzeug.wrappersR   t   werkzeug.urlsR   R   R   R   R   R   t   werkzeug.wsgiR   R   R   t   werkzeug.utilsR   t   werkzeug.datastructuresR   R   R   R    R!   R%   R5   RF   RG   RM   t   objectRN   R]   R_   Rk   Rl   R   R   R   R   R6   R   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/test.pyt   <module>
   sH   @.(
H		 	