HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/vultr/__pycache__/utils.cpython-310.pyc
o

;j��@sLdZddlZddlZddlZdZGdd�de�ZGdd�de�Z	dd	�Z
dS)
zHelper classes�Nzhttps://api.vultr.comc@seZdZdZdS)�
VultrErrorzVultr custom exceptionN)�__name__�
__module__�__qualname__�__doc__�rr�?/opt/saltstack/salt/lib/python3.10/site-packages/vultr/utils.pyr	src@sFeZdZdZdd�Zdd�Zddd�Zdd	d
�Zdd�Zddd�Z	dS)�	VultrBasez Base class for Vultr inheritancecCst|_||_|�d�dS)N�)�API_ENDPOINT�api_endpoint�api_key�set_requests_per_second)�selfr
rrr�__init__szVultrBase.__init__cCs||_d|j|_dS)z&Adjusts the request/second at run-timer
N)�req_per_second�req_duration)rrrrrrsz!VultrBase.set_requests_per_secondNcCs0t|t�st�}|jr|j|d<tj||dd�S)zAPI GET request helperr
�<)�params�timeout)�
isinstance�dictr
�requests�get)r�urlrrrr�_request_get_helpers


zVultrBase._request_get_helpercCs"|jrd|ji}tj|||dd�S)zAPI POST helperr
r)r�datar)r
rZpost)rrr�queryrrr�_request_post_helper#s
zVultrBase._request_post_helperc
Cs\z|dkr|�||�WS|dkr|�||�WStd|��tjy-}zt|��d}~ww)zAPI request helper method�POST�GETzUnsupported method %sN)rrrrZRequestException�RuntimeError)rrr�method�exrrr�_request_helper)s��zVultrBase._request_helperr cCs�t��}|�d�s
d|}|�|j|||�}|jdkrU|jdkr%td��|jdkr.td��|jdkr7td��|jd	krCtd
|j��|jdkrLtd��|jd
krUtd��t��|}||jkrht�|j|�|jro|�	�St
�d�S)zAPI request / call method�/��i�z6Invalid API location. Check the URL that you are usingi�z\Invalid or missing API key. Check that your API key is present and matches your assigned keyi�z^Invalid HTTP method. Check that the method (POST|GET) matches what the documentation indicatesi�zPRequest failed. Check the response body for a more detailed description. Body: 
i�z0Internal server error. Try again at a later timei�z\Rate limit hit. API requests are limited to an average of 1/s. Try your request again later.z{})�time�
startswithr$rZstatus_coder�textr�sleep�json�json_module�loads)r�pathrr"Z_startZrespZ_elapsedrrr�request4s.





�


zVultrBase.request)N)Nr )
rrrrrrrrr$r/rrrrr	s

	r	cCs&t|t�r	|��nt�}|�|�|S)zMerges updates into params)rr�copy�update)rZupdatesrrr�
update_params^s
r2)rrr'r+r,rr!r�objectr	r2rrrr�<module>sP