ó
`¾Tc           @   s   d  Z  d d l m Z d d l m Z m Z d d l m Z y d d l m	 Z	 Wn! e
 k
 rs d d l m Z	 n Xd d d „ Z d	 e f d
 „  ƒ  YZ d S(   sþ   
    flask.testing
    ~~~~~~~~~~~~~

    Implements test support helpers.  This module is lazily imported
    and usually not used in production environments.

    :copyright: (c) 2011 by Armin Ronacher.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿ(   t   contextmanager(   t   Clientt   EnvironBuilder(   t   _request_ctx_stack(   t	   url_parse(   t   urlsplitt   /c         O   sœ   |  j  j d ƒ } |  j  j d ƒ } | d k r‰ t | ƒ } d | j pQ | pQ d } | rq | | j d ƒ 7} n  | j r‰ | j } q‰ n  t | | | | Ž S(   sD   Creates a new test builder with some application defaults thrown in.t   SERVER_NAMEt   APPLICATION_ROOTs
   http://%s/t	   localhostR   N(   t   configt   gett   NoneR   t   netloct   lstript   pathR   (   t   appR   t   base_urlt   argst   kwargst	   http_hostt   app_roott   url(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyt   make_test_environ_builder   s    	t   FlaskClientc           B   s>   e  Z d  Z e Z e d „  ƒ Z d „  Z d „  Z d „  Z	 RS(   sk  Works like a regular Werkzeug test client but has some knowledge about
    how Flask works to defer the cleanup of the request context stack to the
    end of a with body when used in a with statement.  For general information
    about how to use this class refer to :class:`werkzeug.test.Client`.

    Basic usage is outlined in the :ref:`testing` chapter.
    c   
      o   s!  |  j  d k r t d ƒ ‚ n  |  j } | j d i  ƒ } |  j  j | ƒ t j } | j | | Ž  · } | j	 | j
 ƒ } | d k r” t d ƒ ‚ n  t j | ƒ z	 | VWd t j ƒ  X| j ƒ  } | j j | ƒ sé | j | | ƒ n  | j | j
 j ƒ }	 |  j  j | j
 j |	 ƒ Wd QXd S(   s~  When used in combination with a with statement this opens a
        session transaction.  This can be used to modify the session that
        the test client uses.  Once the with block is left the session is
        stored back.

            with client.session_transaction() as session:
                session['value'] = 42

        Internally this is implemented by going through a temporary test
        request context and since session handling could depend on
        request variables this function accepts the same arguments as
        :meth:`~flask.Flask.test_request_context` which are directly
        passed through.
        s:   Session transactions only make sense with cookies enabled.t   environ_overridess?   Session backend did not open a session. Check the configurationN(   t
   cookie_jarR   t   RuntimeErrort   applicationt
   setdefaultt   inject_wsgiR   t   topt   test_request_contextt   open_sessiont   requestt   pusht   popt   response_classt   session_interfacet   is_null_sessiont   save_sessiont   get_wsgi_headerst   environt   extract_wsgi(
   t   selfR   R   R   R   t   outer_reqctxt   ct   sesst   respt   headers(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyt   session_transaction0   s&    		
	c      	   O   s†   |  j  | j d i  ƒ d <| j d t ƒ } | j d t ƒ } | j d t ƒ } t |  j | | Ž } t j |  | d | d | d | ƒS(   NR   s   flask._preserve_contextt   as_tuplet   bufferedt   follow_redirects(   t   preserve_contextR   R$   t   FalseR   R   R   t   open(   R,   R   R   R3   R4   R5   t   builder(    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyR8   `   s    c         C   s%   |  j  r t d ƒ ‚ n  t |  _  |  S(   Ns   Cannot nest client invocations(   R6   R   t   True(   R,   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyt	   __enter__n   s    		c         C   s8   t  |  _ t j } | d  k	 r4 | j r4 | j ƒ  n  d  S(   N(   R7   R6   R   R   R   t	   preservedR$   (   R,   t   exc_typet	   exc_valuet   tbR   (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyt   __exit__t   s    		(
   t   __name__t
   __module__t   __doc__R7   R6   R    R2   R8   R;   R@   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyR   %   s   0		N(   RC   t
   contextlibR    t   werkzeug.testR   R   t   flaskR   t   werkzeug.urlsR   t   ImportErrort   urlparseR   R   R   R   (    (    (    sS   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/flask/testing.pyt   <module>   s   