
     i                     d    S r SSKrSSKrSSKJrJr   " S S\5      r " S S5      rS\	S	\
4S
 jrg)zR
Control Socket Client

Client library for connecting to gunicorn control socket.
    N)ControlProtocolmake_requestc                       \ rS rSrSrSrg)ControlClientError   zControl client error. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       E/var/www/ias/venv/lib/python3.13/site-packages/gunicorn/ctl/client.pyr   r      s    r   r   c                   `    \ rS rSrSrSS\S\4S jjrS rS r	SS	\S
\
S\4S jjrS rS rSrg)ControlClient   z
Client for connecting to gunicorn control socket.

Can be used as a context manager:

    with ControlClient('/path/to/gunicorn.ctl') as client:
        result = client.send_command('show workers')
socket_pathtimeoutc                 8    Xl         X l        SU l        SU l        g)z
Initialize control client.

Args:
    socket_path: Path to the Unix socket
    timeout: Socket timeout in seconds (default 30)
Nr   )r   r   _sock_request_id)selfr   r   s      r   __init__ControlClient.__init__"   s     '
r   c                    U R                   (       a  g [        R                  " [        R                  [        R                  5      U l         U R                   R	                  U R
                  5        U R                   R                  U R                  5        g! [        R                   a'  nSU l         [        SU R                   SU 35      eSnAff = f)zQ
Connect to control socket.

Raises:
    ControlClientError: If connection fails
NzFailed to connect to z: )
r   socketAF_UNIXSOCK_STREAM
settimeoutr   connectr   errorr   )r   es     r   r!   ControlClient.connect/   s     ::	Vv~~v7I7IJDJJJ!!$,,/JJt//0|| 	VDJ$'<T=M=M<NbQRPS%TUU	Vs   BB C+"CCc                     U R                   (       a#   U R                   R                  5         SU l         gg! [         a     Nf = f)zClose connection.N)r   close	Exceptionr   s    r   r&   ControlClient.closeA   s@    ::

  " DJ   s   6 
AANcommandargsreturnc                    U R                   (       d  U R                  5         U =R                  S-  sl        [        U R                  X5      n [        R
                  " U R                   U5        [        R                  " U R                   5      nUR                  S5      S:X  a  [        UR                  SS5      5      eUR                  S0 5      $ ! [         a#  nU R                  5         [        SU 35      eSnAff = f)z
Send command and wait for response.

Args:
    command: Command string (e.g., "show workers")
    args: Optional additional arguments

Returns:
    Response data dictionary

Raises:
    ControlClientError: If communication fails
   zCommunication error: Nstatusr"   zUnknown errordata)r   r!   r   r   r   write_messageread_messager'   r&   r   get)r   r*   r+   requestresponser#   s         r   send_commandControlClient.send_commandJ   s     zzLLNAt//?	B))$**g>&33DJJ?H
 <<!W,$X\\'?%KLL||FB''  	BJJL$'<QC%@AA	Bs   AC 
C>C99C>c                 &    U R                  5         U $ N)r!   r(   s    r   	__enter__ControlClient.__enter__j   s    r   c                 $    U R                  5         g r9   )r&   )r   r+   s     r   __exit__ControlClient.__exit__n   s    

r   )r   r   r   r   )g      >@r9   )r	   r
   r   r   r   strfloatr   r!   r&   listdictr6   r:   r=   r   r   r   r   r   r      sJ    C % V$(C (t (t (@r   r   liner,   c                 0   [         R                  " U 5      nU(       d  S/ 4$ / n/ nU HY  nU(       d>  UR                  5       (       d)  UR                  S5      (       d  UR	                  U5        MH  UR	                  U5        M[     SR                  U5      U4$ )z
Parse a command line into command and args.

Args:
    line: Command line string

Returns:
    Tuple of (command_string, args_list)
 - )shlexsplitisdigit
startswithappendjoin)rC   partscommand_partsr+   parts        r   parse_commandrQ   r   s     KKE2v MDDLLNN4??33G3G  &KK  88M"D((r   )r   rH   r   gunicorn.ctl.protocolr   r   r'   r   r   r?   tuplerQ   r   r   r   <module>rT      sC   
     W Wt) ) )r   