
j4Vdc           @  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
 m
 Z
 d d l m Z m Z d d l m Z m Z m Z m Z m Z d d l m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m  Z  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& d d l' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ d   Z0 d e1 f d     YZ2 d e3 f d     YZ4 d   Z5 d d d d  Z7 e d d e8 e8 d e9 d d   Z: e d e8 d d   Z; d   Z< d d  Z= e9 d d  Z> d   Z? e8 d  Z@ e9 d e8 d d d d d  ZA e d d   ZB e d    ZC e9 e9 e9 e8 d e8 e8 d d d d d d d  ZD e e9 e9 d e8 e8 d d d d d d  
  ZE e e9 e9 d d e8 e8 d d d d d d d!   ZF e8 d d"  ZG e d# d$ e9 d%   ZH d S(&   sR   

Functions to be used in fabfiles and other non-core code, such as run()/sudo().
i(   t   with_statementN(   t   glob(   t   closingt   contextmanager(   t   settingst   char_bufferedt   hidet   quiett	   warn_only(   t   output_loopt
   input_loop(   t
   needs_hostt   ssht
   ssh_config(   t   SFTP(   t   envt   connectionst   outputt   win32t   default_channel(   t   ThreadHandler(   t   abortt   errort   handle_prompt_abortt   indentt	   _pty_sizet   warnt
   apply_lcwdt
   RingBufferc         C  s+   x$ d D] } |  j  | d |  }  q W|  S(   s   
    Escape double quotes, backticks and dollar signs in given ``string``.

    For example::

        >>> _shell_escape('abc$')
        'abc\\$'
        >>> _shell_escape('"')
        '\\"'
    t   "t   $t   `s   \%s(   R   R   R   (   t   replace(   t   stringt   char(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _shell_escape   s    t   _AttributeStringc           B  s   e  Z d  Z e d    Z RS(   sE   
    Simple string subclass to allow arbitrary attribute access.
    c         C  s
   t  |   S(   N(   t   str(   t   self(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   stdout3   s    (   t   __name__t
   __module__t   __doc__t   propertyR'   (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR$   /   s   t   _AttributeListc           B  s   e  Z d  Z RS(   s/   
    Like _AttributeString, but for lists.
    (   R(   R)   R*   (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR,   8   s   c          O  sP  t  d   |   } | s d St |  d k r= d } d } n d } d } d t k re d	 t j } n d
 } d | | t |  f } d | k r | d | | d f 7} n  d | k rB| d } t | d  s | g } n  t |  d k r d } n d } d   }	 g  | D] }
 |	 |
  ^ q} | d | t |  f 7} n  t |  d S(   s  
    Check for given keys in the shared environment dict and abort if not found.

    Positional arguments should be strings signifying what env vars should be
    checked for. If any of the given arguments do not exist, Fabric will abort
    execution and print the names of the missing keys.

    The optional keyword argument ``used_for`` may be a string, which will be
    printed in the error output to inform users why this requirement is in
    place. ``used_for`` is printed as part of a string similar to::

        "Th(is|ese) variable(s) (are|is) used for %s"

    so format it appropriately.

    The optional keyword argument ``provided_by`` may be a list of functions or
    function names or a single function or function name which the user should
    be able to execute in order to set the key or keys; it will be included in
    the error output if requirements are not met.

    Note: it is assumed that the keyword arguments apply to all given keys as a
    group. If you feel the need to specify more than one ``used_for``, for
    example, you should break your logic into multiple calls to ``require()``.

    .. versionchanged:: 1.1
        Allow iterable ``provided_by`` values instead of just single values.
    c         S  s@   |  t  k p? |  t  k o? t t  |  t t t t f  o? t  |  S(   N(   R   t
   isinstancet   dictt   listt   tuplet   set(   t   x(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   <lambda>^   s   Ni   s   variables weres   These variables ares   variable wass   This variable ist   commands$   The command '%s' failed because the s   The s3   %sfollowing required environment %s not defined:
%st   used_fors   

%s used for %st   provided_byt   __iter__s   one of the following commandss   the following commandc         S  s   t  |  d t |    S(   NR(   (   t   getattrR%   (   t   obj(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR3      t    s:   

Try running %s prior to this one, to fix the problem:
%s(   t   filtert   lenR   R4   R   t   hasattrR   (   t   keyst   kwargst   missing_keyst   variablet   usedt   prefixt   msgt   funcsR4   t   to_sR9   R6   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   requireA   s8    			
		R:   c   
      C  s  t  d  | r" t j |  } n  d } | d k rM d t |  j   } n d } |  j   | } d } x | d k rPt |  p | } | rl t |  r y | |  } WqJt k
 r } d } d GHt	 | j
  d GHqJXqM| j d  s d | } n  | j d  s| d 7} n  t j | |  }	 |	 sMd	 | | f GHd } qMql ql W| rd| t | <n  | r| d k	 r| | k rt d
 | | | f  n  | S(   s
  
    Prompt user with ``text`` and return the input (like ``raw_input``).

    A single space character will be appended for convenience, but nothing
    else. Thus, you may want to end your prompt text with a question mark or a
    colon, e.g. ``prompt("What hostname?")``.

    If ``key`` is given, the user's input will be stored as ``env.<key>`` in
    addition to being returned by `prompt`. If the key already existed in
    ``env``, its value will be overwritten and a warning printed to the user.

    If ``default`` is given, it is displayed in square brackets and used if the
    user enters nothing (i.e. presses Enter without entering any text).
    ``default`` defaults to the empty string. If non-empty, a space will be
    appended, so that a call such as ``prompt("What hostname?",
    default="foo")`` would result in a prompt of ``What hostname? [foo]`` (with
    a trailing space after the ``[foo]``.)

    The optional keyword argument ``validate`` may be a callable or a string:

    * If a callable, it is called with the user's input, and should return the
      value to be stored on success. On failure, it should raise an exception
      with an exception message, which will be printed to the user.
    * If a string, the value passed to ``validate`` is used as a regular
      expression. It is thus recommended to use raw strings in this case. Note
      that the regular expression, if it is not fully matching (bounded by
      ``^`` and ``$``) it will be made so. In other words, the input must fully
      match the regex.

    Either way, `prompt` will re-prompt until validation passes (or the user
    hits ``Ctrl-C``).

    .. note::
        `~fabric.operations.prompt` honors :ref:`env.abort_on_prompts
        <abort-on-prompts>` and will call `~fabric.utils.abort` instead of
        prompting if that flag is set to ``True``. If you want to block on user
        input regardless, try wrapping with
        `~fabric.context_managers.settings`.

    Examples::

        # Simplest form:
        environment = prompt('Please specify target environment: ')

        # With default, and storing as env.dish:
        prompt('Specify favorite dish: ', 'dish', default='spam & eggs')

        # With validation, i.e. requiring integer input:
        prompt('Please specify process nice level: ', key='nice', validate=int)

        # With validation against a regular expression:
        release = prompt('Please supply a release name',
                validate=r'^\w+-\d+(\.\d+)?$')

        # Prompt regardless of the global abort-on-prompts setting:
        with settings(abort_on_prompts=False):
            prompt('I seriously need an answer on this! ')

    s   a user-specified prompt() callR:   s    [%s] t    s+   Validation failed for the following reason:s   
t   ^R   s?   Regular expression validation failed: '%s' does not match '%s'
sC   overwrote previous env variable '%s'; used to be '%s', is now '%s'.N(   R   R   t   getR%   t   stript   Nonet	   raw_inputt   callablet	   ExceptionR   t   messaget
   startswitht   endswitht   ret   findallR   (
   t   textt   keyt   defaultt   validatet   previous_valuet   default_strt
   prompt_strt   valuet   et   result(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   prompt   sB    <
c         C  s  |  p t  j   }  t |  d  o- t |  j  } t t j  } t |  t} | j	 d  }	 | pg |	 } | j
 d  r | j d |	 d  } n  t  j j |  r t j d  r t j j d  d | } n  | r3t  j j |   }  t |  t  }  | rt |   }
 q<t  j j |   r*|  g }
 q<g  }
 n	 |  g }
 | rb|
 rbd |  } t |   n  | j |  r| rt |
  d k r| j |  rt d |   qn  g  } g  } x |
 D] } yx | rt  j j |  r| j | | | | | |  } | j |  n. | j | | | | | | |  } | j |  Wqt k
 r} d	 } | rd| n d
 } | j |  t d | | d |  qXqWt |  } | | _ | j | _  | SWd QXd S(   s  
    Upload one or more files to a remote host.

    As with the OpenSSH ``sftp`` program, `.put` will overwrite pre-existing
    remote files without requesting confirmation.

    `~fabric.operations.put` returns an iterable containing the absolute file
    paths of all remote files uploaded. This iterable also exhibits a
    ``.failed`` attribute containing any local file paths which failed to
    upload (and may thus be used as a boolean test.) You may also check
    ``.succeeded`` which is equivalent to ``not .failed``.

    ``local_path`` may be a relative or absolute local file or directory path,
    and may contain shell-style wildcards, as understood by the Python ``glob``
    module (give ``use_glob=False`` to disable this behavior).  Tilde expansion
    (as implemented by ``os.path.expanduser``) is also performed.

    ``local_path`` may alternately be a file-like object, such as the result of
    ``open('path')`` or a ``StringIO`` instance.

    .. note::
        In this case, `~fabric.operations.put` will attempt to read the entire
        contents of the file-like object by rewinding it using ``seek`` (and
        will use ``tell`` afterwards to preserve the previous file position).

    ``remote_path`` may also be a relative or absolute location, but applied to
    the remote host. Relative paths are relative to the remote user's home
    directory, but tilde expansion (e.g. ``~/.ssh/``) will also be performed if
    necessary.

    An empty string, in either path argument, will be replaced by the
    appropriate end's current working directory.

    While the SFTP protocol (which `put` uses) has no direct ability to upload
    files to locations not owned by the connecting user, you may specify
    ``use_sudo=True`` to work around this. When set, this setting causes `put`
    to upload the local files to a temporary location on the remote end
    (defaults to remote user's ``$HOME``; this may be overridden via
    ``temp_dir``), and then use `sudo` to move them to ``remote_path``.

    In some use cases, it is desirable to force a newly uploaded file to match
    the mode of its local counterpart (such as when uploading executable
    scripts). To do this, specify ``mirror_local_mode=True``.

    Alternately, you may use the ``mode`` kwarg to specify an exact mode, in
    the same vein as ``os.chmod``, such as an exact octal number (``0755``) or
    a string representing one (``"0755"``).

    `~fabric.operations.put` will honor `~fabric.context_managers.cd`, so
    relative values in ``remote_path`` will be prepended by the current remote
    working directory, if applicable. Thus, for example, the below snippet
    would attempt to upload to ``/tmp/files/test.txt`` instead of
    ``~/files/test.txt``::

        with cd('/tmp'):
            put('/path/to/local/test.txt', 'files')

    Use of `~fabric.context_managers.lcd` will affect ``local_path`` in the
    same manner.

    Examples::

        put('bin/project.zip', '/tmp/project.zip')
        put('*.py', 'cgi-bin/')
        put('index.html', 'index.html', mode=0755)

    .. note::
        If a file-like object such as StringIO has a ``name`` attribute, that
        will be used in Fabric's printed output instead of the default
        ``<file obj>``
    .. versionchanged:: 1.0
        Now honors the remote working directory as manipulated by
        `~fabric.context_managers.cd`, and the local working directory as
        manipulated by `~fabric.context_managers.lcd`.
    .. versionchanged:: 1.0
        Now allows file-like objects in the ``local_path`` argument.
    .. versionchanged:: 1.0
        Directories may be specified in the ``local_path`` argument and will
        trigger recursive uploads.
    .. versionchanged:: 1.0
        Return value is now an iterable of uploaded remote file paths which
        also exhibits the ``.failed`` and ``.succeeded`` attributes.
    .. versionchanged:: 1.5
        Allow a ``name`` attribute on file-like objects for log output
    .. versionchanged:: 1.7
        Added ``use_glob`` option to allow disabling of globbing.
    t   readt   .t   ~i   t   cwdt   /s'   '%s' is not a valid local path or glob.s   '%s' is not a directorys3   put() encountered an exception while uploading '%s's
   <StringIO>RP   t	   exceptionN(!   t   ost   getcwdR=   RN   R`   R   R   t   host_stringR   t	   normalizeRQ   R    t   patht   isabsRJ   Rc   t   rstript
   expanduserR   R   t   existst
   ValueErrorR<   t   isdirt   put_dirt   extendt   putt   appendRO   R   R,   t   failedt	   succeeded(   t
   local_patht   remote_patht   use_sudot   mirror_local_modet   modet   use_globt   temp_dirt   local_is_patht   ftpt   homet   namest   errt   remote_pathst   failed_local_pathst   lpatht   pR]   RD   t   failuret   ret(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyRs      s\    ["		
(	c         C  s  | p	 d } t  | d  o' t | j  } | rC t | t  } n  t t j  } t |  W} | j d  } |  j	 d  r |  j
 d | d  }  n  | r t j j |  } n  t j j |   st j d  rt j j d  } | j
 d d	  } | d |  }  qt j | |   }  n  g  } g  }	 y| j |   sSd
 |  k sSd |  k re| j |   }
 n	 |  g }
 | st |
  d k s| j |
 d  rt d t j |  f  qn  x |
 D]} }  | j |   r| j |  | | |  } | j |  q| j |  | | | t j j |   |  } | r| j |  qqWWn= t k
 r~} |	 j |   d } t d | |  d |  n Xt | r| n g   } |	 | _ | j | _ | SWd QXd S(   s  
    Download one or more files from a remote host.

    `~fabric.operations.get` returns an iterable containing the absolute paths
    to all local files downloaded, which will be empty if ``local_path`` was a
    StringIO object (see below for more on using StringIO). This object will
    also exhibit a ``.failed`` attribute containing any remote file paths which
    failed to download, and a ``.succeeded`` attribute equivalent to ``not
    .failed``.

    ``remote_path`` is the remote file or directory path to download, which may
    contain shell glob syntax, e.g. ``"/var/log/apache2/*.log"``, and will have
    tildes replaced by the remote home directory. Relative paths will be
    considered relative to the remote user's home directory, or the current
    remote working directory as manipulated by `~fabric.context_managers.cd`.
    If the remote path points to a directory, that directory will be downloaded
    recursively.

    ``local_path`` is the local file path where the downloaded file or files
    will be stored. If relative, it will honor the local current working
    directory as manipulated by `~fabric.context_managers.lcd`. It may be
    interpolated, using standard Python dict-based interpolation, with the
    following variables:

    * ``host``: The value of ``env.host_string``, eg ``myhostname`` or
      ``user@myhostname-222`` (the colon between hostname and port is turned
      into a dash to maximize filesystem compatibility)
    * ``dirname``: The directory part of the remote file path, e.g. the
      ``src/projectname`` in ``src/projectname/utils.py``.
    * ``basename``: The filename part of the remote file path, e.g. the
      ``utils.py`` in ``src/projectname/utils.py``
    * ``path``: The full remote path, e.g. ``src/projectname/utils.py``.

    While the SFTP protocol (which `get` uses) has no direct ability to download
    files from locations not owned by the connecting user, you may specify
    ``use_sudo=True`` to work around this. When set, this setting allows `get`
    to copy (using sudo) the remote files to a temporary location on the remote end
    (defaults to remote user's ``$HOME``; this may be overridden via ``temp_dir``),
    and then download them to ``local_path``.

    .. note::
        When ``remote_path`` is an absolute directory path, only the inner
        directories will be recreated locally and passed into the above
        variables. So for example, ``get('/var/log', '%(path)s')`` would start
        writing out files like ``apache2/access.log``,
        ``postgresql/8.4/postgresql.log``, etc, in the local working directory.
        It would **not** write out e.g.  ``var/log/apache2/access.log``.

        Additionally, when downloading a single file, ``%(dirname)s`` and
        ``%(path)s`` do not make as much sense and will be empty and equivalent
        to ``%(basename)s``, respectively. Thus a call like
        ``get('/var/log/apache2/access.log', '%(path)s')`` will save a local
        file named ``access.log``, not ``var/log/apache2/access.log``.

        This behavior is intended to be consistent with the command-line
        ``scp`` program.

    If left blank, ``local_path`` defaults to ``"%(host)s/%(path)s"`` in order
    to be safe for multi-host invocations.

    .. warning::
        If your ``local_path`` argument does not contain ``%(host)s`` and your
        `~fabric.operations.get` call runs against multiple hosts, your local
        files will be overwritten on each successive run!

    If ``local_path`` does not make use of the above variables (i.e. if it is a
    simple, explicit file path) it will act similar to ``scp`` or ``cp``,
    overwriting pre-existing files if necessary, downloading into a directory
    if given (e.g. ``get('/path/to/remote_file.txt', 'local_directory')`` will
    create ``local_directory/remote_file.txt``) and so forth.

    ``local_path`` may alternately be a file-like object, such as the result of
    ``open('path', 'w')`` or a ``StringIO`` instance.

    .. note::
        Attempting to `get` a directory into a file-like object is not valid
        and will result in an error.

    .. note::
        This function will use ``seek`` and ``tell`` to overwrite the entire
        contents of the file-like object, in order to be consistent with the
        behavior of `~fabric.operations.put` (which also considers the entire
        file). However, unlike `~fabric.operations.put`, the file pointer will
        not be restored to its previous location, as that doesn't make as much
        sense here and/or may not even be possible.

    .. note::
        If a file-like object such as StringIO has a ``name`` attribute, that
        will be used in Fabric's printed output instead of the default
        ``<file obj>``

    .. versionchanged:: 1.0
        Now honors the remote working directory as manipulated by
        `~fabric.context_managers.cd`, and the local working directory as
        manipulated by `~fabric.context_managers.lcd`.
    .. versionchanged:: 1.0
        Now allows file-like objects in the ``local_path`` argument.
    .. versionchanged:: 1.0
        ``local_path`` may now contain interpolated path- and host-related
        variables.
    .. versionchanged:: 1.0
        Directories may be specified in the ``remote_path`` argument and will
        trigger recursive downloads.
    .. versionchanged:: 1.0
        Return value is now an iterable of downloaded local file paths, which
        also exhibits the ``.failed`` and ``.succeeded`` attributes.
    .. versionchanged:: 1.5
        Allow a ``name`` attribute on file-like objects for log output
    s   %(host)s/%(path)st   writeRa   Rb   i   Rc   Rd   s   \ RH   t   *t   ?i    s@   [%s] %s is a glob or directory, but local_path is a file object!s5   get() encountered an exception while downloading '%s'RP   Re   N(    R=   RN   R   R   R   R   Rh   R   Ri   RQ   R    Rf   Rj   Rm   Rk   RJ   Rc   Rl   t	   posixpatht   joinRp   R   R<   R   t   get_dirRr   t   basenameRt   RO   R,   Ru   Rv   (   Rx   Rw   Ry   R}   R~   R   R   t   remote_path_escapedt   local_filest   failed_remote_filesR   R^   R]   RD   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyRJ     sV    p	%*	c         C  s=   | d  k r d St |  j   r/ d | } n  d |  | f S(   NR:   s   #%ss    %s "%s"(   RL   R%   t   isdigit(   t   argumentR\   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _sudo_prefix_argumentV  s
    c         C  sL   t  j t  } |  d k	 s% | d k	 rH d | t d |   t d |  f S| S(   sS   
    Return ``env.sudo_prefix`` with ``user``/``group`` inserted if necessary.
    s   %s%s%s s   -us   -gN(   R   t   sudo_prefixRL   R   (   t   usert   groupRC   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _sudo_prefix^  s    c         C  s   | r t  j r t } n  | d k r. d } n
 | d 7} | rm t  j d } | r` t |   }  n  d |  }  n d } | | |  S(   sN   
    Conditionally wrap given command in env.shell (while honoring sudo.)
    R:   RH   s   "%s"N(   R   t	   use_shellt   FalseRL   t   shellR#   (   R4   t   shell_escapeR   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _shell_wrapk  s    		
c         C  s   t  t j  } | d k r$ t j n t j } t s9 d n d } | rb | j d d | | f  n  d } | r | j |  | n d } | |  S(   s  
    Prefixes ``command`` with all prefixes found in ``env.command_prefixes``.

    ``env.command_prefixes`` is a list of strings which is modified by the
    `~fabric.context_managers.prefix` context manager.

    This function also handles a special-case prefix, ``cwd``, used by
    `~fabric.context_managers.cd`. The ``which`` kwarg should be a string,
    ``"local"`` or ``"remote"``, which will determine whether ``cwd`` or
    ``lcwd`` is used.
    t   remotes    >/dev/nullR:   i    s   cd %s%ss    && (   R/   R   t   command_prefixesRc   t   lcwdR   t   insertR   (   R4   t   whicht   prefixesRc   t   redirectt   glueRC   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _prefix_commands  s    c           s   i  } t  j } | rv t  j d k r1 d | } n8 t  j d k rM d | } n t  j d k ri d | } n  | | d <n  | j t  j  | r d \   } t r | r d	   n d
 } d j   f d   | j   D  } d | | f } n d } | |  S(   sv  
    Prefixes ``command`` with any shell environment vars, e.g. ``PATH=foo ``.

    Currently, this only applies the PATH updating implemented in
    `~fabric.context_managers.path` and environment variables from
    `~fabric.context_managers.shell_env`.

    Will switch to using Windows style 'SET' commands when invoked by
    ``local()`` and on a Windows localhost.
    Rt   s
   $PATH:"%s"t   prepends
   "%s":$PATHR    s   "%s"t   PATHR:   s   SET s   export RH   c         3  s@   |  ]6 \ } } d    | | d k r* | n	 t  |  f Vq d S(   s	   %s%s="%s"R   N(   R#   (   t   .0t   kt   v(   t   set_cmd(    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pys	   <genexpr>  s   s   %s%s && (   R:   R:   (   R   Rj   t   path_behaviort   updatet	   shell_envR   R   t	   iteritems(   R4   t   localt   env_varsRj   t   exp_cmdt   exportst   shell_env_str(    (   R   s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _prefix_env_vars  s,    		c	         C  s  | p t  j } | p t  j } | d k r3 t j n | } t j }	 t t  j  .| d k rj t j	 } n  |  j
 |  t }
 | r | s t j r t }
 n  |
 r t   \ } } |  j d | d |  n  t   j d d  j   d k } d } t j s| rt j j |   } n  | rD|  j   | rT|  j | d  qTn |  j d |  t d g  d	 |  } t d g  d	 |  } | rd } } n  t d
 t |  d d | d | d | t d t |  d d | d | d | t d t |  |
  f } |	 d k r| }	 n  |	 r|
 rt }	 n  xv t r|  j   r5Pn x | D] } | j   q<Wy t  j! t j"  Wqt# k
 r|	 s  n  |  j$ d  qXqW|  j%   } x% | D] } | j& j'   | j   qW|  j(   | d k	 r| j(   n  | sd j' |  j)   } d j' |  j)   } n  t* j+ rGt* j rG| rG| j, d  sft* j rn| rn| j, d  rnd GHn  | | | f SWd QXd S(   s  
    Execute ``command`` over ``channel``.

    ``pty`` controls whether a pseudo-terminal is created.

    ``combine_stderr`` controls whether we call ``channel.set_combine_stderr``.
    By default, the global setting for this behavior (:ref:`env.combine_stderr
    <combine-stderr>`) is consulted, but you may specify ``True`` or ``False``
    here to override it.

    ``invoke_shell`` controls whether we use ``exec_command`` or
    ``invoke_shell`` (plus a handful of other things, such as always forcing a
    pty.)

    ``capture_buffer_size`` controls the length of the ring-buffers used to
    capture stdout/stderr. (This is ignored if ``invoke_shell=True``, since
    that completely disables capturing overall.)

    Returns a three-tuple of (``stdout``, ``stderr``, ``status``), where
    ``stdout``/``stderr`` are captured output strings and ``status`` is the
    program's return code, if applicable.
    t   widtht   heightt   forwardagentt   not   yess   
R4   R\   t   maxlent   outt   recvt   capturet   streamt   timeoutR   t   recv_stderrt   ins   R:   N(-   t   sysR'   t   stderrRL   R   t   command_timeoutt   remote_interruptR   t   stdint   combine_stderrt   set_combine_stderrt   Truet   always_use_ptyR   R   t   get_ptyR   RJ   t   lowert   forward_agentR   t   agentt   AgentRequestHandlert   invoke_shellt   sendallt   exec_commandR   R   R	   R
   t   exit_status_readyt   raise_if_neededt   timet   sleept   io_sleept   KeyboardInterruptt   sendt   recv_exit_statust   threadR   t   closeRK   R   t   runningRR   (   t   channelR4   t   ptyR   R   R'   R   R   t   capture_buffer_sizeR   t	   using_ptyt   rowst   colst   config_agentt   forwardt
   stdout_buft
   stderr_buft   workerst   workert   status(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _execute  s|    		!
			
	c         C  s,   t  d t   d |  d t d t d t  d S(   s9  
    Invoke a fully interactive shell on the remote end.

    If ``command`` is given, it will be sent down the pipe before handing
    control over to the invoking user.

    This function is most useful for when you need to interact with a heavily
    shell-based command or series of commands, such as when debugging or when
    fully interactive recovery is required upon remote program failure.

    It should be considered an easy way to work an interactive shell session
    into the middle of a Fabric script and is *not* a drop-in replacement for
    `~fabric.operations.run`, which is also capable of interacting with the
    remote end (albeit only while its given command is executing) and has much
    stronger programmatic abilities such as error handling and stdout/stderr
    capture.

    Specifically, `~fabric.operations.open_shell` provides a better interactive
    experience than `~fabric.operations.run`, but use of a full remote shell
    prevents Fabric from determining whether programs run within the shell have
    failed, and pollutes the stdout/stderr stream with shell output such as
    login banners, prompts and echoed stdin.

    Thus, this function does not have a return value and will not trigger
    Fabric's failure handling if any remote programs result in errors.

    .. versionadded:: 1.0
    R   R4   R   R   R   N(   R   R   R   (   R4   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt
   open_shellT  s    c           c  s	   d  Vd  S(   N(    (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _noopv  s    c         C  s  t  } | r t } n  | r$ t } n  |   |  } | d k rU t j d t  } n  t t t	 |  d   | | | r t
 | |
  n d  } | r d n d } t j r d t j | | f GHn! t j r d t j | | f GHn  t d t   d | d | d	 | d
 t d | d |	 d | d |  	\ } } } t |  } t |  } t | _ | | _ | | _ | t j k rt | _ d | | f } t j r| d | 7} n | d | | f 7} t d | d | d |  n  | | _ | j | _ | | _ | SWd QXd S(   sP   
    Underpinnings of `run` and `sudo`. See their docstrings for more info.
    R   R   t   sudot   runs   [%s] %s: %sR   R4   R   R   R   R'   R   R   R   s4   %s() received nonzero return code %s while executings    '%s'!s   !

Requested: %s
Executed: %sRP   N(   R   t   warn_only_managert   quiet_managerRL   R   RJ   R   R   R   R   R   R   t   debugRh   R   R   R   R   R$   Ru   R4   t   real_commandt   ok_ret_codesR   R   t   return_codeRv   R   (   R4   R   R   R   R   R   R   R   R'   R   R   R   R   R   t   managert   given_commandt   wrapped_commandR   t   result_stdoutt   result_stderrR   R   R   RD   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   _run_command{  sT    		
									c         C  s=   t  |  | | | d | d | d | d | d | d |	 d |
 S(   s  
    Run a shell command on a remote host.

    If ``shell`` is True (the default), `run` will execute the given command
    string via a shell interpreter, the value of which may be controlled by
    setting ``env.shell`` (defaulting to something similar to ``/bin/bash -l -c
    "<command>"``.) Any double-quote (``"``) or dollar-sign (``$``) characters
    in ``command`` will be automatically escaped when ``shell`` is True (unless
    disabled by setting ``shell_escape=False``).

    When ``shell=False``, no shell wrapping or escaping will occur. (It's
    possible to specify ``shell=False, shell_escape=True`` if desired, which
    will still trigger escaping of dollar signs, etc but will not wrap with a
    shell program invocation).

    `run` will return the result of the remote program's stdout as a single
    (likely multiline) string. This string will exhibit ``failed`` and
    ``succeeded`` boolean attributes specifying whether the command failed or
    succeeded, and will also include the return code as the ``return_code``
    attribute. Furthermore, it includes a copy of the requested & actual
    command strings executed, as ``.command`` and ``.real_command``,
    respectively.

    To lessen memory use when running extremely verbose programs (and,
    naturally, when having access to their full output afterwards is not
    necessary!) you may limit how much of the program's stdout/err is stored by
    setting ``capture_buffer_size`` to an integer value.

    .. warning::
        Do not set ``capture_buffer_size`` to any value smaller than the length
        of ``env.sudo_prompt`` or you will likely break the functionality of
        `sudo`! Ditto any user prompts stored in ``env.prompts``.

    .. note::
        This value is used for each buffer independently, so e.g. ``1024`` may
        result in storing a total of ``2048`` bytes if there's data in both
        streams.)

    Any text entered in your local terminal will be forwarded to the remote
    program as it runs, thus allowing you to interact with password or other
    prompts naturally. For more on how this works, see
    :doc:`/usage/interactivity`.

    You may pass ``pty=False`` to forego creation of a pseudo-terminal on the
    remote end in case the presence of one causes problems for the command in
    question. However, this will force Fabric itself to echo any  and all input
    you type while the command is running, including sensitive passwords. (With
    ``pty=True``, the remote pseudo-terminal will echo for you, and will
    intelligently handle password-style prompts.) See :ref:`pseudottys` for
    details.

    Similarly, if you need to programmatically examine the stderr stream of the
    remote program (exhibited as the ``stderr`` attribute on this function's
    return value), you may set ``combine_stderr=False``. Doing so has a high
    chance of causing garbled output to appear on your terminal (though the
    resulting strings returned by `~fabric.operations.run` will be properly
    separated). For more info, please read :ref:`combine_streams`.

    To ignore non-zero return codes, specify ``warn_only=True``. To both ignore
    non-zero return codes *and* force a command to run silently, specify
    ``quiet=True``.

    To override which local streams are used to display remote stdout and/or
    stderr, specify ``stdout`` or ``stderr``. (By default, the regular
    ``sys.stdout`` and ``sys.stderr`` Python stream objects are used.)

    For example, ``run("command", stderr=sys.stdout)`` would print the remote
    standard error to the local standard out, while preserving it as its own
    distinct attribute on the return value (as per above.) Alternately, you
    could even provide your own stream objects or loggers, e.g. ``myout =
    StringIO(); run("command", stdout=myout)``.

    If you want an exception raised when the remote program takes too long to
    run, specify ``timeout=N`` where ``N`` is an integer number of seconds,
    after which to time out. This will cause ``run`` to raise a
    `~fabric.exceptions.CommandTimeout` exception.

    If you want to disable Fabric's automatic attempts at escaping quotes,
    dollar signs etc., specify ``shell_escape=False``.

    Examples::

        run("ls /var/www/")
        run("ls /home/myuser", shell=False)
        output = run('ls /var/www/site1')
        run("take_a_long_time", timeout=5)

    .. versionadded:: 1.0
        The ``succeeded`` and ``stderr`` return value attributes, the
        ``combine_stderr`` kwarg, and interactive behavior.

    .. versionchanged:: 1.0
        The default value of ``pty`` is now ``True``.

    .. versionchanged:: 1.0.2
        The default value of ``combine_stderr`` is now ``None`` instead of
        ``True``. However, the default *behavior* is unchanged, as the global
        setting is still ``True``.

    .. versionadded:: 1.5
        The ``quiet``, ``warn_only``, ``stdout`` and ``stderr`` kwargs.

    .. versionadded:: 1.5
        The return value attributes ``.command`` and ``.real_command``.

    .. versionadded:: 1.6
        The ``timeout`` argument.

    .. versionadded:: 1.7
        The ``shell_escape`` argument.

    .. versionadded:: 1.11
        The ``capture_buffer_size`` argument.
    R   R   R'   R   R   R   R   (   R   (   R4   R   R   R   R   R   R'   R   R   R   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR     s    vc         C  s^   t  |  | | | d t d | r$ | n t j d |	 d | d | d | d | d |
 d	 | d
 | 
S(   sy  
    Run a shell command on a remote host, with superuser privileges.

    `sudo` is identical in every way to `run`, except that it will always wrap
    the given ``command`` in a call to the ``sudo`` program to provide
    superuser privileges.

    `sudo` accepts additional ``user`` and ``group`` arguments, which are
    passed to ``sudo`` and allow you to run as some user and/or group other
    than root.  On most systems, the ``sudo`` program can take a string
    username/group or an integer userid/groupid (uid/gid); ``user`` and
    ``group`` may likewise be strings or integers.

    You may set :ref:`env.sudo_user <sudo_user>` at module level or via
    `~fabric.context_managers.settings` if you want multiple ``sudo`` calls to
    have the same ``user`` value. An explicit ``user`` argument will, of
    course, override this global setting.

    Examples::

        sudo("~/install_script.py")
        sudo("mkdir /var/www/new_docroot", user="www-data")
        sudo("ls /home/jdoe", user=1001)
        result = sudo("ls /tmp/")
        with settings(sudo_user='mysql'):
            sudo("whoami") # prints 'mysql'

    .. versionchanged:: 1.0
        See the changed and added notes for `~fabric.operations.run`.

    .. versionchanged:: 1.5
        Now honors :ref:`env.sudo_user <sudo_user>`.

    .. versionadded:: 1.5
        The ``quiet``, ``warn_only``, ``stdout`` and ``stderr`` kwargs.

    .. versionadded:: 1.5
        The return value attributes ``.command`` and ``.real_command``.

    .. versionadded:: 1.7
        The ``shell_escape`` argument.

    .. versionadded:: 1.11
        The ``capture_buffer_size`` argument.
    R   R   R   R   R   R'   R   R   R   R   (   R   R   R   t	   sudo_user(   R4   R   R   R   R   R   R   R'   R   R   R   R   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR   D  s    1c         C  s  |  } t  |  d t } t | d  } t j r< d | GHn t j rQ d | GHn  d
 } | rr t j } t j } n< t	 t
 j d  } t j r d
 n | } t j r d
 n | } zY t r | n | g }	 t j |	 d t d | d | d | d	 t }
 |
 j   \ } } Wd
 | d
 k	 r#| j   n  Xt | r9| j   n d  } t | rW| j   n d  } | | _ | | _ t | _ |
 j | _ | | _ |
 j t j k rt | _ d |
 j |  f } t d | d | d |  n  | j | _ | S(   s	  
    Run a command on the local system.

    `local` is simply a convenience wrapper around the use of the builtin
    Python ``subprocess`` module with ``shell=True`` activated. If you need to
    do anything special, consider using the ``subprocess`` module directly.

    ``shell`` is passed directly to `subprocess.Popen
    <http://docs.python.org/library/subprocess.html#subprocess.Popen>`_'s
    ``execute`` argument (which determines the local shell to use.)  As per the
    linked documentation, on Unix the default behavior is to use ``/bin/sh``,
    so this option is useful for setting that value to e.g.  ``/bin/bash``.

    `local` is not currently capable of simultaneously printing and
    capturing output, as `~fabric.operations.run`/`~fabric.operations.sudo`
    do. The ``capture`` kwarg allows you to switch between printing and
    capturing as necessary, and defaults to ``False``.

    When ``capture=False``, the local subprocess' stdout and stderr streams are
    hooked up directly to your terminal, though you may use the global
    :doc:`output controls </usage/output_controls>` ``output.stdout`` and
    ``output.stderr`` to hide one or both if desired. In this mode, the return
    value's stdout/stderr values are always empty.

    When ``capture=True``, you will not see any output from the subprocess in
    your terminal, but the return value will contain the captured
    stdout/stderr.

    In either case, as with `~fabric.operations.run` and
    `~fabric.operations.sudo`, this return value exhibits the ``return_code``,
    ``stderr``, ``failed``, ``succeeded``, ``command`` and ``real_command``
    attributes. See `run` for details.

    `~fabric.operations.local` will honor the `~fabric.context_managers.lcd`
    context manager, allowing you to control its current working directory
    independently of the remote end (which honors
    `~fabric.context_managers.cd`).

    .. versionchanged:: 1.0
        Added the ``succeeded`` and ``stderr`` attributes.
    .. versionchanged:: 1.0
        Now honors the `~fabric.context_managers.lcd` context manager.
    .. versionchanged:: 1.0
        Changed the default value of ``capture`` from ``True`` to ``False``.
    .. versionadded:: 1.9
        The return value attributes ``.command`` and ``.real_command``.
    R   s   [localhost] local: %ss   [localhost] local: s   w+R   R'   R   t
   executablet	   close_fdsNR:   sB   local() encountered an error (return code %s) while executing '%s'RP   (   R   R   R   R   R   R   RL   t
   subprocesst   PIPEt   openRf   t   devnullR'   R   R   t   Popent   communicateR   R$   RK   R4   R   R   Ru   t
   returncodeR   R   R   R   Rv   (   R4   R   R   R   t   with_envR   t   dev_nullt
   out_streamt
   err_streamt   cmd_argR   R'   R   R   R   RD   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR   ~  sF    0			
					ix   t   rebootc         C  s   d } t  t t |   t |    } t t d  d | d | 8 | rS t n t |  t j d  t	 j
 t j  Wd QXd S(   sq  
    Reboot the remote system.

    Will temporarily tweak Fabric's reconnection settings (:ref:`timeout` and
    :ref:`connection-attempts`) to ensure that reconnection does not give up
    for at least ``wait`` seconds.

    .. note::
        As of Fabric 1.4, the ability to reconnect partway through a session no
        longer requires use of internal APIs.  While we are not officially
        deprecating this function, adding more features to it will not be a
        priority.

        Users who want greater control
        are encouraged to check out this function's (6 lines long, well
        commented) source code and write their own adaptation using different
        timeout/attempt values or additional logic.

    .. versionadded:: 0.9.2
    .. versionchanged:: 1.4
        Changed the ``wait`` kwarg to be optional, and refactored to leverage
        the new reconnection functionality; it may not actually have to wait
        for ``wait`` seconds before reconnecting.
    .. versionchanged:: 1.11
        Added ``use_sudo`` as a kwarg. Maintained old functionality by setting
        the default value to True.
    i   R   R   t   connection_attemptsN(   t   intt   roundt   floatR   R   R   R   R   R   R   t   connectR   Rh   (   t   waitR4   Ry   R   t   attempts(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyR    s    "
(I   R*   t
   __future__R    Rf   t   os.pathR   RS   R  R   R   R   t
   contextlibR   R   t   fabric.context_managersR   R   R   R   R   R   R   t	   fabric.ioR	   R
   t   fabric.networkR   R   R   t   fabric.sftpR   t   fabric.stateR   R   R   R   R   t   fabric.thread_handlingR   t   fabric.utilsR   R   R   R   R   R   R   R   R#   R%   R$   R/   R,   RG   RL   R_   R   R   Rs   RJ   R   R   R   R   R   R   R   R   R   R   R   R   R  (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/fabric/operations.pyt   <module>   sj   ((:				Er			.!	Iz7]