
    3~h                     j    d dl Z d dl mZmZ ddlmZ ddlmZ ddlmZ  G d de j                        Z	y)	    N)CallTask   )ConnectionCall)NothingToDo)debugc                   *    e Zd ZdZd ZddZd Zd Zy)Executora6  
    `~invoke.executor.Executor` subclass which understands Fabric concepts.

    Designed to work in tandem with Fabric's `@task
    <fabric.tasks.task>`/`~fabric.tasks.Task`, and is capable of acting on
    information stored on the resulting objects -- such as default host lists.

    This class is written to be backwards compatible with vanilla Invoke-level
    tasks, which it simply delegates to its superclass.

    Please see the parent class' `documentation <invoke.executor.Executor>` for
    details on most public API members and object lifecycle.
    c                 z    g }|xs g D ]/  }t        |t              st        |      }|j                  |       1 |S )a  
        Normalize mixed host-strings-or-kwarg-dicts into kwarg dicts only.

        In other words, transforms data taken from the CLI (--hosts, always
        strings) or decorator arguments (may be strings or kwarg dicts) into
        kwargs suitable for creating Connection instances.

        Subclasses may wish to override or extend this to perform, for example,
        database or custom config file lookups (vs this default behavior, which
        is to simply assume that strings are 'host' kwargs).

        :param hosts:
            Potentially heterogenous list of host connection values, as per the
            ``hosts`` param to `.task`.

        :returns: Homogenous list of Connection init kwarg dicts.
        )host)
isinstancedictappend)selfhostsdictsvalues       X/var/www/peopleoo.sandbox-dev.co.uk/venv/lib/python3.12/site-packages/fabric/executor.pynormalize_hostszExecutor.normalize_hosts   sC    $ [b 	 EeT*%(LL		 
     c                 ,    g }g } j                   d   j                  j                  j                  }|r|r|j	                  d      }|D ]  }t        |t              rt        |      }|j                   j                  |j                  d             t        |dd       } j                  |xs |      }|D ]#  }	|j                   j                  ||	             % |s|j                  |       |j                   j                  |j                  d               j                   j                   r^|st#        d       fd}
t        t        |
	            } j                  |      D ]#  }	|j                   j                  ||	             % |S )
Nr   ,)taskF)apply_hostsr   z@Was told to run a command, but not given any hosts to run it on!c                 P    | j                  j                  j                         y N)runcore	remainder)cr   s    r   	anonymousz(Executor.expand_calls.<locals>.anonymousZ   s    dii))*r   )body)r   argsr   r   splitr   r   r   extendexpand_callspregetattrr   r   parameterizepostr   r   )r   callsr   ret	cli_hostshost_strcall
call_hosts
cxn_paramsinit_kwargsr!   anons   `           r   r&   zExecutor.expand_calls2   s{   	99Q<$$**008 s+I 	HD$% JJt((u(EF !w5J--i.E:FJ) A

4,,T;?@A 

4 JJt(((FG/	H2 99 !V + ),-D  $33I> A

4,,T;?@A
r   c                     d}t        |j                  ||             t        |      }|j                  t        |      }|S )ak  
        Parameterize a Call with its Context set to a per-host Connection.

        :param call:
            The generic `.Call` being parameterized.
        :param connection_init_kwargs:
            The dict of `.Connection` init params/kwargs to attach to the
            resulting `.ConnectionCall`.

        :returns:
            `.ConnectionCall`.
        z/Parameterizing {!r} with Connection kwargs {!r})r2   )intowith_)r   formatr   cloner   )r   r/   connection_init_kwargsmsgnew_call_kwargsr8   s         r   r)   zExecutor.parameterizee   sB     @cjj567 +AB

o
Fr   c                     |S r    )r   taskss     r   dedupezExecutor.dedupez   s	    
 r   N)T)__name__
__module____qualname____doc__r   r&   r)   r?   r=   r   r   r
   r
   	   s    41f*r   r
   )
invoker   r   r>   r   
exceptionsr   utilr   r
   r=   r   r   <module>rG      s&      ! # vv vr   