
    Vh                        d dl mZ d dlmZ d dlmZ ddlmZmZ	 dZ
dZ	 d dlZ	 d dlZ G d	 d
e      Zd ZddZddZe
r G d dej(                        Z G d de	      Zy# e$ r dZ
Y Gw xY w# e$ r dZY Ow xY w)    )annotations)contextmanager)missing_required_lib   )APIExceptionClientTNFc                      e Zd ZdZy)ClientExceptionz(An error related to the client occurred.N)__name__
__module____qualname____doc__     n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/hetzner/hcloud/plugins/module_utils/client.pyr
   r
      s    2r   r
   c                 l    t         st        t        d            t        st        t        d            y )Nrequestszpython-dateutil)HAS_REQUESTSr
   r   HAS_DATEUTILr   r   r   client_check_required_libr      s0    2:>??23DEFF r   c                B    t        d| j                  d       d|       S )Nz
resource (sz) does not exist: )r
   rstrip)resourceparams     r   _client_resource_not_foundr   $   s&    Z(<'==OPUwWXXr   r   c                   t        | |      }|j                  |      }||S 	 t        |       	 |j                  |      S # t        $ r}t	        ||      |d}~ww xY w# t        $ r#}|j                  dk(  rt	        ||      ||d}~ww xY w)a  
    Get a resource by name, and if not found by its ID.

    :param client: Client to use to make the call
    :param resource: Name of the resource client that implements both `get_by_name` and `get_by_id` methods
    :param param: Name or ID of the resource to query
    N	not_found)getattrget_by_nameint
ValueErrorr   	get_by_idr   code)clientr   r   resource_clientresult	exceptions         r   client_get_by_name_or_idr)   (   s     fh/O((/FIE
((//	  I(59yHI
  >>[(,Xu=9Ls.   A  A  	A	AA	B
'BB
c                  8     e Zd ZU ded<   d fdZd fdZ xZS )CachedSessionzdict[str, requests.Response]cachec                0    t         |           i | _        y )N)super__init__r,   )self	__class__s    r   r/   zCachedSession.__init__I   s    GDJr   c                *   |j                   dk7  s|j                  t        |   |fi |S |j                  | j                  v r| j                  |j                     S t        |   |fi |}|j
                  r|| j                  |j                  <   |S )z7
            Send a given PreparedRequest.
            GET)methodurlr.   sendr,   ok)r0   requestkwargsresponser1   s       r   r6   zCachedSession.sendM   s     ~~&'++*=w|G6v66{{djj(zz'++..w|G6v6H{{*2

7;;'Or   )returnNone)r8   zrequests.PreparedRequestr;   zrequests.Response)r   r   r   __annotations__r/   r6   __classcell__)r1   s   @r   r+   r+   F   s    ++		 	r   r+   c                      e Zd Zed        Zy)r   c              #     K   t               | _        	 d t        j                         | _        y# t        j                         | _        w xY ww)z
        Swap the client session during the scope of the context. The session will cache
        all GET requests.

        Cached response will not expire, therefore the cached client must not be used
        for long living scopes.
        N)r+   _requests_sessionr   Session)r0   s    r   cached_sessionzClient.cached_session_   s<      "/	8%-%5%5%7D"X%5%5%7D"s   A1 AAAN)r   r   r   r   rC   r   r   r   r   r   ^   s    8 8r   )r   strr   	str | int)r%   r   r   rD   r   rE   )
__future__r   
contextlibr   ansible.module_utils.basicr   vendor.hcloudr   r   
ClientBaser   r   r   ImportErrordateutil	Exceptionr
   r   r   r)   rB   r+   r   r   r   <module>rN      s    # % ; =
3i 3GY8 (( 08Z 8]  L
  Ls"   A" A/ "A,+A,/A98A9