o
    'Th#                     @   s   d dl Z d dlZd dlZd dlmZ dZdZdZejd  dkZ	e	r)d dl
Z
e
jZnd dlZejjZG dd dZd	d
 Zdd ZG dd deZdS )    N)clientz:return:z:param bool follow:List   c                   @   s   e Zd Zdd ZdS )SimpleNamespacec                 K   s   | j | d S N)__dict__update)selfkwargs r   W/home/air/segue/gemini/back/venv/lib/python3.10/site-packages/kubernetes/watch/watch.py__init__+   s   zSimpleNamespace.__init__N)__name__
__module____qualname__r   r   r   r   r   r   )   s    r   c                 C   s:   t |  D ]}|tr|ttd     S qdS )N )pydocgetdoc
splitlines
startswithPYDOC_RETURN_LABELlenstrip)funcliner   r   r   _find_return_type/   s
   
r   c                 c   s    t  }| jd ddD ]S}t|tr|| nt|tr&||d n
tdt| d|	d}|dkr^|d | j
ddd	}||d
 d  }|rR|V  ndV  |	d}|dks9qd S )NF)amtdecode_contentzutf-8zReceived invalid segment type, z-, from stream. Accepts only 'str' or 'bytes'.   
replace)errors   r   )	bytearraystream
isinstancebytesextendstrencode	TypeErrortypefinddecode)respbuffersegmentnext_newliner   r   r   r   iter_resp_lines6   s.   



r2   c                   @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )WatchNc                 C   s    || _ d| _t | _d | _d S )NF)_raw_return_type_stopr   	ApiClient_api_clientresource_version)r	   return_typer   r   r   r   X   s   

zWatch.__init__c                 C   s
   d| _ d S )NT)r5   )r	   r   r   r   stop^   s   
z
Watch.stopc                 C   s4   | j r| j S t|}|tr|d tt  S |S r   )r4   r   endswithTYPE_LIST_SUFFIXr   )r	   r   r9   r   r   r   get_return_typea   s   
zWatch.get_return_typec                 C   s   t t|v r	dS dS )Nfollowwatch)PYDOC_FOLLOW_PARAMr   r   )r	   r   r   r   r   get_watch_argument_namei   s   zWatch.get_watch_argument_namec                 C   s   |r|  rd S z^t|}|d |d< |rd|d dkrd|d dkrdtt|d d}| j|||d< t|d drF|d jj	| _	|W S t
|d trdd|d v rdd|d d v rd|d d d | _	|W S  tjyq   Y d S w )	Nobject
raw_objectr+   ERRORBOOKMARK)datametadataresourceVersion)isspacejsonloadsr   dumpsr7   deserializehasattrrG   r8   r%   dictJSONDecodeError)r	   rF   r9   jsobjr   r   r   unmarshal_evento   s(   

zWatch.unmarshal_eventc              	   o   sv   d| _ | |}| |}d||< d|d< d|v r|d | _d|v }d}	 ||i |}znt|D ]Q}	|dkru| |	|}
t|
tro|
d dkro|
d	 }|s[|s[|d
 tkr[d} n)d|d |d f }t	j
j|d
 |dd}|
V  n	|	r{|	V  ndV  | j r nq2W |  |  | jdur| j|d< nd| _ n|  |  | jdur| j|d< w d| _ w | j s|rdS q&)aj  Watch an API resource and stream the result back via a generator.

        Note that watching an API resource can expire. The method tries to
        resume automatically once from the last result, but if that last result
        is too old as well, an `ApiException` exception will be thrown with
        ``code`` 410. In that case you have to recover yourself, probably
        by listing the API resource to obtain the latest state and then
        watching from that state on by setting ``resource_version`` to
        one returned from listing.

        :param func: The API function pointer. Any parameter to the function
                     can be passed after this parameter.

        :return: Event object with these keys:
                   'type': The type of event such as "ADDED", "DELETED", etc.
                   'raw_object': a dict representing the watched object.
                   'object': A model representation of raw_object. The name of
                             model will be determined based on
                             the func's doc string. If it cannot be determined,
                             'object' value will be the same as 'raw_object'.

        Example:
            v1 = kubernetes.client.CoreV1Api()
            watch = kubernetes.watch.Watch()
            for e in watch.stream(v1.list_namespace, resource_version=1127):
                type_ = e['type']
                object_ = e['object']  # object is one of type return_type
                raw_object = e['raw_object']  # raw_object is a dict
                ...
                if should_stop:
                    watch.stop()
        FT_preload_contentr8   timeout_secondsr?   r+   rD   rC   codez%s: %sreasonmessage)statusrW   r   N)r5   r=   rA   r8   r2   rS   r%   rO   HTTP_STATUS_GONEr   restApiExceptioncloserelease_conn)r	   r   argsr
   r9   	watch_argdisable_retriesretry_after_410r.   r   eventrR   rW   r   r   r   r$      sf   "








zWatch.streamr   )	r   r   r   r   r:   r=   rA   rS   r$   r   r   r   r   r3   V   s    
r3   )rJ   r   sys
kubernetesr   r   r@   r<   version_infoPY2httplibGONErZ   http
HTTPStatusr   r   r2   rB   r3   r   r   r   r   <module>   s"    