
    ^gj                     D    d dl Z d dlmZmZ d dlmZmZ dZ G d d      Zy)    N)	HTTPErrorURLError)Requesturlopenz1.0.0c                   ,    e Zd ZdZddZddZd Zd Zy)	EntropyClientz7Private TRITROIA adapter for the isolated Entropy Core.c                 >    |j                  d      | _        || _        y )N/)rstripbase_urltimeout)selfr   r   s      /app/engine_sdk/entropy.py__init__zEntropyClient.__init__   s     ,    Nc                 @   t        | j                   dt        j                  d|xs i id      j	                  d      ddt
        dd	      }	 t        || j                  
      5 }t        j                  |j                         j                  d            }d d d        t%        t&              r|j)                  d      st#        d      |S # 1 sw Y   7xY w# t        t        t        t        t        t        j                   f$ r}t#        d|       |d }~ww xY w)Nz/v1/entropycontextT)ensure_asciiutf-8zapplication/json)AcceptzContent-TypezX-Entropy-SDK-VersionPOST)dataheadersmethodr   entropy_core_unavailable: tokenentropy_core_invalid_response)r   r   jsondumpsencodeSDK_VERSIONr   r   loadsreaddecoder   r   TimeoutErrorOSError
ValueErrorJSONDecodeErrorRuntimeError
isinstancedictget)r   r   requestresponsepayloaderrors         r   issuezEntropyClient.issue   s    }}o[)Y26TJQQRYZ1CUp{|	
	P$,,78**X]]_%;%;G%DE 8 '4(G0D>?? 878\7JH\H\] 	P!;E7CD%O	Ps0   C '3CC CC -D	DDc                 d   	 t        | j                   d| j                        5 }t        j                  |j                         j                  d            cd d d        S # 1 sw Y   y xY w# t        t        t        t        t        t        j                  f$ r}t        d|       |d }~ww xY w)Nz/healthr   r   r   )r   r   r   r   r#   r$   r%   r   r   r&   r'   r(   r)   r*   )r   r/   r1   s      r   healthzEntropyClient.health    s    	PDMM?'2DLLIXzz(--/"8"8"AB JII8\7JH\H\] 	P!;E7CD%O	Ps4   $A. 2A"	A. "A+'A. +A. .-B/B**B/c                     	 d| j                   | j                         dS # t        $ r#}d| j                   t        |      dcY d }~S d }~ww xY w)NT)	connectedurlr4   F)r6   r7   r1   )r   r4   r*   str)r   r1   s     r   statuszEntropyClient.status'   sF    	S!%dmmt{{}UU 	S!&t}}s5zRR	Ss     	AAAA)   )N)__name__
__module____qualname____doc__r   r2   r4   r9    r   r   r   r   	   s    A PSr   r   )	r   urllib.errorr   r   urllib.requestr   r   r"   r   r?   r   r   <module>rB      s!     , + "S "Sr   