o
    wOi                     @   s  d dl Z ddlmZ ddlmZ e eZzd dl mZ W n e	y/   G dd de j
ZY nw ee  G dd	 d	eZG d
d deZG dd deeZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZ G d,d- d-eZ!G d.d/ d/eZ"zd d0l#m$Z$ e$%  W dS  e	y   Y dS w )1    N   )Client)Lock)NullHandlerc                   @   s   e Zd Zdd ZdS )r   c                 C   s   d S N )selfrecordr   r   A/home/ubuntu/.local/lib/python3.10/site-packages/etcd/__init__.pyemit   s   zNullHandler.emitN)__name__
__module____qualname__r   r   r   r   r
   r      s    r   c                	   @   sn   e Zd ZdddddddddZdddZdd Zddd	Zed
d Zedd Z	dd Z
dd Zdd ZdS )
EtcdResultNF)keyvalue
expirationttlmodifiedIndexcreatedIndexnewKeydirc                 K   s   || _ | j D ]\}}||v rt| |||  qt| || qg | _| jr/d|v r/|d | _|rDtd|d| _| jjrF| jsHd| _dS dS dS dS )a  
        Creates an EtcdResult object.

        Args:
            action (str): The action that resulted in key creation

            node (dict): The dictionary containing all node information.

            prevNode (dict): The dictionary containing previous node information.

        nodesN)nodeT)action_node_propsitemssetattr	_childrenr   r   
_prev_node)r   r   r   prevNodekwdargsr   defaultr   r   r
   __init__   s   

zEtcdResult.__init__c                 C   s0   |  }t|dd| _t|dd| _d S )Nzx-etcd-indexr   zx-raft-index)
getheadersintget
etcd_index
raft_index)r   responseheadersr   r   r
   parse_headers=   s   zEtcdResult.parse_headersc                 c   sN    | j s	| V  dS |s| V  | j D ]}td|}|j|dD ]}|V  qqdS )z
        Get all the subtree resulting from a recursive=true call to etcd.

        Args:
            leaves_only (bool): if true, only value nodes are returned


        Nleaves_only)r   r   get_subtree)r   r-   nr   childr   r   r
   r.   B   s   	

zEtcdResult.get_subtreec                 C   s   | j ddS )NTr,   )r.   r   r   r   r
   leavesY   s   zEtcdResult.leavesc                 C   s   | j S )z+ Deprecated, use EtcdResult.leaves instead )r2   r1   r   r   r
   children]   s   zEtcdResult.childrenc                 C   s^   t | t |ur
dS | j D ]}zt| |}t||}||kr$W  dS W q   Y  dS dS )NFT)typer   keysgetattr)r   otherkabr   r   r
   __eq__b   s   

zEtcdResult.__eq__c                 C   s   |  | S r   )r;   )r   r7   r   r   r
   __ne__o   s   zEtcdResult.__ne__c                 C   s   d| j | jf S )Nz%s(%r))	__class____dict__r1   r   r   r
   __repr__r   s   zEtcdResult.__repr__NNN)F)r   r   r   r   r#   r+   r.   propertyr2   r3   r;   r<   r?   r   r   r   r
   r      s(    



r   c                       "   e Zd ZdZd fdd	Z  ZS )EtcdExceptionz!
    Generic Etcd Exception.
    Nc                    s   t t| | || _d S r   )superrC   r#   payload)r   messagerE   r=   r   r
   r#   {   s   
zEtcdException.__init__)NNr   r   r   __doc__r#   __classcell__r   r   rG   r
   rC   v   s    rC   c                   @      e Zd ZdZdS )EtcdValueErrorz3
    Base class for Etcd value-related errors.
    Nr   r   r   rI   r   r   r   r
   rL          rL   c                   @   rK   )EtcdCompareFailedz"
    Compare-and-swap failure
    NrM   r   r   r   r
   rO      rN   rO   c                   @   rK   )EtcdClusterIdChangedz
    The etcd cluster ID changed.  This may indicate the cluster was replaced
    with a backup.  Raised to prevent waiting on an etcd_index that was only
    valid on the old cluster.
    NrM   r   r   r   r
   rP      s    rP   c                   @   rK   )EtcdKeyErrorz)
    Etcd Generic KeyError Exception
    NrM   r   r   r   r
   rQ      rN   rQ   c                   @   rK   )EtcdKeyNotFoundz,
    Etcd key not found exception (100)
    NrM   r   r   r   r
   rR      rN   rR   c                   @   rK   )EtcdNotFilez)
    Etcd not a file exception (102)
    NrM   r   r   r   r
   rS      rN   rS   c                   @   rK   )
EtcdNotDirz.
    Etcd not a directory exception (104)
    NrM   r   r   r   r
   rT      rN   rT   c                   @   rK   )EtcdAlreadyExistz,
    Etcd already exist exception (105)
    NrM   r   r   r   r
   rU      rN   rU   c                   @   rK   )EtcdEventIndexClearedzB
    Etcd event index is outdated and cleared exception (401)
    NrM   r   r   r   r
   rV      rN   rV   c                       rB   )EtcdConnectionFailedz$
    Connection to etcd failed.
    Nc                    s   t t| j||d || _d S )N)rF   rE   )rD   rW   r#   cause)r   rF   rE   rX   rG   r   r
   r#      s   
zEtcdConnectionFailed.__init__r@   rH   r   r   rG   r
   rW      s    rW   c                   @   rK   )EtcdInsufficientPermissionsz=
    Request failed because of insufficient permissions.
    NrM   r   r   r   r
   rY      rN   rY   c                   @   rK   )EtcdWatchTimedOutz7
    A watch timed out without returning a result.
    NrM   r   r   r   r
   rZ      rN   rZ   c                   @   rK   )EtcdWatcherClearedz2
    Watcher is cleared due to etcd recovery.
    NrM   r   r   r   r
   r[      rN   r[   c                   @   rK   )EtcdLeaderElectionInProgressz<
    Request failed due to in-progress leader election.
    NrM   r   r   r   r
   r\      rN   r\   c                   @   rK   )EtcdRootReadOnlyzA
    Operation is not valid on the root, which is read only.
    NrM   r   r   r   r
   r]      rN   r]   c                   @   rK   )EtcdDirNotEmptyz
    Directory not empty.
    NrM   r   r   r   r
   r^      rN   r^   c                   @   rK   )EtcdLockExpiredzI
    Our lock apparently expired while we were trying to acquire it.
    NrM   r   r   r   r
   r_      rN   r_   c                   @   s   e Zd Zi dedededededede	de
d	ed
edededededededeeeeeedZedd ZdS )	EtcdErrord   e   f   h   i   k   l   n                              )      i-  i    c                 C   sx   | d}| d}| d}d||}| d}|dkr!d}n|dkr'd	}| j |t}t|tr8|||||)
z
        Decodes the error and throws the appropriate error message

        :param payload: The decoded JSON error payload as a dict.
        	errorCoderF   rX   z{} : {}statusi  ra   rt   rh   )r&   formaterror_exceptionsrC   
issubclass)clsrE   
error_coderF   rX   msgrv   excr   r   r
   handle  s   





zEtcdError.handleN)r   r   r   rR   rO   rS   rT   rU   r]   r^   rY   rL   r\   r[   rV   rx   classmethodr~   r   r   r   r
   r`      sX    	 r`   )	pyopenssl)&loggingclientr   lockr   	getLoggerr   _logr   ImportErrorHandler
addHandlerobjectr   	ExceptionrC   
ValueErrorrL   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rY   rZ   r[   r\   r]   r^   r_   r`   urllib3.contribr   inject_into_urllib3r   r   r   r
   <module>   sH    
c
	
=