
    9i'                         S r SSKrSSKrSSKrSSKrSSKJrJr  SSKJ	r	  SSK
JrJrJr  SSKJr  \R                   S   S:X  a  \\4rO\\4rSrS	rS
r " S S\R0                  5      rg)z.
This module provides a client class for BCM.
    N)bce_base_clientcompat)bce_v1_signer)handlerbce_http_clienthttp_methods)bls_handler   i  d   descc                       \ rS rSrSrSrSrSrS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rg
)	BlsClient$   z
BLS base sdk client
s	   /logstore   /v1s   /v2s   /v3s   content-types   application/json;charset=UTF-8s   x-bce-request-idNc                 B    [         R                  R                  X5        g N)r   BceBaseClient__init__)selfconfigs     `/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/baidubce/services/bls/bls_client.pyr   BlsClient.__init__2   s    %%..t<    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   _merge_configBlsClient._merge_config5   s7    >;;4;;/J,,V4r   c	           
         U R                  U5      nUc  [        R                  nUc  0 nU R                  U;  a  U R                  XPR                  '   U R
                  U;  a!  [        R                  " 5       XPR
                  '   [        R                  " U[        R                  [        R                  U/X[        R                  -   U-   XEU5      $ r   )r   r   
parse_jsoncontent_type_header_keycontent_type_header_valuerequest_id_header_keyuuiduuid4r   send_requestr   signr	   parse_errorr   
log_prefix)	r   http_methodpathversionbodyheadersparamsr   body_parsers	            r   _send_requestBlsClient._send_request=   s    ##F+!,,K?G''w6484R4RG001%%W426**,G../++M&&)@)@+(N9#7#77$>vW 	Wr   c	                     [         R                  " U5      nSU-  n	X#US.n
Ub  XZS'   Uc	  [        U
S'   Ub  U[        :  a  [        nXjS'   Ub  XzS'   U R	                  [
        R                  XUS9$ )a  
Pull log records from specified log store.

:param config:
:param marker:
:param limit:
:param project:
:param log_stream_name:
:param log_store_name: The name of log store which will be pulled.
:type log_store_name: string
:param start_time: Start time of pulling log records.
:type start_time: string
:param end_time: End time of pulling log records.
:type end_time: string
:return: A list of log records.
:rtype: list
   /%s/logrecords   startDateTimes   endDateTimes   logStreamName   project   limit   markerr0   r   )r   convert_to_bytesDEFAULT_BATCH_RECORD_NUMBERMAX_BATCH_RECORD_NUMBERr2   r   GET)r   log_store_name
start_timeend_timelog_stream_nameprojectlimitmarkerr   r,   r0   s              r   pull_log_recordsBlsClient.pull_log_recordsM   s    &  00@.0$.\kl!(:=:F8../$8 &9!!,"2"2DPV!WWr   c                 N   [         R                  " U5      nSU-  n0 n	U V
s/ s H  n
[        U
5      PM     nn
Ub  UOSnU Vs/ s H  n[        U5      PM     nnUb  XIS'   UUUUS.nU R                  [        R
                  X[        R                  " U5      US9$ s  sn
f s  snf )a`  
Push log records into the specified log stream in the given log store.

:param log_store_name: The name of the log store which will receive the log records.
:type log_store_name: str

:param log_stream_name: The name of the log stream to write to.
:type log_stream_name: str

:param log_records: A list of log records to push.
                    Each record should be an instance of `LogRecordModel`.
                    Example:
                    [
                        LogRecordModel(message="test log", timestamp=1715231012000),
                        LogRecordModel(message="another log", timestamp=1715231044000)
                    ]
:type log_records: List[LogRecordModel]

:param project: (Optional) The project name to which the log store belongs.
:type project: str or None

:param type: (Optional) Type of logs, defaults to 'TEXT' if not specified.
:type type: str or None

:param tags: (Optional) A list of tags associated with the push.
             Each tag should be an instance of `TagModel`.
             Example:
             [
                 TagModel("env", "prod"),
                 TagModel("service", "auth")
             ]
:type tags: List[TagModel] or None

:param config: (Optional) Custom request config.
:type config: baidubce.BceClientConfiguration or None

:return: A dictionary containing the result of the push operation.
:rtype: dict
r5   TEXTrC   )logStreamNametagstype
logRecords)r0   r.   r   )r   r;   dictr2   r   POSTjsondumps)r   r?   rB   log_recordsrC   rL   rK   r   r,   r0   tag	tags_listrecordrecords_payloadr.   s                  r   push_log_recordsBlsClient.push_log_recordsq   s    R  00@.0*./$3T#Y$	/'tV6ABkF4<kB '9,)	
 !!,"3"3TtzzZ^O_hn!oo 0Bs   BB"c                    [         R                  " U5      nSU-  nX#US.nUb  X\S'   Uc	  [        US'   Ub  U[        :  a  [        nXS'   U	b  XS'   Ub  XlS'   Ub  US:X  a  X|S'   O	[        US'   U R                  [        R                  XU
S	9$ )
a  
query log records from specified log store.

:param sort: desc or asc
:type sort: string
:param query: query statement, eg: match *
:type query: string
:param config:
:param marker:
:param limit:
:param project:
:param log_stream_name:
:param log_store_name: The name of log store which will be pulled.
:type log_store_name: string
:param start_time: Start time of pulling log records.
:type start_time: string
:param end_time: End time of pulling log records.
:type end_time: string
:return: A list of log records.
:rtype: list
r5   r6   r7   r8   r9      queryasc   sortr:   )r   r;   r<   r=   DEFAULT_SORTr2   r   r>   )r   r?   r@   rA   rB   rC   querysortrD   rE   r   r,   r0   s                r   query_log_recordsBlsClient.query_log_records   s    .  00@.0$.\kl!(:=:F8../$8 &9$8u}"&w".w!!,"2"2DPV!WWr   c                 2   [         R                  " U5      nSU-  nX#US.nUb  X\S'   Uc	  [        US'   Ub  U[        :  a  [        nX|S'   Ub  XS'   U	b  U	S:X  a  XS'   O	[        US'   Ub  XlS'   U R                  [        R                  XR                  XS	9$ )
a  
Pull log records v3 from specified log store.

:param query: query statement, eg: match *
:type query: string
:param sort: desc or asc
:type: sort: string
:param config:
:param marker:
:param limit:
:param project:
:param log_stream_name:
:param log_store_name: The name of log store which will be pulled.
:type log_store_name: string
:param start_time: Start time of pulling log records.
:type start_time: string
:param end_time: End time of pulling log records.
:type end_time: string
:return: A list of log records.
:rtype: list
s   /%s/logrecord/pullr6   r7   r8   r9   r[   r\   rZ   )r-   r0   r   )	r   r;   r<   r=   r]   r2   r   r>   
version_v3)r   r?   r@   rA   rB   rC   r^   rD   rE   r_   r   r,   r0   s                r   pull_log_records_v3BlsClient.pull_log_records_v3   s    .  00@$~5$.\kl!(:=:F8../$8 &9u}"&w".w$8!!,"2"2D//Z`!ppr    r   )r   NNNNN)NNNN)NNNNNN)__name__
__module____qualname____firstlineno____doc__r*   r-   
version_v2rc   r"   r#   r$   r   r   r2   rF   rW   r`   rd   __static_attributes__rf   r   r   r   r   $   s     JGJJ- A/= 8>UYW  _c9="XH lp $8pt lpEI/Xb nrGK-qr   r   )rk   r   rP   sysr%   baidubcer   r   baidubce.authr   baidubce.httpr   r   r   baidubce.services.blsr	   version_infostrunicode
value_typebytesr=   r<   r]   r   r   rf   r   r   <module>rx      ss      
  , ' @ @ -A!wJuJ ! eq-- eqr   