
2ec           @  s  d  Z  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
 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 d   Z d e f d     YZ d   Z  d e f d     YZ! d e" f d     YZ# d e f d     YZ$ d e f d     YZ% d e f d     YZ& d e f d     YZ' d e f d     YZ( e j) d e j*  Z+ d   Z, d e f d      YZ- d! e- f d"     YZ. e. e- j/ d# <d$ e. f d%     YZ0 e0 e- j/ d& <d' e- f d(     YZ1 e1 e- j/ d) <d* e- f d+     YZ2 e2 e- j/ d, <d- e2 f d.     YZ3 e3 e- j/ d/ <d0 e2 f d1     YZ4 e4 e- j/ d2 <d3 e- f d4     YZ5 e5 e- j/ d5 <e5 e- j/ d6 <e5 e- j/ d7 <d8 e f d9     YZ6 d: e f d;     YZ7 d< e f d=     YZ8 d> e f d?     YZ9 e: d@  Z; e: e: e< dA  Z= dB   Z> e: dC  Z? dD   Z@ d S(E   s  
Routines for testing WSGI applications.

Most interesting is the `TestApp <class-paste.fixture.TestApp.html>`_
for testing WSGI applications, and the `TestFileEnvironment
<class-paste.fixture.TestFileEnvironment.html>`_ class for testing the
effects of command-line scripts.
i(   t   print_functionN(   t	   cStringIO(   t	   urlencode(   t   parse(   t
   BaseCookie(   t   wsgilib(   t   lint(   t
   HeaderDictc          G  s   t  j |    S(   s   
    An os.tempnam with the warning turned off, because sometimes
    you just need to use this and don't care about the stupid
    security warning.
    (   t   ost   tempnam(   t   args(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   tempnam_no_warning"   s    t	   NoDefaultc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   *   s   c         C  s   t  |   }  |  j   |  S(   N(   t   listt   sort(   t   l(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   sorted-   s    
t   Dummy_smtplibc           B  sG   e  Z d Z d    Z d   Z d   Z d   Z e e  Z d   Z	 RS(   c         C  sW   d d  l  } | j d t d  |  j s5 t d   | |  _ t |  _ |  |  j _ d  S(   Nis1   Dummy_smtplib is not maintained and is deprecatedi   sI   smtplib.SMTP() called again before Dummy_smtplib.existing.reset() called.(	   t   warningst   warnt   DeprecationWarningt   existingt   AssertionErrort   servert   Truet   opent	   __class__(   t   selfR   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __init__6   s    
			c         C  s&   |  j  s t d |    t |  _  d  S(   Ns   Called %s.quit() twice(   R   R   t   False(   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   quitB   s    c         C  s   | |  _  | |  _ | |  _ d  S(   N(   t   from_addresst   to_addressest   message(   R   R!   R"   t   msg(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   sendmailG   s    		c         C  s   |  t  _ d  S(   N(   t   smtplibt   SMTP(   t   cls(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   installL   s    c         C  s&   |  j  s t d   d  |  j _ d  S(   Ns   SMTP connection not quit(   R   R   t   NoneR   R   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   resetQ   s    	N(
   R   R   R*   R   R   R    R%   R)   t   classmethodR+   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   2   s   				t   AppErrorc           B  s   e  Z RS(    (   R   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR-   W   s   t   TestAppc           B  s  e  Z e Z d d d d d d   Z d   Z d   Z d d d d e d  Z d d d d d e d  Z	 d d d d d e d  Z
 d d d d d e d  Z d d d d e d  Z d d d e d	  Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C  s   t  | t j t j f  r@ d d l m } | | d | } n  | |  _ | |  _ | |  _ | d k rp i  } n  | |  _
 | |  _ | |  _ |  j   d S(   s}  
        Wraps a WSGI application in a more convenient interface for
        testing.

        ``app`` may be an application, or a Paste Deploy app
        URI, like ``'config:filename.ini#test'``.

        ``namespace`` is a dictionary that will be written to (if
        provided).  This can be used with doctest or some other
        system, and the variable ``res`` will be assigned everytime
        you make a request (instead of returning the request).

        ``relative_to`` is a directory, and filenames used for file
        uploads are calculated relative to this.  Also ``config:``
        URIs that aren't absolute.

        ``extra_environ`` is a dictionary of values that should go
        into the environment for each request.  These can provide a
        communication channel with the application.

        ``pre_request_hook`` is a function to be called prior to
        making requests (such as ``post`` or ``get``). This function
        must take one argument (the instance of the TestApp).

        ``post_request_hook`` is a function, similar to
        ``pre_request_hook``, to be called after requests are made.
        i(   t   loadappt   relative_toN(   t
   isinstancet   sixt   binary_typet	   text_typet   paste.deployR/   t   appt	   namespaceR0   R*   t   extra_environt   pre_request_hookt   post_request_hookR+   (   R   R6   R7   R0   R8   R9   R:   R/   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   _   s    							c         C  s   i  |  _  d S(   sc   
        Resets the state of the application; currently just clears
        saved cookies.
        N(   t   cookies(   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR+      s    c         C  s   |  j  j   } t | d <| S(   Ns   paste.throw_errors(   R8   t   copyR   (   R   t   environ(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   _make_environ   s    
c   
      C  s  | d k r i  } n  t } | r t | t j t j f  sQ t | d t } n  d | k rj | d 7} n
 | d 7} | | 7} n  |  j   } t |  } d | k r | j	 d d  \ } | d <n
 d | d <|  j
 | |  | j |  t | | |  }	 |  j |	 d | S(	   s  
        Get the given url (well, actually a path like
        ``'/page.html'``).

        ``params``:
            A query string, or a dictionary that will be encoded
            into a query string.  You may also include a query
            string on the ``url``.

        ``headers``:
            A dictionary of extra headers to send.

        ``extra_environ``:
            A dictionary of environmental variables that should
            be added to the request.

        ``status``:
            The integer status code you expect (if not 200 or 3xx).
            If you expect a 404 response, for instance, you must give
            ``status=404`` or it will be an error.  You can also give
            a wildcard, like ``'3*'`` or ``'*'``.

        ``expect_errors``:
            If this is not true, then if anything is written to
            ``wsgi.errors`` it will be an error.  If it is true, then
            non-200/3xx responses are also okay.

        Returns a `response object
        <class-paste.fixture.TestResponse.html>`_
        t   doseqt   ?t   &i   t   QUERY_STRINGt    t   statusN(   R*   R   R1   R2   R3   R4   R   R>   t   strt   splitt   _set_headerst   updatet   TestRequestt
   do_request(
   R   t   urlt   paramst   headersR8   RD   t   expect_errorst   __tracebackhide__R=   t   req(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   get   s&     	

RC   c	         C  s  | d k r i  } n  | d k r* i  } n  |  j   }	 t | t t t f  r] t |  } n  t | d  r t | j    } n  t	 j
 r t | t	 j  r | j d  } n  | r t j | d t } |  j | |  \ }
 } |
 |	 d <n | r|	 j d d  n  t |  } d | k r>| j d d  \ } |	 d <n
 d	 |	 d <t t |   |	 d
 <| |	 d <t	 j |  |	 d <|  j | |	  |	 j |  t | |	 |  } |  j | d | S(   s'   
        Do a generic request.
        t   itemst   utf8t   keep_blank_valuest   CONTENT_TYPEs!   application/x-www-form-urlencodedR@   i   RB   RC   t   CONTENT_LENGTHt   REQUEST_METHODs
   wsgi.inputRD   N(   R*   R>   R1   R   t   tuplet   dictR   t   hasattrRR   R2   t   PY3R4   t   encodet   urlparset	   parse_qslR   t   encode_multipartt
   setdefaultRE   RF   t   lent   BytesIORG   RH   RI   RJ   (   R   t   methodRK   RL   RM   R8   RD   t   upload_filesRN   R=   t   content_typeRP   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   _gen_request   s:    		

c         C  s4   |  j  d | d | d | d | d | d | d | S(   s  
        Do a POST request.  Very like the ``.get()`` method.
        ``params`` are put in the body of the request.

        ``upload_files`` is for file uploads.  It should be a list of
        ``[(fieldname, filename, file_content)]``.  You can also use
        just ``[(fieldname, filename)]`` and the file content will be
        read from disk.

        Returns a `response object
        <class-paste.fixture.TestResponse.html>`_
        t   POSTRL   RM   R8   RD   Rd   RN   (   Rf   (   R   RK   RL   RM   R8   RD   Rd   RN   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   post   s    c         C  s4   |  j  d | d | d | d | d | d | d | S(   s  
        Do a PUT request.  Very like the ``.get()`` method.
        ``params`` are put in the body of the request.

        ``upload_files`` is for file uploads.  It should be a list of
        ``[(fieldname, filename, file_content)]``.  You can also use
        just ``[(fieldname, filename)]`` and the file content will be
        read from disk.

        Returns a `response object
        <class-paste.fixture.TestResponse.html>`_
        t   PUTRL   RM   R8   RD   Rd   RN   (   Rf   (   R   RK   RL   RM   R8   RD   Rd   RN   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   put  s    c         C  s4   |  j  d | d | d | d | d | d d d | S(	   s   
        Do a DELETE request.  Very like the ``.get()`` method.
        ``params`` are put in the body of the request.

        Returns a `response object
        <class-paste.fixture.TestResponse.html>`_
        t   DELETERL   RM   R8   RD   Rd   RN   N(   Rf   R*   (   R   RK   RL   RM   R8   RD   RN   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   delete  s    	c         C  s.   |  j  d | d | d | d | d d d | S(   s   
        Do a HEAD request.  Very like the ``.get()`` method.

        Returns a `response object
        <class-paste.fixture.TestResponse.html>`_
        t   HEADRM   R8   RD   Rd   RN   N(   Rf   R*   (   R   RK   RM   R8   RD   RN   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   head'  s    c         C  s   | s
 d Sxv | j    D]h \ } } | j   d k r> d } n7 | j   d k rY d } n d | j d d  j   } | | | <q Wd S(	   s9   
        Turn any headers into environ variables
        Ns   content-typeRU   s   content-lengthRV   s   HTTP_%st   -t   _(   RR   t   lowert   replacet   upper(   R   RM   R=   t   headert   valuet   var(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRG   6  s    		c         C  s  d t  j    } d | } t j r5 | j d  } n  g  } xn | D]f \ } } | j d |  d t j |  } | j |  | j d  t j |  } | j |  qB Wx | D] }	 |  j |	  \ } }
 } | j d |  d t j |  t j |
  f } | j |  t j t j	 |
 d d   d	 } d
 | rK| j d  n d } | j |  | j d  | j |  q W| j d | d  | j d  d j
 |  } | | f S(   s   
        Encodes a set of parameters (typically a name/value list) and
        a set of files (a list of (name, filename, file_body)) into a
        typical POST body, returning the (content_type, body).
        s   ----------a_BoUnDaRy%s$s    multipart/form-data; boundary=%st   asciis   --s)   Content-Disposition: form-data; name="%s"RC   s8   Content-Disposition: form-data; name="%s"; filename="%s"t   ignorei    s   Content-Type: %ss   application/octet-streams   
(   t   randomR2   R[   R\   t   appendt   ensure_binaryt   _get_file_infot	   mimetypest
   guess_typet
   ensure_strt   join(   R   RL   t   filest   boundaryRe   t   linest   keyRu   t   linet	   file_infot   filenamet   fcontentt   body(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR_   E  s8    
	"c         C  s   t  |  d k rv | d } |  j r@ t j j |  j |  } n  t | d  } | j   } | j   | d | | f St  |  d k r | St d t	 |  d    d  S(   Ni   i   t   rbi    i   su   upload_files need to be a list of tuples of (fieldname, filename, filecontent) or (fieldname, filename); you gave: %rid   (
   Ra   R0   R   t   pathR   R   t   readt   closet
   ValueErrort   repr(   R   R   R   t   ft   content(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR|   i  s    
	
c         C  s  |  j  r |  j  |   n  t } |  j r t   } x' |  j j   D] \ } } | | | <qA Wd j g  | j   D]! } d j | j | j g  ^ qn  } | | j	 d <n  t | j	 d <i  | j	 d <t
 j |  j  }	 t j }
 t |
  } zP | t _ t j   } | j } t j |	 | j d | | j	 } t j   } Wd |
 t _ t j j | j    X|  j | | |  } | | _ xS | j	 d j   D]> \ } } t | |  rt d |   n  t | | |  qW|  j d k	 r| |  j d	 <n  | j s|  j | |  |  j  |  n  i  | _! x` | j" d
  D]O } t |  } x: | j   D], \ } } | j |  j | <| j | j! | <qQWq2W|  j# r|  j# |   n  |  j d k r| Sd S(   s   
        Executes the given request (``req``), with the expected
        ``status``.  Generally ``.get()`` and ``.post()`` are used
        instead.
        s   ; t   =t   HTTP_COOKIEs   paste.testings   paste.testing_variablest   raise_on_wsgi_errorNso   paste.testing_variables contains the variable %r, but the response object already has an attribute by that namet   ress
   set-cookie($   R9   R   R;   R   RR   R   t   valuesR   Ru   R=   R   t
   middlewareR6   t   syst   stdoutt   CaptureStdoutt   timeRN   R   t   raw_interactiveRK   t   stderrt   writet   getvaluet   _make_responset   requestRZ   R   t   setattrR7   R*   t   _check_statust   _check_errorst   cookies_sett   all_headersR:   (   R   RP   RD   RO   t   ct   nameRu   t   mt   hcR6   t
   old_stdoutt   outt
   start_timeR   t   raw_rest   end_timeR   Rt   R   t   morsel(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRJ   |  s`    			=		
		 			c         C  s$  t  } | d k r d  St | t t f  r{ | j | k rw t d | j d j t t	 |   | j
 j | j f   n  d  S| d  k r | j d k r | j d k  r d  S| j } t j r | j d d  } n  t d | j | j
 j | f   n  | | j k r t d	 | j | f   n  d  S(
   Nt   *s*   Bad response: %s (not one of %s for %s)
%ss   , i   i  RS   t   xmlcharrefreplaces7   Bad response: %s (not 200 OK or 3xx redirect for %s)
%ss   Bad response: %s (not %s)(   R   R1   R   RX   RD   R-   t   full_statusR   t   mapRE   R   RK   R   R*   R2   R[   t   decode(   R   RD   R   RO   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s.    		c         C  s#   | j  r t d | j    n  d  S(   Ns!   Application had errors logged:
%s(   t   errorsR-   (   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    	c         C  s+   | \ } } } } t  |  | | | | |  S(   N(   t   TestResponse(   R   t   respt
   total_timeRD   RM   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    N(   R   R   R   t   __test__R*   R   R+   R>   RQ   Rf   Rh   Rj   Rl   Rn   RG   R_   R|   RJ   R   R   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR.   [   s2   +			5	%					$		<		R   c           B  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C  s   t    |  _ | |  _ d  S(   N(   t   StringIOt   capturedt   actual(   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    c         C  s$   |  j  j |  |  j j |  d  S(   N(   R   R   R   (   R   t   s(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    c         C  s   |  j  j   d  S(   N(   R   t   flush(   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    c         C  s"   x | D] } |  j  |  q Wd  S(   N(   R   (   R   R   t   item(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt
   writelines  s    c         C  s   |  j  j   S(   N(   R   R   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    (   R   R   R   R   R   R   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s
   				R   c           B  s2  e  Z e Z d    Z d   Z e e d d Z d   Z e e d d Z	 e
 j d e
 j e
 j B Z d   Z e d  Z d	   Z d
   Z d d d d d e d  Z d d d d d e d  Z d   Z d d  Z e
 j d  Z d   Z e e d d Z d   Z d   Z d   Z d   Z d   Z  RS(   c         C  sz   | |  _  t | j   d  |  _ | |  _ | |  _ t j |  j  |  _ | |  _	 | |  _
 d  |  _ | |  _ d  |  _ d  S(   Ni    (   t   test_appt   intRF   RD   R   RM   R   t   fromlistt   header_dictR   R   R*   t   _normal_bodyR   t   _forms_indexed(   R   R   RD   RM   R   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    							c         C  s#   |  j  d k r |  j   n  |  j  S(   s   
        Returns a dictionary of ``Form`` objects.  Indexes are both in
        order (from zero) and by form id (if the form is given an id).
        N(   R   R*   t   _parse_forms(   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt
   forms__get  s    t   docs   
                     A list of <form>s found on the page (instances of
                     `Form <class-paste.fixture.Form.html>`_)
                     c         C  sA   |  j  } | s t d   n  d | k r9 t d   n  | d S(   Ns*   You used response.form, but no forms existi   s5   You used response.form, but more than one form existsi    (   t   formst	   TypeError(   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt	   form__get  s    	s   
                    Returns a single `Form
                    <class-paste.fixture.Form.html>`_ instance; it
                    is an error if there are multiple forms on the
                    page.
                    s   <(/?)([:a-z0-9_\-]*)(.*?)>c         C  su  i  } |  _  g  } d  } |  j } t j s@ | j d d  } n  x |  j j |  D] } | j d  d k } | j d  j	   } | d k r qS n  | r | s t
 d | j     | j | | | j   ! d  } qS | s t
 d | j     | j   } qS W| s"t
 d	 | |   xL t |  D]> \ } }	 t |  |	  }
 |
 | | <|
 j r/|
 | |
 j <q/q/Wd  S(
   NRS   R   i   t   /i   t   forms   </form> unexpected at %ss   Nested form tags at %ss   Dangling form: %r(   R   R*   R   R2   t   PY2R   t   _tag_ret   finditert   groupRq   R   t   startRz   t   endt	   enumeratet   Formt   id(   R   R   t
   form_textst   startedR   t   matchR   t   tagt   it   textR   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   *  s4    				


	c         C  s   d } xX |  j D]M \ } } | j   | j   k r | sT t d | | | f   | } q q W| d k r | t k r t d | d j g  |  j D] \ } } | ^ q  f   q | Sn  | S(   s   
        Returns the named header; an error if there is not exactly one
        matching header (unless you give a default -- always an error
        if there is more than one header)
        s&   Ambiguous header: %s matches %r and %rs   No header found: %r (from %s)s   , N(   R*   RM   Rq   R   R   t   KeyErrorR   (   R   R   t   defaultt   foundt   cur_nameRu   t   nt   v(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRt   G  s    
8c         C  sL   g  } x? |  j  D]4 \ } } | j   | j   k r | j |  q q W| S(   sE   
        Gets all headers by the ``name``, returns as a list
        (   RM   Rq   Rz   (   R   R   R   R   Ru   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   ]  s
    c         K  sS   |  j  d k r |  j  d k  s1 t d |  j   |  j d  } |  j j | |  S(   s   
        If this request is a redirect, follow that redirect.  It
        is an error if this is not a redirect response.  Returns
        another response object.
        i,  i  s/   You can only follow redirect responses (not %s)t   location(   RD   R   R   Rt   R   RQ   (   R   t   kwR   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   followg  s
    !c         C  sb   t  } |  j d d d d d d d | d | d | d	 | d
 | d |  	\ } }	 }
 |  j |
 d  S(   s  
        Click the link as described.  Each of ``description``,
        ``linkid``, and ``url`` are *patterns*, meaning that they are
        either strings (regular expressions), compiled regular
        expressions (objects with a ``search`` method), or callables
        returning true or false.

        All the given patterns are ANDed together:

        * ``description`` is a pattern that matches the contents of the
          anchor (HTML and all -- everything between ``<a...>`` and
          ``</a>``)

        * ``linkid`` is a pattern that matches the ``id`` attribute of
          the anchor.  It will receive the empty string if no id is
          given.

        * ``href`` is a pattern that matches the ``href`` of the anchor;
          the literal content of that attribute, not the fully qualified
          attribute.

        * ``anchor`` is a pattern that matches the entire anchor, with
          its contents.

        If more than one link matches, then the ``index`` link is
        followed.  If ``index`` is not given and more than one link
        matches, or if no link matches, then ``IndexError`` will be
        raised.

        If you give ``verbose`` then messages will be printed about
        each link, and why it does or doesn't match.  If you use
        ``app.click(verbose=True)`` you'll see a list of all the
        links.

        You can use multiple criteria to essentially assert multiple
        aspects about the link, e.g., where the link's destination is.
        R   t   at	   href_attrt   hreft   href_extractR   R   t   href_patternt   html_patternt   indext   verboset   uriN(   R   t   _find_elementR*   t   goto(   R   t   descriptiont   linkidR   t   anchorR   R   RO   t
   found_htmlt
   found_desct   found_attrs(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   clickt  s    '	c         C  sk   t  } |  j d d d d d t j d  d | d | d	 | d
 | d | d |  	\ } }	 }
 |  j |
 d  S(   s   
        Like ``.click()``, except looks for link-like buttons.
        This kind of button should look like
        ``<button onclick="...location.href='url'...">``.
        R   t   buttonR   t   onclickR   s   location\.href='(.*?)'R   R   R   R   R   R   R   (   R   R   t   ret   compileR   (   R   R   t   buttonidR   R   R   R   RO   R   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   clickbutton  s    	c
           s  t  |  }
 t  |  } t  |  } t  |  } t j d | | f t j t j  }   f d   } g  } d } x| j |  j  D]} | j d  } | j d  } | j d  } t |  }   r | d |  n  | j	 |  s | d |  q n  | | } | rD| j
 |  } | s2| d  q n  | j d  } n  | | d	 <| j d
  rm| d  q n  | j d  r| d  q n  | d 7} |
 r|
 |  r| d  q n  | r| | j	 d d   r| d  q n  | r| |  r| d  q n  | r.| |  r.| d  q n  | d  | j | | | f  q W| skt d |   n  | d  k rt |  d k rt d d j g  | D] \ } } } t |  ^ q   n  | d } nA y | | } Wn0 t k
 rt d t |  | | f   n X| S(   Ns   <%s\s+(.*?)>(.*?)</%s>c           s     r t  |   n  d  S(   N(   t   print(   R   (   R   (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   printlog  s    i    i   i   s   Element: %rs     Skipped: no %s attributes(     Skipped: doesn't match extract patternR   t   #s&     Skipped: only internal fragment hrefs   javascript:s$     Skipped: cannot follow javascript:s$     Skipped: doesn't match descriptionR   RC   s     Skipped: doesn't match ids     Skipped: doesn't match hrefs     Skipped: doesn't match htmls
     Accepteds-   No matching elements found (from %s possible)s   Multiple links match: %ss   , s6   Only %s (out of %s) links match; index %s out of range(   t   _make_patternR   R   t   It   SR   R   R   t   _parse_attrsRQ   t   searcht
   startswithRz   t
   IndexErrorR*   Ra   R   R   (   R   R   R   R   R   R   R   R   R   R   t   content_patt   id_patt   href_patt   html_patR   R  t   found_linkst   total_linksR   t   el_htmlt   el_attrt
   el_contentt   attrst   el_hrefR   t   anct   dt   attrt
   found_link(    (   R   s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    










8RQ   c   	      K  s   t  j |  \ } } } } } d } } } t  j | | | | | f  } t  j |  j j |  } | j   } | d k s t d |   | d k r |  j j	 } n |  j j
 } | | |  S(   s  
        Go to the (potentially relative) link ``href``, using the
        given method (``'get'`` or ``'post'``) and any extra arguments
        you want to pass to the ``app.get()`` or ``app.post()``
        methods.

        All hostnames and schemes will be ignored.
        RC   RQ   Rh   s9   Only "get" or "post" are allowed for method (you gave %r)(   RQ   Rh   (   R]   t   urlsplitt
   urlunsplitt   urljoinR   t   full_urlRq   R   R   RQ   Rh   (	   R   R   Rc   R
   t   schemet   hostR   t   queryt   fragment(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    	
s
   [ \n\r\t]+c         C  s4   |  j  d  k r- |  j j d |  j  |  _  n  |  j  S(   Nt    (   R   R*   t   _normal_body_regext   subR   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   normal_body__get  s    	s]   
                           Return the whitespace-normalized body
                           c         C  s|   t  | t j t j f  s* t |  } n  t  | t j  rN | j d  } n  |  j j |  d k p{ |  j j |  d k S(   s   
        A response 'contains' a string if it is present in the body
        of the response.  Whitespace is normalized when searching
        for a string.
        RS   i(	   R1   R2   R3   R4   RE   R\   R   t   findt   normal_body(   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __contains__*  s    c         O  s  d | k rG | d } | d =t  | t j t j f  rM | g } qM n g  } | rb t d   n  xW | D]O } | |  k ri t d | d t j t |  d t j t d |   qi qi WxW | D]O } | |  k r t d | d t j t |  d t j t d |   q q Wd S(	   s   
        Assert that the response contains all of the strings passed
        in as arguments.

        Equivalent to::

            assert string in res
        t   nos)   The only keyword argument allowed is 'no's   Actual response (no %r):t   files   Body does not contain string %rs   Actual response (has %r)s   Body contains string %rN(	   R1   R2   R3   R4   R   R   R   R   R	  (   R   t   stringsR   R(  R   t   no_s(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   mustcontain8  s*    	
c         C  sB   |  j  } t j r' | j d d  } n  | d  } d |  j | f S(   NRS   R   i   s   <Response %s %r>(   R   R2   R[   R   R   (   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __repr__X  s
    		
c         C  s   d j  g  |  j j   D] } | j   r | ^ q  } t j rU | j d d  } n  d |  j d j  g  |  j D] \ } } d | | f ^ qn  | f S(   Ns   
RS   R   s   Response: %s
%s
%ss   %s: %s(	   R   R   t
   splitlinest   stripR2   R[   R   RD   RM   (   R   R   t   simple_bodyR   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __str___  s    	2c         C  sr   d d l  } t d d  d } t | d  } | j |  j  | j   d | j t j	 d  } | j
 |  d S(   s{   
        Show this response in a browser window (for debugging purposes,
        when it's hard to read the HTML).
        iNs   paste-fixtures   .htmlt   wbs   file:R   (   t
   webbrowserR   R*   R   R   R   R   Rr   R   t   sept   open_new(   R   R3  t   fnR   RK   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   showbrowseri  s    
N(!   R   R   R   R   R   R   t   propertyR   R   R   R   R   R  R  R   R   R   Rt   R   R   R*   R   R   R   R   R"  R$  R&  R'  R,  R-  R1  R7  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s8   										
		1		M					 		
RI   c           B  s   e  Z e Z e d   Z RS(   c         C  sq   | j  d  r" | t d  } n  | |  _ | |  _ | j d  r[ | d | d |  _ n	 | |  _ | |  _ d  S(   Ns   http://localhostRB   R@   (   R  Ra   RK   R=   RQ   R  RN   (   R   RK   R=   RN   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    			(   R   R   R   R   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRI   w  s   R   c           B  s   e  Z d  Z e j d e j  Z d   Z d   Z d   Z	 d   Z
 d   Z d d  Z d e d  Z d d	  Z d d d
  Z d d d  Z RS(   s  
    This object represents a form that has been found in a page.
    This has a couple useful attributes:

    ``text``:
        the full HTML of the form.

    ``action``:
        the relative URI of the action.

    ``method``:
        the method (e.g., ``'GET'``).

    ``id``:
        the id, or None if not given.

    ``fields``:
        a dictionary of fields, each value is a list of fields by
        that name.  ``<input type="radio">`` and ``<select>`` are
        both represented as single fields with multiple options.
    s   <(/?)([:a-z0-9_\-]*)([^>]*?)>c         C  s*   | |  _  | |  _ |  j   |  j   d  S(   N(   t   responseR   t   _parse_fieldst   _parse_action(   R   R9  R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    		
c         C  sP  d  } d  } i  } |  j } x%|  j j |  D]} | j d  d k } | j d  j   } | d k rp q. n  | d k r | r | s t d	 | j d
    d  } q. n  | d k r| r| s t d | j     t |  j | d | j   ! | d
 _	 d  } q. n  | rq. n  t
 | j d   } d | k rM| j d  }	 n d  }	 | d k r| j j | j d  d | k f  q. n  | d k rD| j d  d k rD| j |	  }
 |
 st |  | |	 | j   |  }
 | j |	 g   j |
  n |
 d
 }
 t |
 t  st  |
 j j | j d  d | k f  q. n  | } | d k rq| j d d  j   } n  t j j | t  } | |  | |	 | j   |  }
 | d k r| st d | | j d
  f   |
 | j   f } n; | d k r&| st d | | j d
  f   |
 } n  | j |	 g   j |
  q. W| |  _ d  S(   Ni   R   i   t   inputt   selectt   optiont   textareaR   s   %r without starting selecti    s$   </textarea> with no <textarea> at %si   R   Ru   t   selectedt   typet   radiot   checkedR   s   Nested textareas: %r and %rs   Nested selects: %r and %r(   R<  R=  R>  R?  R   (   R*   R   R   R   R   Rq   R   R   t   html_unquoteRu   R  t   popt   optionsRz   RQ   t   RadioR`   R1   t   Fieldt   classesR   t   fields(   R   t	   in_selectt   in_textareaRJ  R   R   R   R   R  R   t   fieldt   tag_typet
   FieldClass(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR:    st    				'!


	c         C  s   d  |  _ |  j } x |  j j |  D] } | j d  d k } | j d  j   } | d k rg q% n  | rq Pn  t | j d   } | j d d  |  _ | j d d	  |  _	 | j d
  |  _
 q% Wd s t d   |  j d  k	 s t d   d  S(   Ni   R   i   R   i   t   actionRC   Rc   t   GETR   i    s   No </form> tag founds   No <form> tag found(   R*   RP  R   R   R   R   Rq   R  RQ   Rc   R   R   (   R   R   R   R   R   R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR;    s     		c         C  s   |  j  j |  } | d k	 sO t d | d j t t |  j  j     f   t |  d k s t d | d j t t |   f   | | d _	 d S(   s  
        Set the value of the named field.  If there is 0 or multiple
        fields by that name, it is an error.

        Setting the value of a ``<select>`` selects the given option
        (and confirms it is an option).  Setting radio fields does the
        same.  Checkboxes get boolean values.  You cannot set hidden
        fields or buttons.

        Use ``.set()`` if there is any ambiguity and you must provide
        an index.
        s*   No field by the name %r found (fields: %s)s   , i   s   Multiple fields match %r: %si    N(
   RJ  RQ   R*   R   R   R   R   t   keysRa   Ru   (   R   R   Ru   RJ  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __setitem__  s    +"c         C  sp   |  j  j |  } | d k	 s. t d |   t |  d k sh t d | d j t t |   f   | d S(   sE   
        Get the named field object (ambiguity is an error).
        s   No field by the name %r foundi   s   Multiple fields match %r: %ss   , i    N(   RJ  RQ   R*   R   Ra   R   R   R   (   R   R   RJ  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   __getitem__'  s    "c         C  s^   | d k r | |  | <nA |  j j |  } | d k	 sG t d |   | | } | | _ d S(   sF   
        Set the given name, using ``index`` to disambiguate.
        s   No fields found matching %rN(   R*   RJ  RQ   R   Ru   (   R   R   Ru   R   RJ  RM  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   set3  s    
c         C  s   |  j  j |  } | d k r. | t k	 r. | S| d k rB |  | S|  j  j |  } | d k	 sp t d |   | | } | Sd S(   sb   
        Get the named/indexed field object, or ``default`` if no field
        is found.
        s   No fields found matching %rN(   RJ  RQ   R*   R   R   (   R   R   R   R   RJ  RM  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRQ   @  s    
c         C  s7   |  j  | d | } t | t  s* t  | | _ d S(   s]   
        Like ``.set()``, except also confirms the target is a
        ``<select>``.
        R   N(   RQ   R1   t   SelectR   Ru   (   R   R   Ru   R   RM  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR=  Q  s    c         K  s:   |  j  | d | } |  j j |  j d |  j d | | S(   s	  
        Submits the form.  If ``name`` is given, then also select that
        button (using ``index`` to disambiguate)``.

        Any extra keyword arguments are passed to the ``.get()`` or
        ``.post()`` method.

        Returns a response object.
        R   Rc   RL   (   t   submit_fieldsR9  R   RP  Rc   (   R   R   R   R
   RJ  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   submitZ  s    
c         C  s   g  } | d k	 rF |  j | d | } | j | j | j   f  n  xn |  j j   D]] \ } } | d k rt qV n  x< | D]4 } | j } | d k r q{ n  | j | | f  q{ WqV W| S(   sf   
        Return a list of ``[(name, value), ...]`` for the current
        state of the form.
        R   N(   R*   RQ   Rz   R   t   value_if_submittedRJ  RR   Ru   (   R   R   R   RX  RM  RJ  Ru   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRW  h  s    	N(   R   R   t   __doc__R   R   R  R   R   R:  R;  RS  RT  R*   RU  R   RQ   R=  RX  RW  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s   		>				sH   ([^= \n\r\t]+)[ \n\r\t]*(?:=[ \n\r\t]*(?:"([^"]*)"|([^"][^ \n\r\t>]*)))?c         C  ss   i  } xf t  j |   D]U } | j d  j   } | j d  pL | j d  } t | p[ d  } | | | <q W| S(   Ni   i   i   RC   (   t   _attr_reR   R   Rq   RD  (   R   R  R   t	   attr_namet	   attr_body(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR  ~  s    RH  c           B  sS   e  Z d  Z i  Z e Z d d d  Z d   Z d   Z	 d   Z
 e e
 e  Z RS(   s   
    Field object.
    c         K  sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   R   R   t   post   _valueR   R  (   R   R   R   R   R^  Ru   R   R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    						c         C  s5   |  j  s( t d |  j |  j f   n  | |  _ d  S(   Ns-   You cannot set the value of the <%s> field %r(   t   settablet   AttributeErrorR   R   R_  (   R   Ru   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt
   value__set  s
    	c         C  s   | |  _  d S(   s^   
        Like setting a value, except forces it even for, say, hidden
        fields.
        N(   R_  (   R   Ru   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   force_value  s    c         C  s   |  j  S(   N(   R_  (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt
   value__get  s    N(   R   R   RZ  RI  R   R`  R*   R   Rb  Rc  Rd  R8  Ru   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRH    s   				RV  c           B  s8   e  Z d  Z d   Z d   Z d   Z e e e  Z RS(   s)   
    Field representing ``<select>``
    c         O  sW   t  t |   j | |   g  |  _ | j d  |  _ |  j sJ t d   d  |  _ d  S(   Nt   multiples#   <select multiple> not yet supported(	   t   superRV  R   RF  RQ   Re  R   R*   t   selectedIndex(   R   R
   R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    		c         C  s   x t  |  j  D]1 \ } \ } } | t |  k r | |  _ Pq q Wt d | d j g  |  j D] \ } } t |  ^ q^  f   d  S(   Ns   Option %r not found (from %s)s   , (   R   RF  RE   Rg  R   R   R   (   R   Ru   R   R>  RC  t   oR   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRb    s    "		c         C  se   |  j  d  k	 r! |  j |  j  d Sx= |  j D] \ } } | r+ | Sq+ W|  j r] |  j d d Sd  Sd  S(   Ni    (   Rg  R*   RF  (   R   R>  RC  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRd    s    	(   R   R   RZ  R   Rb  Rd  R8  Ru   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRV    s
   				R=  RG  c           B  s   e  Z d  Z RS(   s5   
    Field representing ``<input type="radio">``
    (   R   R   RZ  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRG    s   RB  t   Checkboxc           B  s8   e  Z d  Z d   Z d   Z d   Z e e e  Z RS(   s8   
    Field representing ``<input type="checkbox">``
    c         O  s,   t  t |   j | |   d | k |  _ d  S(   NRC  (   Rf  Ri  R   RC  (   R   R
   R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s    c         C  s   | |  _  d  S(   N(   RC  (   R   Ru   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRb    s    c         C  s.   |  j  r& |  j d  k r d S|  j Sn d  Sd  S(   Nt   on(   RC  R_  R*   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRd    s
    	
(   R   R   RZ  R   Rb  Rd  R8  Ru   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRi    s
   				t   checkboxt   Textc           B  s   e  Z d  Z d d d  Z RS(   s4   
    Field representing ``<input type="text">``
    RC   c         K  s,   t  j |  | | | | d | d | | d  S(   NRu   R   (   RH  R   (   R   R   R   R   R^  Ru   R   R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR      s    N(   R   R   RZ  R*   R   (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRl    s   R   t   Textareac           B  s   e  Z d  Z RS(   s+   
    Field representing ``<textarea>``
    (   R   R   RZ  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRm    s   R?  t   Hiddenc           B  s   e  Z d  Z RS(   s6   
    Field representing ``<input type="hidden">``
    (   R   R   RZ  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRn    s   t   hiddent   Submitc           B  s2   e  Z d  Z e Z d   Z e e  Z d   Z RS(   sG   
    Field representing ``<input type="submit">`` and ``<button>``
    c         C  s   d  S(   N(   R*   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRd    s    c         C  s   |  j  S(   N(   R_  (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRY  "  s    (	   R   R   RZ  R   R`  Rd  R8  Ru   RY  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRp    s
   	RX  R   t   imaget   TestFileEnvironmentc           B  sw   e  Z d  Z e Z d	 d	 d	 d	 e d	 e d  Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	 d	 d  Z RS(
   se   
    This represents an environment in which files will be written, and
    scripts will be run.
    c	   	      C  s  | |  _  | |  _ | d k r0 t j j   } n  | |  _ | d k r t j d k rr | j d d  j	 d  } q | j d d  j	 d  } n  | |  _
 | d k r | } n  | |  _ | r |  j   n" t j j |  s t j |  n  | p g  |  _ | |  _ d S(   s  
        Creates an environment.  ``base_path`` is used as the current
        working directory, and generally where changes are looked for.

        ``template_path`` is the directory to look for *template*
        files, which are files you'll explicitly add to the
        environment.  This is done with ``.writefile()``.

        ``script_path`` is the PATH for finding executables.  Usually
        grabbed from ``$PATH``.

        ``environ`` is the operating system environment,
        ``os.environ`` if not given.

        ``cwd`` is the working directory, ``base_path`` by default.

        If ``start_clear`` is true (default) then the ``base_path``
        will be cleared (all files deleted) when an instance is
        created.  You can also use ``.clear()`` to clear the files.

        ``ignore_paths`` is a set of specific filenames that should be
        ignored when created in the environment.  ``ignore_hidden``
        means, if true (default) that filenames and directories
        starting with ``'.'`` will be ignored.
        t   win32t   PATHRC   t   ;t   :N(   t	   base_patht   template_pathR*   R   R=   R<   R   t   platformRQ   RF   t   script_patht   cwdt   clearR   t   existst   makedirst   ignore_pathst   ignore_hidden(	   R   Rw  Rx  Rz  R=   R{  t   start_clearR  R  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   9  s&    						c         O  s  t  } t | d t  } t | d |  } t | d |  j  } t | d d  } t | d t   }	 t t t |   } | s t d d j	 | j
      d | k r | s t d	 | | f   | j d d
  \ } } t j |  } n  |  j |  } | g | }
 |  j   } t j |
 d t j d t j d t j d | d |  j } | j |  \ } } |  j   } t |  |
 | | | d | j d | d | } |	 rt |  t d d  n  | s| j   n  | s| j   n  | S(   s  
        Run the command, with the given arguments.  The ``script``
        argument can have space-separated arguments, or you can use
        the positional arguments.

        Keywords allowed are:

        ``expect_error``: (default False)
            Don't raise an exception in case of errors
        ``expect_stderr``: (default ``expect_error``)
            Don't raise an exception if anything is printed to stderr
        ``stdin``: (default ``""``)
            Input to the script
        ``printresult``: (default True)
            Print the result after running
        ``cwd``: (default ``self.cwd``)
            The working directory to run in

        Returns a `ProcResponse
        <class-paste.fixture.ProcResponse.html>`_ object.
        t   expect_errort   expect_stderrR{  t   stdint   printresults   Arguments not expected: %ss   , R!  s?   You cannot give a multi-argument script (%r) and arguments (%s)i   R   R   t   envt
   returncodet   files_beforet   files_afterRo   i(   N(   R   t   _popgetR   R{  R*   R   R   RE   R   R   RR  RF   t   shlext	   _find_exet   _find_filest
   subprocesst   Popent   PIPER=   t   communicatet
   ProcResultR  R   t   assert_no_errort   assert_no_stderr(   R   t   scriptR
   R   RO   R  R  R{  R  R  t   allR  t   procR   R   R  t   result(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   runk  sL    

				
c         C  s   |  j  d  k rP t j j |  j |  } t j j |  sL t d |   n  | Sx< |  j  D]1 } t j j | |  } t j j |  rZ | SqZ Wt d | d j |  j   f   d  S(   Ns   Script %s does not exists"   Script %s could not be found in %sRv  (   Rz  R*   R   R   R   R{  R}  t   OSError(   R   t   script_nameR   R6  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    c         C  sL   i  } x? t  j |  j  D]+ } |  j |  r4 q n  |  j | |  q W| S(   N(   R   t   listdirRw  t   _ignore_filet   _find_traverse(   R   R  R6  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    c         C  s?   | |  j  k r t S|  j r; t j j |  j d  r; t St S(   Nt   .(   R  R   R  R   R   t   basenameR  R   (   R   R6  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s
    $c         C  s   t  j j |  j |  } t  j j |  r t |  j |  | | <xj t  j |  D]@ } t  j j | |  } |  j |  r qP n  |  j | |  qP Wn t	 |  j |  | | <d  S(   N(
   R   R   R   Rw  t   isdirt   FoundDirR  R  R  t	   FoundFile(   R   R   R  t   fullR6  (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    c         C  s<   t  j j |  j  r( t j |  j  n  t  j |  j  d S(   s=   
        Delete all the files in the base directory.
        N(   R   R   R}  Rw  t   shutilt   rmtreet   mkdir(   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR|    s    c         C  s   t  j j |  j |  } t  j j t  j j |   sR t  j t  j j |   n  t | d  } | d k	 r} | j	 |  n  | d k	 r |  j
 r t  j j |  j
 |  } n  t | d  } | j	 | j    | j   n  | j   t |  j |  S(   s   
        Write a file to the given path.  If ``content`` is given then
        that text is written, otherwise the file in ``frompath`` is
        used.  ``frompath`` is relative to ``self.template_path``
        R2  R   N(   R   R   R   Rw  R}  t   dirnameR~  R   R*   R   Rx  R   R   R  (   R   R   R   t   frompathR  R   t   f2(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt	   writefile  s    	
N(   R   R   RZ  R   R   R*   R   R   R  R  R  R  R  R|  R  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRr  0  s   	/	=					R  c           B  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s  
    Represents the results of running a command in
    `TestFileEnvironment
    <class-paste.fixture.TestFileEnvironment.html>`_.

    Attributes to pay particular attention to:

    ``stdout``, ``stderr``:
        What is produced

    ``files_created``, ``files_deleted``, ``files_updated``:
        Dictionaries mapping filenames (relative to the ``base_dir``)
        to `FoundFile <class-paste.fixture.FoundFile.html>`_ or
        `FoundDir <class-paste.fixture.FoundDir.html>`_ objects.
    c	         C  s   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ i  |  _ i  |  _	 | j
   |  _ xm | j   D]_ \ }	 }
 |	 | k r |
 |  j |	 <qv n  |  j |	 =|
 j | |	 j k  rv | |	 |  j	 |	 <qv qv Wd  S(   N(   t   test_envR
   R  R   R   R  R  R  t   files_deletedt   files_updatedR<   t   files_createdRR   t   mtime(   R   R  R
   R  R   R   R  R  R  R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s$    										
c         C  s,   t  } |  j d k s( t d |  j   d  S(   Ni    s   Script returned code: %s(   R   R  R   (   R   RO   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    c         C  s9   t  } |  j r5 t d  t |  j  t d   n  d  S(   Ns   Error output:s   stderr output not expected(   R   R   R   R   (   R   RO   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s
    	
c   	   
   C  s  d d j  |  j  g } |  j r9 | j d |  j  n  |  j rb | j d  | j |  j  n  |  j r | j d  | j |  j  n  x d |  j t f d |  j t f d |  j	 t f g D] \ } } } | r | j d	 |  | j
   } | j   d
 } xr | D]g \ } } d t | | d d d t } | } | rb| j d k rb| d | j 7} n  | j |  qWq q Wd j  |  S(   Ns   Script result: %sR!  s     return code: %ss   -- stderr: --------------------s   -- stdout: --------------------t   createdt   deletedt   updateds   -- %s: -------------------RC   s     %st   indenti   t   include_seps   N/As     (%s bytes)s   
(   R   R
   R  Rz   R   R   R  R   R  R  RR   R   t   _space_prefixR   t   size(	   R   R   R   R   t	   show_sizet   lastR   R   t   t(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR1  #  s4    			"

(   R   R   RZ  R   R  R  R1  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s
   			R  c           B  sS   e  Z d  Z e Z e Z d   Z d   Z e	 e  Z
 d   Z d   Z d   Z RS(   s  
    Represents a single file found as the result of a command.

    Has attributes:

    ``path``:
        The path of the file, relative to the ``base_path``

    ``full``:
        The full path

    ``stat``:
        The results of ``os.stat``.  Also ``mtime`` and ``size``
        contain the ``.st_mtime`` and ``st_size`` of the stat.

    ``bytes``:
        The contents of the file.

    You may use the ``in`` operator with these objects (tested against
    the contents of the file), and the ``.mustcontain()`` method.
    c         C  sj   | |  _  | |  _ t j j | |  |  _ t j |  j  |  _ |  j j |  _ |  j j |  _	 d  |  _ d  S(   N(   Rw  R   R   R   R  t   statt   st_mtimeR  t   st_sizeR  R*   t   _bytes(   R   Rw  R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR   Z  s    		c         C  sD   |  j  d  k r= t |  j d  } | j   |  _  | j   n  |  j  S(   NR   (   R  R*   R   R  R   R   (   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt
   bytes__getc  s
    c         C  s   | |  j  k S(   N(   t   bytes(   R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR'  k  s    c         C  sL   t  } |  j } | | k rH t d |  t |  | | k sH t  n  d  S(   Ns   Could not find %r in:(   R   R  R   R   (   R   R   RO   t   bytes_(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR,  n  s    	
c         C  s   d |  j  j |  j |  j f S(   Ns
   <%s %s:%s>(   R   R   Rw  R   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR-  v  s    	(   R   R   RZ  R   R)  R   t   dirR   R  R8  R  R'  R,  R-  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR  ?  s   					R  c           B  s,   e  Z d  Z e Z e Z d   Z d   Z RS(   s6   
    Represents a directory created by a command.
    c         C  s@   | |  _  | |  _ t j j | |  |  _ d |  _ d |  _ d  S(   Ns   N/A(   Rw  R   R   R   R  R  R  (   R   Rw  R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR     s
    			c         C  s   d |  j  j |  j |  j f S(   Ns
   <%s %s:%s>(   R   R   Rw  R   (   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR-    s    	(	   R   R   RZ  R   R)  R   R  R   R-  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR  {  s
   	c         C  s   | |  k r |  j  |  S| S(   s4   
    Pop the key if found (else return default)
    (   RE  (   R  R   R   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    c         C  s  | d k r t j j } n  |  j |  }  | j |  } g  } x |  r | r |  d | d k r | d k r | j d t | d  t |   n | j d |  | j d  |  j d  qB W| r| r d j |  | | j |  Sd j |  | j |  Sn | j |  Sd S(   sg   
    Anything shared by pref and full will be replaced with spaces
    in full, and full returned.
    i    R!  RC   N(	   R*   R   R   R4  RF   Rz   Ra   RE  R   (   t   prefR  R4  R  R  t   padding(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s     #(c         C  s}   |  d  k r d  St |  t j t j f  r= t j |   }  n  t |  d  rS |  j St	 |   rc |  Sd sy t
 d |    d  S(   NR  i    s-   Cannot make callable pattern object out of %r(   R*   R1   R2   R3   R4   R   R   RZ   R  t   callableR   (   t   pat(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyR    s    	c         C  s   d d l  } | j d t d  |  d k rD t j   j j d }  n  t |  t	 j
 t	 j f  ro t j |  }  n  t |  d  r |  j   n  d S(   s   
    This is used by pytest if it is in the module, so you can
    import this directly.

    Use like::

        from paste.fixture import setup_module
    iNs   setup_module is deprecatedi   R   t   reset_state(   R   R   R   R*   R   t	   _getframet   f_backt	   f_globalsR1   R2   R3   R4   t   modulesRZ   R  (   t   moduleR   (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   setup_module  s    

c         C  s<   x5 d d d d d g D] \ } } |  j  | |  }  q W|  S(   s8   
    Unquote (some) entities in HTML.  (incomplete)
    s   &nbsp;R!  s   &gt;t   >s   &lt;t   <s   &quot;t   "s   &amp;RA   (   s   &nbsp;R!  (   s   &gt;R  (   s   &lt;R  (   s   &quot;R  (   s   &amp;RA   (   Rr   (   R   t   entt   repl(    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyRD    s
    	(A   RZ  t
   __future__R    R   Ry   R}   R   R   R  R&   R  R   R2   R  t	   six.movesR   R   t   six.moves.urllib.parseR   t   six.moves.urllibR   R]   t   six.moves.http_cookiesR   t   pasteR   R   t   paste.responseR   R   t   objectR   R   R   t	   ExceptionR-   R.   R   R   RI   R   R   R  R[  R  RH  RV  RI  RG  Ri  Rl  Rm  Rn  Rp  Rr  R  R  R  R*   R  R   R  R  R  RD  (    (    (    s7   /usr/local/lib/python2.7/dist-packages/paste/fixture.pyt   <module>
   sv   		%  %		()
O<	