
    E0j5                         d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZmZ  e ej                    dz            Zd a G d	 d
          ZdS )    N)datetime)	urlencode)BytesIO)TeaModel)READABLE)AnyBinaryIODictList  c                      e Zd ZdZ G d dej                  Zed=d            Zed             Z	ede
defd	            Zedede
fd
            Zede
defd            Zedefd            Zede
fd            Zedefd            Zedefd            Zede
fd            Zedefd            Zede
fd            Zede
fd            Zede
de
de
fd            Zedededefd            Zedede
fd            Zedede
fd            Zede
defd            Zede
de
defd            Z edededefd            Z!ededefd             Z"ed!e#e
ef         de#e
e
f         fd"            Z$ed!e#e
e
f         de#e
ef         fd#            Z%ededefd$            Z&edede
fd%            Z'ededefd&            Z(ededefd'            Z)ededefd(            Z*edede#e
ef         fd)            Z+ed*e
de
fd+            Z,ed,edefd-            Z-ed,edefd.            Z.ed,edefd/            Z/ed,edefd0            Z0ed!e1dd1fd2            Z2ed3e1de#e
ef         fd4            Z3ed5edd1fd6            Z4ed5edd1fd7            Z5ed8ede6e#e
ef                  fd9            Z7edede8fd:            Z9edede:fd;            Z;ede
fd<            Z<d1S )>Clientz"
    This is a utility module
    c                   (     e Zd Zdedef fdZ xZS )Client.__ModelEncoderoreturnc                     t          |t                    r|                                S t          |t                    r|                    d          S t                                          |           d S )Nutf-8)
isinstancer   to_mapbytesdecodesuperdefault)selfr   	__class__s     d/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/alibabacloud_tea_util/client.pyr   zClient.__ModelEncoder.default   sc    !X&& )xxzz!Au%% )xx(((GGOOA    )__name__
__module____qualname__r   r   __classcell__)r   s   @r   __ModelEncoderr      sK        	S 	S 	 	 	 	 	 	 	 	 	 	r   r#      c              #   F   K   	 |                      |          }|r|V  nd S )N)read)fsizeparts      r   __read_partzClient.__read_part"   s7      	66$<<D 



	r   c            	          dt          j                     dt          j                     dt          j                     dt          j         d	S )NzAlibabaCloud (z; z	) Python/z Core/z	 TeaDSL/1)platformsystemmachinepython_versionTea__version__ r   r   __get_default_agentzClient.__get_default_agent+   sj    U 1 1 U UX5E5G5G U U!022U U:=/U U U 	Ur   valr   c                     t          | t                    r| S t          | t                    r|                     d          S t          |                               d          S )zS
        Convert a string(utf8) to bytes
        @return: the return bytes
        r   encoding)r   r   strencoder4   s    r   to_byteszClient.to_bytes0   s[     c5!! 	5JS!! 	5::w:///s88??G?444r   c                     t          | t                    r| S t          | t                    r|                     d          S t          |           S )zT
        Convert a bytes to string(utf8)
        @return: the return string
        r   )r   r8   r   r   r:   s    r   	to_stringzClient.to_string@   sJ     c3 	JU## 	::g&&&s88Or   c                 n    	 t          j        |           S # t          $ r t          d|  d          w xY w)zL
        Parse it by JSON format
        @return: the parsed result
        z2Failed to parse the value as json format, Value: "z".)jsonloads
ValueErrorRuntimeErrorr:   s    r   
parse_jsonzClient.parse_jsonO   sP    	]:c??" 	] 	] 	][TW[[[\\\	]s    4c                    K   t          | t                    r| S t          | t                    rt          | d          S |                                  d{V S )
        Read data from a readable stream, and compose it to a bytes
        @param stream: the readable stream
        @return: the bytes result
        r   r6   N)r   r   r8   r&   streams    r   read_as_bytes_asynczClient.read_as_bytes_async\   sd       fe$$ 	'M$$ 	''2222&&&&&&&r   c                 z   K   t                               |            d{V }t                               |          S )
        Read data from a readable stream, and compose it to a string
        @param stream: the readable stream
        @return: the string result
        N)r   rH   r=   rG   buffs     r   read_as_string_asynczClient.read_as_string_asyncj   sA       //77777777%%%r   c                 v   K   t                               t                               |            d{V           S )
        Read data from a readable stream, and parse it by JSON format
        @param stream: the readable stream
        @return: the parsed result
        N)r   rC   rM   rF   s    r   read_as_json_asynczClient.read_as_json_asynct   sC         --f55555555
 
 	
r   c                     t          | t                    r'd}t                              | d          D ]}||z  }|S t          | t                    r| S t	          | d          S )rE   r   r$   r   r6   )r   r   r   _Client__read_partr   )rG   br)   s      r   read_as_byteszClient.read_as_bytes   st     fh'' 	3A**6488  T	H&& 	3M'2222r   c                 j    t                               |           }t                               |          S )rJ   )r   rT   r=   rK   s     r   read_as_stringzClient.read_as_string   s+     ##F++%%%r   c                 f    t                               t                               |                     S )rO   )r   rC   rV   rF   s    r   read_as_jsonzClient.read_as_json   s&       !6!6v!>!>???r   c            	         t          j                    } t          t          j                    dz            }t          }t          dz  at          j        d          }t           d|  d| d| d| 	}t          j	                    }|
                    |                    d                     |                                S )zK
        Generate a nonce string
        @return: the nonce string
        r      @   -r   )	threading	get_identinttime_seqIdrandomgetrandbits_process_start_timehashlibmd5updater9   	hexdigest)	thread_idcurrent_timeseqrandNummsgrf   s         r   	get_noncezClient.get_nonce   s     '))	49;;-..!$R(($QQyQQ<QQ#QQQQkmm

3::g&&'''}}r   c                  N    t          j                                        d          S )z
        Get an UTC format string by current date, e.g. 'Thu, 06 Feb 2020 07:32:54 GMT'
        @return: the UTC format string
        z%a, %d %b %Y %H:%M:%S GMT)r   utcnowstrftimer2   r   r   get_date_utcstringzClient.get_date_utcstring   s!       ))*EFFFr   realr   c                     | | n|S )z[
        If not set the real, use default value
        @return: the return string
        r2   rs   r   s     r   default_stringzClient.default_string        'ttW4r   c                     | | n|S )z[
        If not set the real, use default value
        @return: the return number
        r2   ru   s     r   default_numberzClient.default_number   rw   r   c                 ~      sdS t          t                               } fd|D             }t          |          S )z`
        Format a map to form string, like a=a%20b%20c
        @return: the form string
         c                 X    i | ]&}t          |         t                    ||         'S r2   )r   r   ).0kr4   s     r   
<dictcomp>z)Client.to_form_string.<locals>.<dictcomp>   s2    KKKQjQ.J.JKq#a&KKKr   )sortedlistr   )r4   keysdics   `  r   to_form_stringzClient.to_form_string   sJ      	2d3ii  KKKK$KKK~~r   c                     t          | t                    rt          |           S t          j        | t          j        dd          S )zZ
        Stringify a value by JSON format
        @return: the JSON format string
        F),:)clsensure_ascii
separators)r   r8   r?   dumpsr   _Client__ModelEncoderr:   s    r   to_jsonstringzClient.to_jsonstring   sF     c3 	s88OzV*:
 
 
 	
r   c                     |  S )zk
        Check the string is empty?
        @return: if string is null or zero length, return true
        r2   r:   s    r   emptyzClient.empty   s     wr   val1val2c                     | |k    S )z^
        Check one string equals another one?
        @return: if equals, return true
        r2   r   r   s     r   equal_stringzClient.equal_string        t|r   c                     | |k    S )z^
        Check one number equals another one?
        @return: if equals, return true
        r2   r   s     r   equal_numberzClient.equal_number  r   r   valuec                 
    | du S )zQ
        Check one value is unset
        @return: if unset, return true
        Nr2   r   s    r   is_unsetzClient.is_unset  s     }r   mc                     | i S i }|                                  D ]F\  }}|:t          |t                    r|                    d          }nt	          |          }|||<   G|S )zU
        Stringify the value of map
        @return: the new stringified map
        Nr   )itemsr   r   r   r8   )r   
dic_resultr~   vs       r   stringify_map_valuezClient.stringify_map_value  st     9I
GGII 	 	DAq}a'' ))AAAAJqMMr   c                     | S )zN
        Anyify the value of map
        @return: the new anyfied map
        r2   r   s    r   anyify_map_valuezClient.anyify_map_value-  s	     r   c                 T    t          | t                    st          |  d          | S )zt
        Assert a value, if it is a boolean, return it, otherwise throws
        @return: the boolean value
        z is not a bool)r   boolrA   r   s    r   assert_as_booleanzClient.assert_as_boolean7  2     %&& 	7555666r   c                 T    t          | t                    st          |  d          | S )zr
        Assert a value, if it is a string, return it, otherwise throws
        @return: the string value
        z is not a str)r   r8   rA   r   s    r   assert_as_stringzClient.assert_as_stringC  s2     %%% 	6444555r   c                 T    t          | t                    st          |  d          | S )zp
        Assert a value, if it is a bytes, return it, otherwise throws
        @return: the bytes value
        z is not a bytes)r   r   rA   r   s    r   assert_as_byteszClient.assert_as_bytesO  s2     %'' 	8666777r   c                 b    t          | t          t          f          st          |  d          | S )zr
        Assert a value, if it is a number, return it, otherwise throws
        @return: the number value
        z is not a number)r   r_   floatrA   r   s    r   assert_as_numberzClient.assert_as_number[  s6     %#u.. 	9777888r   c                 T    t          | t                    st          |  d          | S )zt
        Assert a value, if it is a integer, return it, otherwise throws
        @return: the integer value
        z is not a int number)r   r_   rA   r   s    r   assert_as_integerzClient.assert_as_integerg  s2     %%% 	=;;;<<<r   c                 T    t          | t                    st          |  d          | S )zl
        Assert a value, if it is a map, return it, otherwise throws
        @return: the map value
        z is not a dict)r   dictrA   r   s    r   assert_as_mapzClient.assert_as_maps  r   r   
user_agentc                 t    | rt                                            d|  S t                                           S )z
        Get user agent, if it userAgent is not null, splice it with defaultUserAgent and return, otherwise return defaultUserAgent
        @return: the string value
         )r   _Client__get_default_agent)r   s    r   get_user_agentzClient.get_user_agent  s?      	B0022AAZAAA))+++r   codec                 "    d| cxk    odk     nc S )zh
        If the code between 200 and 300, return true, or return false
        @return: boolean
           ,  r2   r   s    r   is_2xxzClient.is_2xx  &     d    S     r   c                 "    d| cxk    odk     nc S )zh
        If the code between 300 and 400, return true, or return false
        @return: boolean
        r     r2   r   s    r   is_3xxzClient.is_3xx  r   r   c                 "    d| cxk    odk     nc S )zh
        If the code between 400 and 500, return true, or return false
        @return: boolean
        r     r2   r   s    r   is_4xxzClient.is_4xx  r   r   c                 "    d| cxk    odk     nc S )zh
        If the code between 500 and 600, return true, or return false
        @return: boolean
        r   iX  r2   r   s    r   is_5xxzClient.is_5xx  r   r   Nc                 \    t          | t                    r|                                  dS dS )z6
        Validate model
        @return: void
        N)r   r   validater   s    r   validate_modelzClient.validate_model  s1     a"" 	JJLLLLL	 	r   in_c                 X    t          | t                    r|                                 S | S )zT
        Model transforms to map[string]any
        @return: map[string]any
        )r   r   r   )r   s    r   r   zClient.to_map  s)     c8$$ 	::<<Jr   millisecondc                 4    t          j        | dz             dS zW
        Suspends the current thread for the specified number of milliseconds.
        r   N)r`   sleepr   s    r   r   zClient.sleep  s     	
;%&&&&&r   c                 D   K   t          j        | dz             d{V  dS r   )asyncior   r   s    r   sleep_asynczClient.sleep_async  s5       mK$.///////////r   inputc                     | g S g }| D ]T}t          |t                    r(|                    |                                           ?|                    |           U|S )z+
        Transform input as array.
        )r   r   appendr   )r   outis      r   to_arrayzClient.to_array  sg     =I 	 	A!X&& 

188::&&&&

1
r   c                     t          | t                    r|                     d          } t          | t                    rt	          |           } n$t          | t
                    st          d          | S )zv
        Assert a value, if it is a readable, return it, otherwise throws
        @return: the readable value
        r   zThe value is not a readable)r   r8   r9   r   r   r   rA   r   s    r   assert_as_readablezClient.assert_as_readable  sl     eS!! 	*LL))EeU## 	=ENNEEE8,, 	=;<<<r   c                 N    t          | t                    st          d          | S )NzThe value is not a list)r   r   rA   r   s    r   assert_as_arrayzClient.assert_as_array   s*     %&& 	86777r   c                  V    ddl } 	 |                                 S # t          $ r Y dS w xY w)zS
        Get hostname of current machine
        @return: the string value
        r   Nr{   )socketgethostname	Exception)r   s    r   get_host_namezClient.get_host_name  sF     		%%''' 	 	 	22	s    
(()r$   )=r   r    r!   __doc__r?   JSONEncoderr   staticmethodrR   r   r8   r   r;   r=   r   rC   rH   rM   rP   rT   rV   rX   rn   rr   rv   r_   ry   r   r   r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r2   r   r   r   r      s-            )       \ U U \U 55	5 5 5 \5 	   \ 
]
]	
] 
] 
] \
] 'U ' ' ' \' &c & & & \& 
C 
 
 
 \
 3 3 3 3 \3  &# & & & \& @ @ @ @ \@ s    \  G G G G \G 555 
5 5 5 \5 555 
5 5 5 \5 	   \ 

	
 
 
 \
 	   \  
   \  
   \ 	   \ S>	c3h   \( S>	c3h   \ 				 	 	 \	 				 	 	 \	 				 	 	 \	 				 	 	 \	 				 	 	 \	 			c3h	 	 	 \	 	,	,		, 	, 	, \	, !!	! ! ! \! !!	! ! ! \! !!	! ! ! \! !!	! ! ! \! 	   \ 

	c3h
 
 
 \
 ''	' ' ' \' 00	0 0 0 \0 	d38n	   \" 	   \  	   \ 	3 	 	 	 \	 	 	r   r   )r?   r,   r`   r0   r   r]   rb   re   r   urllib.parser   ior   	Tea.modelr   
Tea.streamr   typingr   r	   r
   r   r_   rd   ra   r   r2   r   r   <module>r      s,      



              " " " " " "                   , , , , , , , , , , , ,c)$)++,-- 	
} } } } } } } } } }r   