
    ?g9                         d dl Z d dlZd dlmZ d dlmZ  G d de      Z G d de      Z G d d	e      Z	 G d
 de      Z
 G d de      Zy)    N)partial)pformatc                   X    e Zd ZdZ	 	 	 d
dZd Zed        Zd Zed        Z	ddZ
d	 Zy)Resourceza Represents an API resource type, containing the information required to build urls for requests Nc           
      n   d |||fv rt        d      || _        || _        || _        || _        || _        || _        || _        || _        |	| _	        |
xs	 |r|d d nd| _
        || _        || _        |xs i j                         D ci c]  \  }}|t        | fi | c}}| _        || _        y c c}}w )Nz7At least prefix, kind, and api_version must be provided )
ValueErrorprefixgroupapi_versionkind
namespacedverbsname	preferredclientsingular_nameshort_names
categoriesitemsSubresourcesubresources
extra_args)selfr   r   r   r   r   r   r   r   r   singularName
shortNamesr   r   kwargskvs                    P/var/www/openai/venv/lib/python3.12/site-packages/kubernetes/dynamic/resource.py__init__zResource.__init__   s     Kv..VWW
&	$
	")H4d3BiR%$3?3E22L2L2N
2N$!QA{4%1%%2N
 !	
s   	B1c                    d| j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  j                         D ci c]  \  }}||j                          c}}d}|j                  | j                         |S c c}}w )Nr   )_typer   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   to_dictupdater   )r   r   srds       r!   r%   zResource.to_dict2   s    kkZZ++II//ZZII ..**//:>:K:K:Q:Q:ST:SBQ

_:ST
 	
! Us   Cc                 ~    | j                   r&dj                  | j                   | j                        S | j                  S )N{}/{})r   formatr   r   s    r!   group_versionzResource.group_versionE   s0    ::>>$**d.>.>??    c                 x    dj                  | j                  j                  | j                  | j                        S )Nz<{}({}/{})>)r+   	__class____name__r-   r   r,   s    r!   __repr__zResource.__repr__K   s.    ##DNN$;$;T=O=OQUQZQZ[[r.   c                    dj                  | j                  | j                        }| j                  j	                         }dj                  ||      dj                  ||      dj                  ||      dj                  ||      dS )Nr*   z/{}/{}z/{}/namespaces/{{namespace}}/{}z/{}/{}/{{name}}z(/{}/namespaces/{{namespace}}/{}/{{name}})basenamespaced_basefullnamespaced_full)r+   r   r-   r   lower)r   full_prefixresource_names      r!   urlszResource.urlsN   sw    nnT[[$2D2DE		)OOK?@GGUbc%,,[-HIPPQ\^kl	
 	
r.   c                    g }i }| j                   r|r|j                  d       ||d<   |r|j                  d       ||d<   n|j                  d        | j                  dj                  |         j                  di |S )Nr   	namespacer6   r   r4   _ )r   appendr;   joinr+   )r   r   r=   url_typepath_paramss        r!   pathzResource.pathY   sx    ??yOOL)'0K$OOF#"&KOOF#3tyy(+,33BkBBr.   c                 |    || j                   v r| j                   |   S t        t        | j                  |      |       S N)r   r   getattrr   r   r   s     r!   __getattr__zResource.__getattr__f   s9    4$$$$$T**wt{{D1488r.   )NNNNFNNFNNNNNNN)r1   
__module____qualname____doc__r"   r%   propertyr-   r2   r;   rD   rI   r?   r.   r!   r   r      sQ    kGKRVSW!2&    
\ 
 
C9r.   r   c                   ^    e Zd ZdZddZd Zd Zd ZddZddZ	d	 Z
d
 Zd Zd Zd Zd Zy)ResourceListz" Represents a list of API objects Nc                     || _         || _        || _        |xs dj                  |      | _        || _        || _        d | _        y )Nz{}List)r   r   r   r+   r   	base_kindbase_resource_lookup_ResourceList__base_resource)r   r   r   r   rR   r   rS   s          r!   r"   zResourceList.__init__o   sD    
&6HOOI6	"$8!#r.   c                    | j                   r| j                   S | j                  rA | j                  j                  j                  di | j                  | _         | j                   S | j
                  rW| j                  j                  j	                  | j                  | j                  | j
                        | _         | j                   S y )N)r   r   r   r?   )rT   rS   r   	resourcesgetrR   r   r   r,   s    r!   base_resourcezResourceList.base_resourcex   s    '''&&#<4;;#8#8#<#<#Yt?X?X#YD '''^^#';;#8#8#<#<4::[_[k[krv  sA  sA#<  $BD '''r.   c                 $   |t        d      |d   }|d   }|j                  d      }|st        d      | j                  |k7  r%t        dj                  | j                  |            |||D cg c]  }| j	                  |       c}dS c c}w )aN   Takes a List body and return a dictionary with the following structure:
            {
                'api_version': str,
                'kind': str,
                'items': [{
                    'resource': Resource,
                    'name': str,
                    'namespace': str,
                }]
            }
        z>You must provide a body when calling methods on a ResourceList
apiVersionr   r   zVThe `items` field in the body must be populated when calling methods on a ResourceListzXMethods on a {} must be called with a body containing the same kind. Received {} instead)r   r   r   )r
   rW   r   r+   _item_to_resource)r   bodyr   r   r   items         r!   _items_to_resourcesz ResourceList._items_to_resources   s     <]^^<(F|!uvv99w~~  @D  @I  @I  KO  P  Q  Q '?DEutd,,T2uE
 	
 Fs   0Bc                 R   |j                  di       }| j                         }|s_|j                  d| j                        }|j                  d| j                        }| j                  j
                  j                  ||      }|||j                  d      |j                  d      dS )NmetadatarZ   r   )r   r   r   r=   )resource
definitionr   r=   )rW   rX   r   rR   r   rV   )r   r]   r`   ra   r   r   s         r!   r[   zResourceList._item_to_resource   s    88J+%%'((<1A1ABK88FDNN3D{{,,00[t0TH LL(!k2	
 	
r.   c           	         |rt        d      | j                  |      }t        j                  |      }|d   D cg c]2  } |d   j                  d|d   |d   xs |d|j                         4 c}|d<   t        | |      S c c}w NzEOperations on ResourceList objects do not support the `name` argumentr   ra   r   r=   r   r=   r?   )r
   r^   copydeepcopyrW   r%   ResourceInstancer   r\   r   r=   r   resource_listresponser]   s           r!   rW   zResourceList.get   s    dee006==& &g.
. !D  gd6ld;>O>\S\g`fgooq.
  h//	
   7Bc           	         |rt        d      | j                  |      }t        j                  |      }|d   D cg c]2  } |d   j                  d|d   |d   xs |d|j                         4 c}|d<   t        | |      S c c}w rd   )r
   r^   rf   rg   deleter%   rh   ri   s           r!   rn   zResourceList.delete   s    dee006==& &g.
. $D##jfkARA_V_jcijrrt.
  h//	
rl   c           	          | j                  |      }t        j                  |      }|d   D cg c]*  } t        |d   |      dd|d   i|j	                         , c}|d<   t        | |      S c c}w )Nr   ra   r\   rb   r?   )r^   rf   rg   rG   r%   rh   )r   verbr\   r   rj   rk   r]   s          r!   verb_mapperzResourceList.verb_mapper   s    006==& &g.
. ,GD$d+Nl1CNvNVVX.
  h//	
s   /A/c                 .     | j                   dg|i |S )Ncreaterq   r   argsr   s      r!   rs   zResourceList.create   s    t:4:6::r.   c                 .     | j                   dg|i |S )Nreplacert   ru   s      r!   rx   zResourceList.replace   s    t	;D;F;;r.   c                 .     | j                   dg|i |S )Npatchrt   ru   s      r!   rz   zResourceList.patch   s    t9$9&99r.   c                 b    d| j                   | j                  | j                  | j                  dS )NrP   )r$   r   r   r   rR   )r   r   r   rR   r,   s    r!   r%   zResourceList.to_dict   s-    #ZZ++II
 	
r.   c                 X    | j                         rt        | j                         |      S y rF   )rX   rG   rH   s     r!   rI   zResourceList.__getattr__   s'    4--/66r.   )r	   v1r	   NNrJ   )r1   rK   rL   rM   r"   rX   r^   r[   rW   rn   rq   rs   rx   rz   r%   rI   r?   r.   r!   rP   rP   l   sA    ,$	
<

0
00;<:
r.   rP   c                   :    e Zd ZdZd ZddZed        Zd Zd Z	y)	r   z Represents a subresource of an API resource. This generally includes operations
        like scale, as well as status objects for an instantiated resource
    c                    || _         |j                  | _        |j                  | _        |j                  | _        |j	                  d      | _        |j	                  d      | _        |j	                  dd       xs | j                  j                  d      d   | _        |j	                  dd      | _	        |j	                  dd       | _
        || _        y )	Nr   r   subresource/   r   Fr   )parentr   r   r   popr   r   splitr   r   r   r   )r   r   r   s      r!   r"   zSubresource.__init__   s    mm\\
!--JJv&	JJv&	!::mT:Udiiooc>RST>U **\59ZZ.
 r.   Nc                    |xs! |j                  di       j                  d      }| j                  j                  j                  |      }| j                  j                  r1| j                  j                  j                  | j                  ||      }| j                  ||      } | j                  j                  j                  d|fd|i|S )Nr`   r   re   postr\   )rW   r   r   serialize_bodyr   ensure_namespacerD   request)r   r\   r   r=   r   rD   s         r!   rs   zSubresource.create   s    ;txx
B/33F;{{!!006;;!!**;;DKKTXYIyydiy8)t{{!!))&$LTLVLLr.   c                    dj                  | j                  | j                        }dj                  || j                  j                  | j
                        dj                  || j                  j                  | j
                        dS )Nr*   z/{}/{}/{{name}}/{}z+/{}/namespaces/{{namespace}}/{}/{{name}}/{})r6   r7   )r+   r   r-   r   r   r   )r   r9   s     r!   r;   zSubresource.urls  sz    nnT[[$2D2DE(//T[[=M=MtO_O_`LSST_aealalaqaqsw  tD  tD   E
 	
r.   c                 V    t        t        | j                  j                  |      |       S rF   )r   rG   r   r   rH   s     r!   rI   zSubresource.__getattr__
  s     wt{{1148$??r.   c                     | j                   | j                  | j                  | j                  | j                  d}|j                  | j                         |S )N)r   r   r   r   r   )r   r   r   r   r   r&   r   )r   r(   s     r!   r%   zSubresource.to_dict  sE    IIII++//ZZ
 	
!r.   )NNN)
r1   rK   rL   rM   r"   rs   rN   r;   rI   r%   r?   r.   r!   r   r      s1    
!M 
 
@	r.   r   c                   b     e Zd ZdZd Zd Zd Zd Zd Zd Z	 fdZ
 fd	Zd
 Zd Zd Z xZS )rh   z A parsed instance of an API resource. It exists solely to
        ease interaction with API objects by allowing attributes to
        be accessed with '.' notation.
    c                     || _         |d   }|j                  d      r6d|v r2|d   d d }|d   sg |d<   |d   D ]  }d|vr|d   |d<   d|vs||d<    | j                  |      | _        d| _        y )Nr   Listr   rZ   T)r   endswith_ResourceInstance__deserialize
attributes_ResourceInstance__initialised)r   r   instancer   r]   s        r!   r"   zResourceInstance.__init__  s     == W%8F#CR(DG$$&! )t+)1,)?D&%#'DL	 * ,,X6!r.   c           
          t        |t              r=t        |j                         D ci c]  \  }}|| j	                  |       c}}      S t        |t
        t        f      r|D cg c]  }| j	                  |       c}S |S c c}}w c c}w )N)params)
isinstancedictResourceFieldr   r   listtupler   fieldr   r    r]   s        r!   __deserializezResourceInstance.__deserialize1  s    eT" 5:[[])5BTQ4%%a((])   e}-9>?D&&t,??L) @s   B
(Bc                 `   t        |t              r=|j                  j                         D ci c]  \  }}|| j	                  |       c}}S t        |t
        t        f      r|D cg c]  }| j	                  |       c}S t        |t              r|j                         S |S c c}}w c c}w rF   )	r   r   __dict__r   _ResourceInstance__serializer   r   rh   r%   r   s        r!   __serializezResourceInstance.__serialize;  s    e]+38>>3G3G3I3I41a4##A&&3I  e}-7<=utD$$T*u==/0==?"L >s   B%(B+c                 8    | j                  | j                        S rF   )r   r   r,   s    r!   r%   zResourceInstance.to_dictG  s    00r.   c                     t        |       S rF   )reprr,   s    r!   to_strzResourceInstance.to_strJ  s    Dzr.   c           	          dj                  | j                  j                  dj                  t	        j
                  | j                               j                  d                  S )NzResourceInstance[{}]:
  {}z  T)r+   r   r   rA   yaml	safe_dumpr%   
splitlinesr,   s    r!   r2   zResourceInstance.__repr__M  sH    ,33OO  IIdnnT\\^4??EF
 	
r.   c                 r    d| j                   vrt        t        |   |      S t	        | j
                  |      S Nr   )r   superrh   rI   rG   r   )r   r   r0   s     r!   rI   zResourceInstance.__getattr__S  s3    /4==@)4<TBBt--r.   c                     d| j                   vrt        t        |   ||      S || j                   v rt        t        |   ||      S || j                  |<   y r   )r   r   rh   __setattr__r   )r   r   valuer0   s      r!   r   zResourceInstance.__setattr__X  sS    /4==@)4<T5IIT]]")4<T5II$)DOOD!r.   c                      | j                   |   S rF   r   rH   s     r!   __getitem__zResourceInstance.__getitem__`  s    t$$r.   c                 "    || j                   |<   y rF   r   r   r   r   s      r!   __setitem__zResourceInstance.__setitem__c  s     %r.   c                     t        t        |             t        | j                  j                  j                               z   S rF   )dirtyper   r   r   keysr,   s    r!   __dir__zResourceInstance.__dir__f  s-    4:doo&>&>&C&C&E!FFFr.   )r1   rK   rL   rM   r"   r   r   r%   r   r2   rI   r   r   r   r   __classcell__)r0   s   @r!   rh   rh     s@    
"$
1
.
*%&Gr.   rh   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)r   z A parsed instance of an API resource attribute. It exists
        solely to ease interaction with API objects by allowing
        attributes to be accessed with '.' notation
    c                 <     | j                   j                  di | y )Nr?   )r   r&   )r   r   s     r!   r"   zResourceField.__init__p  s    &v&r.   c                 ,    t        | j                        S rF   )r   r   r,   s    r!   r2   zResourceField.__repr__s  s    t}}%%r.   c                 4    | j                   |j                   k(  S rF   r   )r   others     r!   __eq__zResourceField.__eq__v  s    }}..r.   c                 8    | j                   j                  |      S rF   )r   rW   rH   s     r!   r   zResourceField.__getitem__y  s    }}  &&r.   c                 d    | j                   j                  |t        | j                   |d             S rF   )r   rW   rG   rH   s     r!   rI   zResourceField.__getattr__~  s&    }}  wt}}dD'IJJr.   c                 "    || j                   |<   y rF   r   r   s      r!   r   zResourceField.__setattr__  s    #dr.   c                 r    t        t        |             t        | j                  j	                               z   S rF   )r   r   r   r   r   r,   s    r!   r   zResourceField.__dir__  s'    4:dmm&8&8&:!;;;r.   c              #   \   K   | j                   j                         D ]  \  }}||f  y wrF   )r   r   )r   r   r    s      r!   __iter__zResourceField.__iter__  s*     MM'')DAqa&L *s   *,c                 $    | j                  |       S rF   )_ResourceField__serializer,   s    r!   r%   zResourceField.to_dict  s    %%r.   c                     t        |t              r=|j                  j                         D ci c]  \  }}|| j	                  |       c}}S t        |t
        t        f      r|D cg c]  }| j	                  |       c}S |S c c}}w c c}w rF   )r   r   r   r   r   r   r   r   s        r!   r   zResourceField.__serialize  s    e]+38>>3G3G3I3I41a4##A&&3I  edE]+7<=utD$$T*u== >s   B(BN)r1   rK   rL   rM   r"   r2   r   r   rI   r   r   r   r%   r   r?   r.   r!   r   r   j  s:    
'&/'
K$<&r.   r   )rf   r   	functoolsr   pprintr   objectr   rP   r   rh   r   r?   r.   r!   <module>r      s[       S9v S9ly8 yx.( .bNGv NGb+F +r.   