
    9iy$                         S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R*                  " \5      r " S S\5      rg)z/
This module provides a client class for TSDB.
    N)bce_client_configuration)utils)bce_v1_signer)BceBaseClient)bce_http_client)handler)http_content_types)http_headers)http_methods)tsdb_handlerc                       \ rS rSrSrSS jrSS jrS rS rS r	SS	 jr
S
 r       SS jr      SS jr       SS jrS rS r     SS jrSrg)
TsdbClient'   z
sdk client
Nc                 <    X l         [        R                  " X5        g N)databaser   __init__)selfconfigr   s      b/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/tsdb/tsdb_client.pyr   TsdbClient.__init__+   s     t,    c                 H   Sn[         R                  " SU05      R                  S5      n[        R                  [
        R                  0nU(       a$  U R                  U5      nSU[        R                  '   U R                  [        R                  UUU[        R                  S9$ )z
write datapoints

:param datapoints: a list of datapoint dict
:type datapoints: list
:param use_gzip: open gzip compress
:type use_gzip: boolean
   /v1/datapoint
datapointszutf-8s   gzip)pathbodyheadersbody_parser)jsondumpsencoder
   CONTENT_TYPEr	   JSON_gzip_compressCONTENT_ENCODING_send_requestr   POSTr   
parse_json)r   r   use_gzipr   r   r   s         r   write_datapointsTsdbClient.write_datapoints/   s      zz<45<<WE**,>,C,CD&&t,D5<GL112!!!!(33 "  	r   c                 `    SnU R                  [        R                  U[        R                  S9$ )zS
list metrics

:return: a list of metric
:rtype: baidubce.bce_response.BceResponse
s
   /v1/metricr   r   r'   r   GETr   r)   )r   r   s     r   get_metricsTsdbClient.get_metricsG   s-     !!,"2"2<KbKb!ccr   c                     [         R                  " U5      nSU-   S-   nU R                  [        R                  U[
        R                  S9$ )z
get fields

:type metric: string
:param metric:

:return: field dict. {field1:{type: 'Number'},field2:{type: 'String'}}
:rtype: baidubce.bce_response.BceResponse
   /v1/metric/s   /fieldr.   r   convert_to_standard_stringr'   r   r0   r   r)   r   metricr   s      r   
get_fieldsTsdbClient.get_fieldsR   sG     11&9&2!!,"2"2<KbKb!ccr   c                     [         R                  " U5      nSU-   S-   nU R                  [        R                  U[
        R                  S9$ )z
get tags

:type metric: string
:param metric:

:return: {tagk1:[tagk11,tagk21,..],tagk2:[tagk21,tagk22,..]..}
:rtype: baidubce.bce_response.BceResponse
r4   s   /tagr.   r5   r7   s      r   get_tagsTsdbClient.get_tags`   sG     11&9&0!!,"2"2<KbKb!ccr   c                     SnSUS.n[         R                  " SU05      nU R                  [        R                  X4U[
        R                  S9$ )a  
query datapoints

:param query_list: a list of query dict
:type query_list: list
:param disable_presampling: open of close presampling result query
:type disable_presampling: boolean

:return: a list of result dict
:rtype: baidubce.bce_response.BceResponse
r    querydisablePresamplingqueries)r   paramsr   r   )r    r!   r'   r   PUTr   r)   )r   
query_listdisable_presamplingr   rD   r   s         r   get_datapointsTsdbClient.get_datapointsn   sV      5HIzz9j12!!,"2"2|'>'> " @ 	@r   c                 h    SnSU0nU R                  [        R                  X#[        R                  S9$ )z
get_rows_with_sql

:param statement: sql statement
:type statement: string

:return: {rows:[[],[],...], columns: []}
:rtype: baidubce.bce_response.BceResponse
   /v1/rowsql)r   rD   r   r/   )r   	statementr   rD   s       r   get_rows_with_sqlTsdbClient.get_rows_with_sql   s>     #!!,"2"2(33 " 5 	5r   c	           
      f    Sn	[         R                  " SU05      US.n
U R                  XUXXgU5      $ )
Get an authorization url with expire time

:type timestamp: int
:param timestamp: None

:type expiration_in_seconds: int
:param expiration_in_seconds: None

:type options: dict
:param options: None

:return:
    **URL string**
r   rC   r@   )r    r!   _generate_pre_signed_url)r   rF   	timestampexpiration_in_secondsrG   r   headers_to_signprotocolr   r   rD   s              r   generate_pre_signed_url"TsdbClient.generate_pre_signed_url   sG    2  ZZJ 78"5
 ,,T>SFL 	Lr   c           
      8    SnSU0n	U R                  XUXXVU5      $ )z
Get an authorization url with sql

:type timestamp: int
:param timestamp: None

:type expiration_in_seconds: int
:param expiration_in_seconds: None

:type options: dict
:param options: None

:return:
    **URL string**
rK   rL   )rR   )
r   rM   rS   rT   r   rU   rV   r   r   rD   s
             r    generate_pre_signed_url_with_sql+TsdbClient.generate_pre_signed_url_with_sql   s4    0 #,,T>SFL 	Lr   c	           
         U R                  U5      nU=(       d    0 nU=(       d    0 n[        R                  " UR                  UR                  5      u  pnU=(       d    U	nU
nXR                  R
                  :w  a  US[        U5      -   -  nX[        R                  '   [        R                  " UR                  [        R                  UUUUUU5      U[        R                  R                  5       '   UR                   < SUR#                  5       < UR#                  5       < S[        R$                  " US5      R#                  5       < 3$ )rQ      :z://?F)_merge_configr   parse_host_portendpointrV   default_portstrr
   HOSTr   signcredentialsr   r0   AUTHORIZATIONlowernamedecodeget_canonical_querystring)r   r   rS   rT   rD   r   rU   rV   r   endpoint_protocolendpoint_hostendpoint_port	full_hosts                r   rR   #TsdbClient._generate_pre_signed_url   s   0 ##F+-R2:?:O:O;27-00!	OO888M 222I%.!!"5B5G5G!6|))//12 "*!*!1!1!3!%!&!@!@!O!V!V!XZ 	Zr   c                     [         R                  " 5       n[        R                  " USS9 nUR	                  U5        S S S 5        UR                  5       $ ! , (       d  f       UR                  5       $ = f)Nw)fileobjmode)ioBytesIOgzipGzipFilewritegetvalue)r   rc   outfs       r   r%   TsdbClient._gzip_compress  sN    jjl]]3S1QGGCL 2||~ 21||~s   A
A2c                     Uc  U R                   $ [        R                  " U R                   5      nUR                  U5        U$ r   )r   copymerge_non_none_values)r   r   
new_configs      r   r_   TsdbClient._merge_config  s7    >;;4;;/J,,V4r   c           
      `   U R                  U5      nUc   [        R                  [        R                  0nUc  [
        R                  nU R                  b"  Uc  0 nUR                  SU R                  05        [        R                  " U[        R                  [
        R                  U/XX4U5      $ )Ns   database)r_   r
   r#   r	   r$   r   r)   r   updater   send_requestr   re   parse_error)r   http_methodr   r   r   rD   r   r   s           r   r'   TsdbClient._send_request  s     ##F+?#002D2I2IJG!,,K==$~MM;67++M&&)<)<k(Jtf6 	6r   )r   r   )T)F)r     FNNNN)r   r   NNNN)r   r   NNNNN)NNNNN)__name__
__module____qualname____firstlineno____doc__r   r+   r1   r9   r<   rH   rN   rW   rZ   rR   r%   r_   r'   __static_attributes__ r   r   r   r   '   s    -0	ddd@&5$ +,6:49(,04)-'+LF +,6:(,04)-'+L< #$"& 2Zf 6r   r   )r   ru   r   r    loggingrw   baidubcer   r   baidubce.authr   baidubce.bce_base_clientr   baidubce.httpr   r   r	   r
   r   baidubce.services.tsdbr   	getLoggerr   _loggerr   r   r   r   <module>r      sY    
     -  ' 2 ) ! , & & / 

H
%{6 {6r   