o
    3gi                     @  s@   d dl mZ d dlmZmZmZ G dd dZG dd dZdS )    )annotations)CommandNotFoundProcessExecutionErrorProcessTimedOutc                   @  s   e Zd ZdZdd ZdS )PopenAddonszjThis adds a verify to popen objects to that the correct command is attributed when
    an error is thrown.c                 C  s   t | ddrtd| dt | dd|dur@t|dr/| j|vr-tt | dd| j||dS | j|krBtt | dd| j||dS dS )z5This verifies that the correct command is attributed.
_timed_outFz!Process did not terminate within z secondsargvN__contains__)getattrr   hasattr
returncoder   )selfretcodetimeoutstdoutstderr r   M/home/garg/my-data/venv/lib/python3.10/site-packages/plumbum/machines/base.pyverify   s$   




zPopenAddons.verifyN)__name__
__module____qualname____doc__r   r   r   r   r   r   
   s    r   c                   @  sf   e Zd ZdZdd Zdd Zedd Zejdd ZdddZ	G dd dZ
edd Zdd Zd
S )BaseMachinez`This is a base class for other machines. It contains common code to
    all machines in Plumbum.c                 G  s\   z| | }|j  st||j |W S  ty-   |r,| j|d g|dd R   Y S  w )a  This works a little like the ``.get`` method with dict's, only
        it supports an unlimited number of arguments, since later arguments
        are tried as commands and could also fail. It
        will try to call the first command, and if that is not found,
        it will call the next, etc. Will raise if no file named for the
        executable if a path is given, unlike ``[]`` access.

        Usage::

            best_zip = local.get('pigz','gzip')
        r      N)
executableexistsr   get)r   cmdothercommandscommandr   r   r   r   &   s   
"zBaseMachine.getc                 C  s$   z| |  W dS  t y   Y dS w )zTests for the existence of the command, e.g., ``"ls" in plumbum.local``.
        ``cmd`` can be anything acceptable by ``__getitem__``.
        FT)r   )r   r   r   r   r   r	   <   s   
zBaseMachine.__contains__c                 C  s   | j S )z%This is a wrapper for custom_encodingcustom_encodingr   r   r   r   encodingF   s   zBaseMachine.encodingc                 C  
   || _ d S Nr!   )r   valuer   r   r   r$   K      
/NTc                 C  s   t d)Nz(This is not implemented on this machine!)NotImplementedError)r   r    cwdr   r   appendr   r   r   daemonic_popenO   s   zBaseMachine.daemonic_popenc                   @  s   e Zd Zdd Zdd ZdS )zBaseMachine.Cmdc                 C  r%   r&   )_machine)r   machiner   r   r   __init__S   s   
zBaseMachine.Cmd.__init__c                 C  s&   z| j | W S  ty   t|d w r&   )r.   r   AttributeError)r   namer   r   r   __getattr__V   s
   
zBaseMachine.Cmd.__getattr__N)r   r   r   r0   r3   r   r   r   r   CmdR   s    r4   c                 C  s
   |  | S r&   )r4   r#   r   r   r   r   \   r(   zBaseMachine.cmdc                 C  s   | j   dS )z
        Clear the program cache, which is populated via ``machine.which(progname)`` calls.

        This cache speeds up the lookup of a program in the machines PATH, and is particularly
        effective for RemoteMachines.
        N)_program_cacheclearr#   r   r   r   clear_program_cache`   s   zBaseMachine.clear_program_cache)r)   NNT)r   r   r   r   r   r	   propertyr$   setterr-   r4   r   r7   r   r   r   r   r   "   s    





r   N)
__future__r   plumbum.commands.processesr   r   r   r   r   r   r   r   r   <module>   s    