
    9i\V                     b   S 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  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  SSKJ r   SSKJ!r!  \RD                  " \#5      r$ " S S\5      r%g)z.
This module provides a client class for BTS.
    N)bce_v1_signer)BceBaseClient)BceClientError)bce_http_client)handler)http_content_types)http_headers)http_methods)bts)INVALID_ARGS_ERROR)create_instance_args_2_dict)CreateInstanceArgs)Row)Cell)	QueryCell)BatchQueryRowArgs)QueryRowArgs)ScanArgs)create_table_args_2_dict)update_table_args_2_dict)_decode)_encodec                       \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrS r   SS jrSrg)	BtsClient/   z
BTS Client
Nc                 0    [         R                  " X5        g N)r   __init__)selfconfigs     `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/bts/bts_client.pyr   BtsClient.__init__3   s    t,    c           
          [         R                  S-   U-   nUc
  [        5       nU R                  [        R
                  XC[        R                  " U[        S9[        R                  [        R                  0S9$ )a(  
create instance

:param instance_name: instance name
:type instance_name: string
:param create_instance_args: arguments for create instance
:type create_instance_args: CreateInstanceArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
   /defaultpathr    bodyheaders)r   
URL_PREFIXr   _send_requestr
   PUTjsondumpsr   r	   CONTENT_TYPEr   JSON)r   instance_namecreate_instance_argsr    r)   s        r!   create_instanceBtsClient.create_instance7   so     ~~$}4'#5#7 !!,"2"2'+zz2FPk'l+7+D+DFXF]F]*^ " ` 	`r#   c                 j    [         R                  S-   U-   nU R                  [        R                  X2S9$ )z
drop instance

:param instance_name: instance name
:type instance_name: string
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   r)   r    r   r,   r-   r
   DELETEr   r3   r    r)   s       r!   drop_instanceBtsClient.drop_instanceL   s3     ~~$}4!!,"5"5D!PPr#   c                 B    SnU R                  [        R                  X!S9$ )z}
list instances

:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
s   /v1/instancesr8   )r-   r
   GET)r   r    r)   s      r!   list_instancesBtsClient.list_instances[   s%      !!,"2"2!MMr#   c                 j    [         R                  S-   U-   nU R                  [        R                  X2S9$ )z
show instance

:param instance_name: instance name
:type instance_name: string
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   r8   r   r,   r-   r
   r?   r;   s       r!   show_instanceBtsClient.show_instanceh   s3     ~~$}4!!,"2"2!MMr#   c           
          [         R                  S-   U-   S-   U-   nU R                  [        R                  XT[
        R                  " U[        S9[        R                  [        R                  0S9$ )aP  
create table

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param create_table_args: arguments for create table
:type create_table_args: CreateTableArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%      /table/r&   r(   )r   r,   r-   r
   r.   r/   r0   r   r	   r1   r   r2   )r   r3   
table_namecreate_table_argsr    r)   s         r!   create_tableBtsClient.create_tablex   j      ~~$}4zAJN!!,"2"2'+zz2CMe'f+7+D+DFXF]F]*^ " ` 	`r#   c           
          [         R                  S-   U-   S-   U-   nU R                  [        R                  XT[
        R                  " U[        S9[        R                  [        R                  0S9$ )aP  
update table

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param update_table_args: arguments for update table
:type update_table_args: UpdateTableArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   rG   r&   r(   )r   r,   r-   r
   r.   r/   r0   r   r	   r1   r   r2   )r   r3   rH   update_table_argsr    r)   s         r!   update_tableBtsClient.update_table   rL   r#   c                 v    [         R                  S-   U-   S-   U-   nU R                  [        R                  XCS9$ )z
drop table

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   rG   r8   r9   r   r3   rH   r    r)   s        r!   
drop_tableBtsClient.drop_table   s=     ~~$}4zAJN!!,"5"5D!PPr#   c                 v    [         R                  S-   U-   S-   U-   nU R                  [        R                  XCS9$ )z
show table

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   rG   r8   rC   rR   s        r!   
show_tableBtsClient.show_table   s=     ~~$}4zAJN!!,"2"2!MMr#   c                 p    [         R                  S-   U-   S-   nU R                  [        R                  X2S9$ )z
list tables

:param instance_name: instance name
:type instance_name: string
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r%   s   /tablesr8   rC   r;   s       r!   list_tablesBtsClient.list_tables   s8     ~~$}4zA!!,"2"2!MMr#   c                    Ub  UR                   S:X  a&  [        [        5      n[        R	                  U5        Ue[        UR                   5      / S.n UR                   H  n[        U[        5      (       a7  UR                  5       n[        US   5      US'   US   R                  U5        MO  [        U[        5      (       a'  [        US   5      US'   US   R                  U5        M  [        [        5      e   [        R                  " U5      n	[        R                   S-   U-   S-   U-   S-   n
U R#                  [$        R&                  XU	[(        R*                  [,        R.                  0S	9$ ! [         a  nUeSnAff = f)
a0  
put row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param put_row_args: arguments for put row
:type put_row_args: Row
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
N rowkeycellsvaluer_   r%   rG      /rowr(   )r^   r   r   _loggerdebugr   r_   
isinstancer   to_dictappenddict	Exceptionr/   r0   r   r,   r-   r
   r.   r	   r1   r   r2   )r   r3   rH   put_row_argsr    exrow_datacell	cell_dictr*   r)   s              r!   put_rowBtsClient.put_row   sc     <#6#6"#< 23BMM"Hl112
	$**dD)) $I)071C)DIg&W%,,Y7d++$+DM$:DMW%,,T2();<< + zz(#~~$}4zAJNQXX!!,"2"2'++7+D+DFXF]F]*^ " ` 	`  	H	s   B(E. .
E?8E::E?c                 d   Uc&  [        [        5      n[        R                  U5        Ue/ nUR                   H  n [        U[        5      (       a)  UR                  5       nUS   S:X  a  [        [        5      eO_[        U[        5      (       a;  [        R                  " U5      nUR                  S5      S:X  a  [        [        5      eO[        [        5      e[        US   5      US'   UR                  S/ 5       H  n	[        U	S   5      U	S'   M     UR                  U5        M     [        R                   " SU05      n
["        R$                  S-   U-   S-   U-   S	-   nU R'                  [(        R*                  XU
[,        R.                  [0        R2                  0S
9$ ! [         a  nUeSnAff = f)aT  
batch put row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param batch_put_row_args: arguments for batch put row
:type batch_put_row_args: BatchPutRowArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
Nr^   r\   r_   r`   rowsr%   rG      /rowsr(   )r   r   rb   rc   rq   rd   r   re   rg   copydeepcopygetr   rf   rh   r/   r0   r   r,   r-   r
   r.   r	   r1   r   r2   )r   r3   rH   batch_put_row_argsr    rj   	rows_datarowrk   rl   r*   r)   s               r!   batch_put_rowBtsClient.batch_put_row   s     % 23BMM"H	%**Cc3''"{{}H)R/,-?@@ 0T**#}}S1H||H-3,-?@@ 4 ));<<%,Xh-?%@"$LL"5D$+DM$:DM 6  * +& zz69-.~~$}4zAJNQYY!!,"2"2'++7+D+DFXF]F]*^ " ` 	`  s   C)F
F/(F**F/c                 "   Ub!  [        US5      (       a  UR                  S:X  a&  [        [        5      n[        R                  U5        Ue[        UR                  5      / S.n [        US5      (       a  UR                  (       a  UR                   Ht  n[        U[        5      (       a$  US   R                  UR                  5       5        M<  [        U[        5      (       a  US   R                  U5        Mg  [        [        5      e   [        R                  " U5      n[         R"                  S-   U-   S-   U-   S-   n	U R%                  [&        R(                  XU[*        R,                  [.        R0                  0S	9$ ! [         a  nUeSnAff = f)
aE  
delete row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param delete_row_args: arguments for delete row
:type delete_row_args: QueryRowArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
Nr^   r\   r]   r_   r%   rG   ra   r(   )hasattrr^   r   r   rb   rc   r   r_   rd   r   rf   re   rg   rh   r/   r0   r   r,   r-   r
   r:   r	   r1   r   r2   )
r   r3   rH   delete_row_argsr    rj   delete_row_datarl   r*   r)   s
             r!   
delete_rowBtsClient.delete_row/  s[     "'/8*L*LP_PfPfjlPl 23BMM"Ho445

	00_5J5J+11D!$	22'077G#D$//'077=,-?@@ 2 zz/*~~$}4zAJNQXX!!,"5"5D#''3'@'@BTBYBY&Z " \ 	\  	H	s   $B&E= =
FF		Fc                    Ub  [        U[        5      (       d  [        [        5      e/ n UR                   H  n[        U[
        5      (       a  UR                  5       nO'[        U[        5      (       a  UnO[        [        5      eSU;   a  US   (       a  [        US   5      US'   O[        [        5      eUR                  U5        M     SU0n	[        R                  " U	5      n
[        R                  S-   U-   S-   U-   S-   nU R                  [         R"                  XU
[$        R&                  [(        R*                  0S9$ ! [         a  nUeSnAff = f)ab  
batch delete row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param batch_delete_row_args: arguments for batch delete row
:type batch_delete_row_args: BatchQueryRowArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
Nr^   rq   r%   rG   rr   r(   )rd   r   r   r   rq   r   re   rg   r   rf   rh   r/   r0   r   r,   r-   r
   r:   r	   r1   r   r2   )r   r3   rH   batch_delete_row_argsr    rw   rx   rk   rj   batch_delete_row_datar*   r)   s               r!   batch_delete_rowBtsClient.batch_delete_rowY  sC     !(
;PRc0d0d !344		,11c<00"{{}HT**"H();<<x'HX,>)0(1C)DHX&();<<  * 2  "( 3zz/0~~$}4zAJNQYY!!,"5"5D%))5)B)BDVD[D[(\ " ^ 	^  	H	s   B"E 
EEEc           
      <   [        U[        5      (       a  UR                  S5      nO1[        U[        5      (       a  UR                  nO[        [        5      eU(       d  [        [        5      e[        U5      / S.n[        US5      (       a  UR                  (       a  UR                   Ht  n[        U[        5      (       a$  US   R                  UR                  5       5        M<  [        U[        5      (       a  US   R                  U5        Mg  [        [        5      e   [        R                  " U5      n[        R                   S-   U-   S-   U-   S-   n	U R#                  [$        R&                  XU[(        R*                  [,        R.                  [(        R0                  [$        R2                  0S9n
 U
R4                  b  [7        [9        U
R4                  S	   R                  5      5      U
R4                  S	   l        [;        [=        U
R4                  S	   R                  5      5       HZ  n[7        [9        U
R4                  S	   R                  U   R>                  5      5      U
R4                  S	   R                  U   l        M\     U
$ ! [@         a  nUeSnAff = f)
a8  
get row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param get_row_args: arguments for get row
:type get_row_args: QueryRowArg
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r^   r]   r_   r%   rG   ra   r(   Nr   )!rd   rg   ru   r   r^   r   r   r   r|   r_   r   rf   re   r/   r0   r   r,   r-   r
   POSTr	   r1   r   r2   BTS_METHOD_HEADERr?   resultr   strrangelenr`   rh   )r   r3   rH   get_row_argsr    r^   get_row_datarl   r*   r)   responseirj   s                r!   get_rowBtsClient.get_row  s     lD))!%%h/Fl33!((F !344 !344 fo

 <))l.@.@$**dI.. )00@d++ )006();<< + zz,'~~$}4zAJNQXX%%l&7&7d)--9-F-FHZH_H_-9-K-K\M]M]-_ & `	*,3C8J8Q8Q4R,S")s8??1#5#;#;<=A8?HOOTUDVD\D\]^D_DeDe@f8gHOOA&,,Q/5 >   	H	s   5CJ
 

JJJc           
         0 n[        U[        5      (       a  / nUR                   H  n[        U[        5      (       a  UR	                  5       nO'[        U[
        5      (       a  UnO[        [        5      eSU;   a  US   (       a  [        US   5      US'   O[        [        5      eUR                  U5        M     XeS'   O'[        U[
        5      (       a  UnO[        [        5      e[        R                  " U5      n	[        R                  S-   U-   S-   U-   S-   n
U R                  [        R                   XU	["        R$                  [&        R(                  ["        R*                  [        R,                  0S9n UR.                  b  [1        [3        UR.                  5      5       H  n[5        [7        UR.                  U   R8                  5      5      UR.                  U   l        [1        [3        UR.                  U   R:                  5      5       HZ  n[5        [7        UR.                  U   R:                  U   R<                  5      5      UR.                  U   R:                  U   l        M\     M     U$ ! [>         a  nUeSnAff = f)aV  
batch get row

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param batch_get_row_args: arguments for batch get row
:type batch_get_row_args: BatchQueryRowArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
r^   rq   r%   rG   rr   r(   N) rd   r   rq   r   re   rg   r   r   r   rf   r/   r0   r   r,   r-   r
   r   r	   r1   r   r2   r   r?   r   r   r   r   r   r^   r_   r`   rh   )r   r3   rH   batch_get_row_argsr    batch_get_row_datarw   row_argrk   r*   r)   r   r   jrj   s                  r!   batch_get_rowBtsClient.batch_get_row  s!      (*;<<I-22g|44&0H..&H();<<x'HX,>)0(1C)DHX&();<<  * 3 *3v&*D11!3 !!344zz,-~~$}4zAJNQYY%%l&7&7d)--9-F-FHZH_H_-9-K-K\M]M]-_ & `
	*s8??34A07HOOA<N<U<U8V0WHOOA&-"3xq'9'?'?#@A<CCXYHZH`H`abHcHiHiDj<k*0039 B 5   	H	s   :C8I4 4
J>J  Jc                 $   [        U[        5      (       a  UR                  5       nO'[        U[        5      (       a  UnO[	        [
        5      eSU;   a  US   (       a  [        US   5      US'   SU;   a  US   (       a  [        US   5      US'   [        R                  " U5      n[        R                  S-   U-   S-   U-   S-   nU R                  [        R                  XtU[        R                  [         R"                  0S9n UR$                  b  ['        [)        UR$                  5      5       H  n	[+        [-        UR$                  U	   R.                  5      5      UR$                  U	   l        ['        [)        UR$                  U	   R0                  5      5       HZ  n
[+        [-        UR$                  U	   R0                  U
   R2                  5      5      UR$                  U	   R0                  U
   l        M\     M     U$ ! [4         a  nUeSnAff = f)a)  
scan

:param instance_name: instance name
:type instance_name: string
:param table_name: table name
:type table_name: string
:param scan_args: arguments for scan
:type scan_args: ScanArgs
:param config: None
:type config: BceClientConfiguration

:return:
:rtype baidubce.bce_response.BceResponse
startRowkey
stopRowkeyr%   rG   rr   r(   N)rd   r   re   rg   r   r   r   r/   r0   r   r,   r-   r
   r?   r	   r1   r   r2   r   r   r   r   r   r^   r_   r`   rh   )r   r3   rH   	scan_argsr    scan_args_dictr*   r)   r   r   r   rj   s               r!   scanBtsClient.scan  s     i**&..0N	4((&N !344N*~m/L,3N=4Q,RN=)>)n\.J+2>,3O+PN<(zz.)~~$}4zAJNQYY%%l&6&6T)--9-F-FHZH_H_,` & b	*s8??34A07HOOA<N<U<U8V0WHOOA&-"3xq'9'?'?#@A<CCXYHZH`H`abHcHiHiDj<k*0039 B 5   	H	s   C8G> >
HH

Hc                     Uc  U R                   $ [        R                  " U R                   5      nUR                  U5        U$ r   )r    rs   merge_non_none_values)r   r    
new_configs      r!   _merge_configBtsClient._merge_config#  s7    >;;4;;/J,,V4r#   c           
      &   U R                  U5      nUc  [        R                  nUR                  b(  U=(       d    0 nUR                  U[        R
                  '   [        R                  " U[        R                  [        R                  U/XX4U5      $ r   )r   r   
parse_jsonsecurity_tokenr	   STS_SECURITY_TOKENr   send_requestr   signparse_error)r   http_methodr)   r*   r+   paramsr    body_parsers           r!   r-   BtsClient._send_request,  s    
 ##F+!,,K  ,mG7=7L7LGL334++M&&)<)<k(Jtf6 	6r#    r   )NN)NNNNN)__name__
__module____qualname____firstlineno____doc__r   r5   r<   r@   rD   rJ   rO   rS   rV   rY   rn   ry   r   r   r   r   r   r   r-   __static_attributes__r   r#   r!   r   r   /   s    -`*QNN `*`*Q"N"N *`X-`^(\T)^V5n9v+Z -1	6r#   r   )&r   rs   r/   loggingbaidubce.authr   baidubce.bce_base_clientr   baidubce.exceptionr   baidubce.httpr   r   r   r	   r
   baidubce.servicesr   baidubce.services.btsr   baidubce.services.bts.modelr   r   r   r   r   r   r   r   r   r   baidubce.services.bts.utilr   r   	getLoggerr   rb   r   r   r#   r!   <module>r      su       ' 2 - ) ! , & & ! 4 C : + , 1 9 4 0 @ @ . .


H
%L6 L6r#   