ó
³Ebc           @   s,  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 e rÁ d  d	 l m Z n d  d l Z d d
 l
 m Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿNi   (   t
   formatting(   t   termui(   t   utils(   t	   iteritems(   t   PY2(   t   string_types(   t   StringIO(   t   _find_binary_readert   EchoingStdinc           B   sV   e  Z d  „  Z d „  Z d „  Z d d „ Z d d „ Z d „  Z d „  Z d „  Z	 RS(	   c         C   s   | |  _  | |  _ d  S(   N(   t   _inputt   _output(   t   selft   inputt   output(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   __init__   s    	c         C   s   t  |  j | ƒ S(   N(   t   getattrR	   (   R   t   x(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   __getattr__   s    c         C   s   |  j  j | ƒ | S(   N(   R
   t   write(   R   t   rv(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   _echo   s    iÿÿÿÿc         C   s   |  j  |  j j | ƒ ƒ S(   N(   R   R	   t   read(   R   t   n(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   #   s    c         C   s   |  j  |  j j | ƒ ƒ S(   N(   R   R	   t   readline(   R   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   &   s    c         C   s)   g  |  j  j ƒ  D] } |  j | ƒ ^ q S(   N(   R	   t	   readlinesR   (   R   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   )   s    c            s   t  ‡  f d †  ˆ  j Dƒ ƒ S(   Nc         3   s   |  ] } ˆ  j  | ƒ Vq d  S(   N(   R   (   t   .0R   (   R   (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pys	   <genexpr>-   s    (   t   iterR	   (   R   (    (   R   se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   __iter__,   s    c         C   s   t  |  j ƒ S(   N(   t   reprR	   (   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   __repr__/   s    (
   t   __name__t
   __module__R   R   R   R   R   R   R   R   (    (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR      s   					c         C   s—   t  |  d ƒ rD t r |  St |  ƒ } | d  k	 r5 | St d ƒ ‚ n  |  d  k rY d }  n! t |  t ƒ sz |  j | ƒ }  n  t rŠ t |  ƒ St	 j
 |  ƒ S(   NR   s.   Could not find binary reader for input stream.t    (   t   hasattrR   R   t   Nonet	   TypeErrort
   isinstancet   bytest   encodeR   t   iot   BytesIO(   R   t   charsetR   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   make_input_stream3   s    	
t   Resultc           B   sP   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 RS(   s3   Holds the captured result of an invoked CLI script.c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   runnert   stdout_bytest   stderr_bytest	   exit_codet	   exceptiont   exc_info(   R   R,   R-   R.   R/   R0   R1   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   I   s    					c         C   s   |  j  S(   s(   The (standard) output as unicode string.(   t   stdout(   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   Y   s    c         C   s%   |  j  j |  j j d ƒ j d d ƒ S(   s&   The standard output as unicode string.t   replaces   
s   
(   R-   t   decodeR,   R)   R3   (   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR2   ^   s    c         C   sC   |  j  d k r t d ƒ ‚ n  |  j  j |  j j d ƒ j d d ƒ S(   s%   The standard error as unicode string.s   stderr not separately capturedR3   s   
s   
N(   R.   R"   t
   ValueErrorR4   R,   R)   R3   (   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   stderre   s    c         C   s1   d j  t |  ƒ j |  j r* t |  j ƒ n d ƒ S(   Ns   <{} {}>t   okay(   t   formatt   typeR   R0   R   (   R   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   n   s    N(
   R   R   t   __doc__R"   R   t   propertyR   R2   R6   R   (    (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR+   F   s   	t	   CliRunnerc           B   s}   e  Z d  Z d d e e d „ Z d „  Z d d „ Z e	 j
 d d e d „ ƒ Z d d d e e d „ Z e	 j
 d „  ƒ Z RS(   s™  The CLI runner provides functionality to invoke a Click command line
    script for unittesting purposes in a isolated environment.  This only
    works in single-threaded systems without any concurrency as it changes the
    global interpreter state.

    :param charset: the character set for the input and output data.  This is
                    UTF-8 by default and should not be changed currently as
                    the reporting to Click only works in Python 2 properly.
    :param env: a dictionary with environment variables for overriding.
    :param echo_stdin: if this is set to `True`, then reading from stdin writes
                       to stdout.  This is useful for showing examples in
                       some circumstances.  Note that regular prompts
                       will automatically echo the input.
    :param mix_stderr: if this is set to `False`, then stdout and stderr are
                       preserved as independent streams.  This is useful for
                       Unix-philosophy apps that have predictable stdout and
                       noisy stderr, such that each may be measured
                       independently
    c         C   sC   | d  k r d } n  | |  _ | p' i  |  _ | |  _ | |  _ d  S(   Ns   utf-8(   R"   R)   t   envt
   echo_stdint
   mix_stderr(   R   R)   R=   R>   R?   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR   ‰   s    			c         C   s   | j  p d S(   sž   Given a command object it will return the default program name
        for it.  The default is the `name` attribute or ``"root"`` if not
        set.
        t   root(   t   name(   R   t   cli(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   get_default_prog_name‘   s    c         C   s)   t  |  j ƒ } | r% | j | ƒ n  | S(   s8   Returns the environment overrides for invoking a script.(   t   dictR=   t   update(   R   t	   overridesR   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   make_env˜   s    c      	   #   s  t  ˆ |  j ƒ ‰ t j } t j } t j } t j } d t _ |  j | ƒ } t	 r¢ t
 ƒ  } |  j rx t ˆ | ƒ ‰ n  | t _ |  j s/t
 ƒ  }	 |	 t _ q/n t j ƒ  } |  j rÉ t ˆ | ƒ ‰ n  t j ˆ d |  j ƒ‰ t j | d |  j ƒt _ |  j s/t j ƒ  }	 t j |	 d |  j ƒt _ n  |  j rGt j t _ n  ˆ t _ d ‡ f d † }
 d ‡ f d † } d „  } | ‰  d d ‡  f d † } t j } t j } t j } t j } |
 t _ | t _ | t _ | t _ i  } zŠ xn t | ƒ D]` \ } } t j j | ƒ | | <| d k rIy t j | =WqVt k
 rEqVXqö| t j | <qöW| |  j oj|	 f VWd xX t | ƒ D]J \ } } | d k r½y t j | =WqÊt k
 r¹qÊXq€| t j | <q€W| t _ | t _ | t _ | t _ | t _ | t _ | t _ | t _ Xd S(   sÙ  A context manager that sets up the isolation for invoking of a
        command line tool.  This sets up stdin with the given input data
        and `os.environ` with the overrides from the given dictionary.
        This also rebinds some internals in Click to be mocked (like the
        prompt functionality).

        This is automatically done in the :meth:`invoke` method.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param input: the input stream to put into sys.stdin.
        :param env: the environment overrides as dictionary.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.
        iP   t   encodingc            sU   t  j j |  p d ƒ ˆ  j ƒ  j d ƒ } t  j j d j | ƒ ƒ t  j j ƒ  | S(   NR    s   
s   {}
(   t   sysR2   R   R   t   rstripR8   t   flush(   t   promptt   val(   R   (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   visible_inputÒ   s
    c            s?   t  j j d j |  p d ƒ ƒ t  j j ƒ  ˆ  j ƒ  j d ƒ S(   Ns   {}
R    s   
(   RI   R2   R   R8   RK   R   RJ   (   RL   (   R   (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   hidden_inputÙ   s    c         S   s<   t  j j d ƒ } |  r8 t  j j | ƒ t  j j ƒ  n  | S(   Ni   (   RI   t   stdinR   R2   R   RK   (   t   echot   char(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   _getcharÞ   s
    c            s   | d  k r ˆ  S| S(   N(   R"   (   t   streamt   color(   t   default_color(    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   should_strip_ansiç   s    N(   R*   R)   RI   RP   R2   R6   R    t   FORCED_WIDTHRG   R   R   R>   R   R?   R'   R(   t   TextIOWrapperR"   R   t   visible_prompt_funct   hidden_prompt_funcRS   R   RW   R   t   ost   environt   gett	   Exception(   R   R   R=   RU   t	   old_stdint
   old_stdoutt
   old_stderrt   old_forced_widtht   bytes_outputt   bytes_errorRN   RO   RS   RW   t   old_visible_prompt_funct   old_hidden_prompt_funct   old__getchar_funct   old_should_strip_ansit   old_envt   keyt   value(    (   RV   R   se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt	   isolationŸ   s‚    																														c         K   sî  d	 } |  j d | d | d | ƒ }	 d	 }
 d } t | t ƒ rT t j | ƒ } n  y | j d ƒ } Wn  t k
 r‰ |  j | ƒ } n Xzð y# | j	 d | p¢ d d | |  WnÆ t
 k
 rB} t j ƒ  } | j } | d	 k rì d } n  | d k r| }
 n  t | t ƒ syt j j t | ƒ ƒ t j j d ƒ d } qyn7 t k
 rx} | s]‚  n  | }
 d } t j ƒ  } n XWd	 t j j ƒ  |	 d j ƒ  } |  j r¬d	 } n |	 d j ƒ  } XWd	 QXt d
 |  d | d | d | d |
 d | ƒ S(   s;  Invokes a command in an isolated environment.  The arguments are
        forwarded directly to the command line script, the `extra` keyword
        arguments are passed to the :meth:`~clickpkg.Command.main` function of
        the command.

        This returns a :class:`Result` object.

        .. versionadded:: 3.0
           The ``catch_exceptions`` parameter was added.

        .. versionchanged:: 3.0
           The result object now has an `exc_info` attribute with the
           traceback if available.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param cli: the command to invoke
        :param args: the arguments to invoke. It may be given as an iterable
                     or a string. When given as string it will be interpreted
                     as a Unix shell command. More details at
                     :func:`shlex.split`.
        :param input: the input data for `sys.stdin`.
        :param env: the environment overrides.
        :param catch_exceptions: Whether to catch any other exceptions than
                                 ``SystemExit``.
        :param extra: the keyword arguments to pass to :meth:`main`.
        :param color: whether the output should contain color codes. The
                      application can still override this explicitly.
        R   R=   RU   i    t	   prog_namet   argss   
i   NR,   R-   R.   R/   R0   R1   (    (   R"   Rm   R$   R   t   shlext   splitt   popt   KeyErrorRC   t   maint
   SystemExitRI   R1   t   codet   intR2   R   t   strR_   RK   t   getvalueR?   R+   (   R   RB   Ro   R   R=   t   catch_exceptionsRU   t   extraR1   t
   outstreamsR0   R/   Rn   t   eR2   R6   (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   invoke  sT    (! #					c      	   c   sn   t  j ƒ  } t j ƒ  } t  j | ƒ z	 | VWd t  j | ƒ y t j | ƒ Wn t t f k
 rh n XXd S(   s‘   A context manager that creates a temporary folder and changes
        the current working directory to it for isolated filesystem tests.
        N(	   R\   t   getcwdt   tempfilet   mkdtempt   chdirt   shutilt   rmtreet   OSErrort   IOError(   R   t   cwdt   t(    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   isolated_filesystemo  s    	N(   R   R   R:   R"   t   Falset   TrueR   RC   RG   t
   contextlibt   contextmanagerRm   R~   R‰   (    (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyR<   t   s   	vU(   RŒ   R\   Rp   Rƒ   RI   R€   R    R    R   R   t   _compatR   R   R   t	   cStringIOR   R'   R   t   objectR   R*   R+   R<   (    (    (    se   /var/www/html/facial-emotion-detection-webapp-main/flask/lib/python2.7/site-packages/click/testing.pyt   <module>   s&   	.