ó
j4Vdc           @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z d „  Z d „  Z d „  Z d „  Z	 d e
 d	 „ Z d d
 e
 d „ Z e
 d e d „ Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d d d d „ Z d „  Z d e f d „  ƒ  YZ d „  Z d S(   sv   
Internal subroutines for e.g. aborting execution with an error message,
or performing indenting on multiline output.
iÿÿÿÿN(   t
   format_excc         C   sK   t  |  t ƒ r= t | d ƒ r= | j d  k	 r= |  j | j ƒ St |  ƒ Sd  S(   Nt   encoding(   t
   isinstancet   unicodet   hasattrR   t   Nonet   encodet   str(   t   msgt   stream(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   _encode   s    -c         C   s)   t  |  d d ƒ } | d k r" t S| ƒ  S(   s^   Check if a stream is a tty.

    Not all file-like objects implement the `isatty` method.
    t   isattyN(   t   getattrR   t   False(   R	   t   fn(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyR      s    c         C   s½   d d l  m } m } | j s+ d „  } n d d l m } | j rƒ t j j	 | d t
 |  t j ƒ ƒ ƒ t j j	 | d ƒ ƒ n  | j rž | j |  ƒ ‚ n t d ƒ } |  | _ | ‚ d S(	   sB  
    Abort execution, print ``msg`` to stderr and exit with error status (1.)

    This function currently makes use of `SystemExit`_ in a manner that is
    similar to `sys.exit`_ (but which skips the automatic printing to stderr,
    allowing us to more tightly control it via settings).

    Therefore, it's possible to detect and recover from inner calls to `abort`
    by using ``except SystemExit`` or similar.

    .. _sys.exit: http://docs.python.org/library/sys.html#sys.exit
    .. _SystemExit: http://docs.python.org/library/exceptions.html#exceptions.SystemExit
    iÿÿÿÿ(   t   outputt   envc         S   s   |  S(   N(    (   t   x(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   <lambda>-   t    (   t   reds   
Fatal error: %s
s   
Aborting.
i   N(   t   fabric.stateR   R   t   colorize_errorst   colorsR   t   abortst   syst   stderrt   writeR
   t   abort_exceptiont
   SystemExitt   message(   R   R   R   R   t   e(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   abort   s    		&		c         C   sw   d d l  m } m } | j s+ d „  } n d d l m } | j rs t |  t j	 ƒ }  t j	 j
 | d |  ƒ ƒ n  d S(   s#  
    Print warning message, but do not abort execution.

    This function honors Fabric's :doc:`output controls
    <../../usage/output_controls>` and will print the given ``msg`` to stderr,
    provided that the ``warnings`` output level (which is active by default) is
    turned on.
    iÿÿÿÿ(   R   R   c         S   s   |  S(   N(    (   R   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyR   M   R   (   t   magentas   
Warning: %s

N(   R   R   R   R   R   R!   t   warningsR
   R   R   R   (   R   R   R   R!   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   warnA   s    			i   c            s‚   t  |  d ƒ s! d j |  ƒ }  n  | r9 t j |  ƒ }  n  d | ‰  d j ‡  f d †  |  j ƒ  Dƒ ƒ } | j ƒ  } ˆ  | } | S(   sâ  
    Return ``text`` indented by the given number of spaces.

    If text is not a string, it is assumed to be a list of lines and will be
    joined by ``\n`` prior to indenting.

    When ``strip`` is ``True``, a minimum amount of whitespace is removed from
    the left-hand side of the given string (so that relative indents are
    preserved, but otherwise things are left-stripped). This allows you to
    effectively "normalize" any previous indentation for some inputs.
    t
   splitliness   
t    c         3   s   |  ] } ˆ  | Vq d  S(   N(    (   t   .0t   line(   t   prefix(    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pys	   <genexpr>j   s    (   R   t   joint   textwrapt   dedentR$   t   strip(   t   textt   spacesR,   R   (    (   R(   sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   indentV   s    
%
s   
c         C   s   d d l  m } m } | d k r. | j } n  | j r™ d } | j r\ | r\ d | j } n  t j j	 | t
 |  t j ƒ | ƒ | r™ t j j ƒ  q™ n  d S(   s÷  
    An alias for ``print`` whose output is managed by Fabric's output controls.

    In other words, this function simply prints to ``sys.stdout``, but will
    hide its output if the ``user`` :doc:`output level
    </usage/output_controls>` is set to ``False``.

    If ``show_prefix=False``, `puts` will omit the leading ``[hostname]``
    which it tacks on by default. (It will also omit this prefix if
    ``env.host_string`` is empty.)

    Newlines may be disabled by setting ``end`` to the empty string (``''``).
    (This intentionally mirrors Python 3's ``print`` syntax.)

    You may force output flushing (e.g. to bypass output buffering) by setting
    ``flush=True``.

    .. versionadded:: 0.9.2
    .. seealso:: `~fabric.utils.fastprint`
    iÿÿÿÿ(   R   R   R   s   [%s] N(   R   R   R   R   t   output_prefixt   usert   host_stringR   t   stdoutR   R
   t   flush(   R-   t   show_prefixt   endR4   R   R   R(   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   putsr   s    	$R   c      	   C   s   t  d |  d | d | d | ƒ S(   sz  
    Print ``text`` immediately, without any prefix or line ending.

    This function is simply an alias of `~fabric.utils.puts` with different
    default argument values, such that the ``text`` is printed without any
    embellishment and immediately flushed.

    It is useful for any situation where you wish to print text which might
    otherwise get buffered by Python's output buffering (such as within a
    processor intensive ``for`` loop). Since such use cases typically also
    require a lack of line endings (such as printing a series of dots to
    signify progress) it also omits the traditional newline by default.

    .. note::

        Since `~fabric.utils.fastprint` calls `~fabric.utils.puts`, it is
        likewise subject to the ``user`` :doc:`output level
        </usage/output_controls>`.

    .. versionadded:: 0.9.2
    .. seealso:: `~fabric.utils.puts`
    R-   R5   R6   R4   (   R7   (   R-   R5   R6   R4   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt	   fastprint“   s    c         C   si   d d  l  } d |  | j j j f } | j j j rE t | d ƒ n  | j j j re t | d ƒ n  d  S(   Niÿÿÿÿs+   Needed to prompt for %s (host: %s), but %%ss    abort-on-prompts was set to Trues)   input would be ambiguous in parallel mode(   R   t   stateR   R2   t   abort_on_promptsR    t   parallel(   t
   prompt_fort   fabrict   reason(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   handle_prompt_abort­   s    t   _AttributeDictc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s3  
    Dictionary subclass enabling attribute lookup/assignment of keys/values.

    For example::

        >>> m = _AttributeDict({'foo': 'bar'})
        >>> m.foo
        'bar'
        >>> m.foo = 'not bar'
        >>> m['foo']
        'not bar'

    ``_AttributeDict`` objects also provide ``.first()`` which acts like
    ``.get()`` but accepts multiple keys as arguments, and returns the value of
    the first hit, e.g.::

        >>> m = _AttributeDict({'foo': 'bar', 'biz': 'baz'})
        >>> m.first('wrong', 'incorrect', 'foo', 'biz')
        'bar'

    c         C   s0   y |  | SWn t  k
 r+ t | ƒ ‚ n Xd  S(   N(   t   KeyErrort   AttributeError(   t   selft   key(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   __getattr__Ð   s    c         C   s   | |  | <d  S(   N(    (   RC   RD   t   value(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   __setattr__×   s    c         G   s.   x' | D] } |  j  | ƒ } | r | Sq Wd  S(   N(   t   get(   RC   t   namest   nameRF   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   firstÚ   s    (   t   __name__t
   __module__t   __doc__RE   RG   RK   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyR@   º   s   		t
   _AliasDictc           B   s/   e  Z d  Z d d d „ Z d „  Z d „  Z RS(   s7  
    `_AttributeDict` subclass that allows for "aliasing" of keys to other keys.

    Upon creation, takes an ``aliases`` mapping, which should map alias names
    to lists of key names. Aliases do not store their own value, but instead
    set (override) all mapped keys' values. For example, in the following
    `_AliasDict`, calling ``mydict['foo'] = True`` will set the values of
    ``mydict['bar']``, ``mydict['biz']`` and ``mydict['baz']`` all to True::

        mydict = _AliasDict(
            {'biz': True, 'baz': False},
            aliases={'foo': ['bar', 'biz', 'baz']}
        )

    Because it is possible for the aliased values to be in a heterogenous
    state, reading aliases is not supported -- only writing to them is allowed.
    This also means they will not show up in e.g. ``dict.keys()``.

    ..note::

        Aliases are recursive, so you may refer to an alias within the key list
        of another alias. Naturally, this means that you can end up with
        infinite loops if you're not careful.

    `_AliasDict` provides a special function, `expand_aliases`, which will take
    a list of keys as an argument and will return that list of keys with any
    aliases expanded. This function will **not** dedupe, so any aliases which
    overlap will result in duplicate keys in the resulting list.
    c         C   sI   t  t |  ƒ j } | d  k	 r+ | | ƒ n | ƒ  t j |  d | ƒ d  S(   Nt   aliases(   t   superRO   t   __init__R   t   dictRG   (   RC   t   argRP   t   init(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRR   ÿ   s
    c         C   s`   t  |  d ƒ rC | |  j k rC x; |  j | D] } | |  | <q, Wn t t |  ƒ j | | ƒ Sd  S(   NRP   (   R   RP   RQ   RO   t   __setitem__(   RC   RD   RF   t   aliased(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRV     s    c         C   sW   g  } xJ | D]B } | |  j  k rB | j |  j |  j  | ƒ ƒ q | j | ƒ q W| S(   N(   RP   t   extendt   expand_aliasest   append(   RC   t   keyst   retRD   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRY     s     N(   RL   RM   RN   R   RR   RV   RY   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRO   á   s   		c          C   s  d d l  m }  |  s= d d l } d d l } d d l } n  d \ } } | | } } |  rt t j ƒ rd } | j | d d ƒ }	 yg | j	 t j j
 ƒ  | j |	 ƒ }
 | j | |
 ƒ \ } } | d k rØ | } n  | d k rí | } n  Wqt k
 rqXn  | | f S(	   sÞ   
    Obtain (rows, cols) tuple for sizing a pty on the remote end.

    Defaults to 80x24 (which is also the 'ssh' lib's default) but will detect
    local (stdout-based) terminal window size on non-Windows platforms.
    iÿÿÿÿ(   t   win32Ni   iP   t   HHi    (   i   iP   (   R   R]   t   fcntlt   termiost   structR   R   R3   t   packt   ioctlt   filenot
   TIOCGWINSZt   unpackRB   (   R]   R_   R`   Ra   t   default_rowst   default_colst   rowst   colst   fmtt   buffert   result(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt	   _pty_size  s*    		c         C   sA  d d l  } | d k r6 | j j j r- t p0 t } n  | j j j sT | j j j	 rw t
 ƒ  } | rÐ |  d | 7}  qÐ nY | d k	 rÐ t | d ƒ r­ | j d k	 r­ | j } n | } |  d t t | ƒ ƒ 7}  n  | t k r7| r| j j j r|  t d | ƒ 7}  n  | r7| j j j r7|  t d | ƒ 7}  q7n  | |  ƒ S(   sœ  
    Call ``func`` with given error ``message``.

    If ``func`` is None (the default), the value of ``env.warn_only``
    determines whether to call ``abort`` or ``warn``.

    If ``exception`` is given, it is inspected to get a string message, which
    is printed alongside the user-generated ``message``.

    If ``stdout`` and/or ``stderr`` are given, they are assumed to be strings
    to be printed.
    iÿÿÿÿNs   

t   strerrors   

Underlying exception:
s   Standard outputs   Standard error(   R   R   R9   R   t	   warn_onlyR#   R    R   t
   exceptionst   debugR    R   Ro   R/   R   R3   t   _format_error_outputR   (   R   t   funct	   exceptionR3   R   R=   t   exception_messaget
   underlying(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   errorA  s$    	c         C   sP   t  ƒ  d } | t |  ƒ d d } d } | | } d | |  | | | | f S(   Ni   i   t   =s   

%s %s %s

%s

%s(   Rn   t   len(   t   headert   bodyt
   term_widtht   header_side_lengtht   markt   side(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRs   i  s    
t
   RingBufferc           B   sP   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s+   t  t |  ƒ |  _ | |  _ |  j j | ƒ S(   N(   RQ   R   t   _supert   _maxlenRR   (   RC   RF   t   maxlen(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRR   u  s    	c         C   s=   |  j  d  k r d  St t |  ƒ |  j  d ƒ } |  d | 5d  S(   Ni    (   Rƒ   R   t   maxRz   (   RC   t   overage(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   _trim|  s    c         C   s   |  j  j | ƒ |  j ƒ  d  S(   N(   R‚   RZ   R‡   (   RC   RF   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRZ   ‚  s    c         C   s   |  j  j | ƒ |  j ƒ  d  S(   N(   R‚   RX   R‡   (   RC   t   values(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRX   †  s    c         C   s   |  j  | ƒ |  S(   N(   RX   (   RC   t   other(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   __iadd__Š  s    c         C   s   t  d ƒ ‚ d  S(   Ns.   Can't insert into the middle of a ring buffer!(   t
   ValueError(   RC   t   indexRF   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   insert  s    c         C   s   t  d ƒ ‚ d  S(   Ns#   Can't set a slice of a ring buffer!(   R‹   (   RC   t   it   jt   sequence(    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   __setslice__’  s    c         C   s5   t  | t ƒ r t d ƒ ‚ n |  j j | | ƒ Sd  S(   Ns#   Can't set a slice of a ring buffer!(   R   t   sliceR‹   R‚   RV   (   RC   RD   RF   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyRV   •  s    (
   RL   RM   RR   R‡   RZ   RX   RŠ   R   R‘   RV   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyR   t  s   							c         C   s;   t  j j |  ƒ r7 | j r7 t  j j | j |  ƒ }  n  |  S(   N(   t   ost   patht   isabst   lcwdR)   (   R”   R   (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt
   apply_lcwdœ  s    (   RN   R“   R   R*   t	   tracebackR    R
   R   R    R#   R   R/   R   R7   t   TrueR8   R?   RS   R@   RO   Rn   Rx   Rs   t   listR   R—   (    (    (    sZ   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/utils.pyt   <module>   s&   			$	!	'9	'(	(