
    	]j-                        d 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m	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZ  edi 	      Z ej*                  d
ej,                        Zd'dZd ZdddddddefdddddddfZ ej6                  dd eD              Z ed eD              ej<                  _        dZ dZ! G d  de      Z" G d! d"e"      Z# G d# d$e"      Z$ G d% d&e"      Z%y)(z0Log entries within the Google Cloud Logging API.    N)_datetime_to_rfc3339_name_from_project_path_rfc3339_nanos_to_datetime)audit_data_pb2)MessageToDictParse)Message)Resourceglobal)typelabelsz
    projects/            # static prefix
    (?P<project>[^/]+)   # initial letter, wordchars + hyphen
    /logs/               # static midfix
    (?P<name>[^/]+)      # initial letter, wordchars + allowed punc
c                 $    t        | |t              S )a  Validate a logger URI path and get the logger name.

    Args:
        path (str): URI path for a logger API request
        project (str): The project the path is expected to belong to

    Returns:
        str: Logger name parsed from ``path``.

    Raises:
        ValueError: If the ``path`` is ill-formed of if the project
            from ``path`` does not agree with the ``project`` passed in.
    )r   _LOGGER_TEMPLATE)pathprojects     I/root/env/lib/python3.12/site-packages/google/cloud/logging_v2/entries.pylogger_name_from_pathr   2   s     #42BCC    c                      | t        |       } | S )z&Helper: return an integer or ``None``.)int)values    r   _int_or_noner   C   s    E
Lr   )log_nameN)r   N)	insert_idN)severityN)http_requestN)	timestampNresource)traceN)span_idN)trace_sampledN)source_locationN)	operationN)loggerN)payloadNLogEntryc              #   &   K   | ]	  \  }}|  y wN ).0field_s      r   	<genexpr>r-   ]   s     985!9   c              #   &   K   | ]	  \  }}|  y wr(   r)   )r*   r,   defaults      r   r-   r-   `   s     +X
7G+Xr.   a  
    Args:
        log_name (str): The name of the logger used to post the entry.
        labels (Optional[dict]): Mapping of labels for the entry
        insert_id (Optional[str]): The ID used to identify an entry
            uniquely.
        severity (Optional[str]): The severity of the event being logged.
        http_request (Optional[dict]): Info about HTTP request associated
            with the entry.
        timestamp (Optional[datetime.datetime]): Timestamp for the entry.
        resource (Optional[google.cloud.logging_v2.resource.Resource]):
            Monitored resource of the entry.
        trace (Optional[str]): Trace ID to apply to the entry.
        span_id (Optional[str]): Span ID within the trace for the log
            entry. Specify the trace parameter if ``span_id`` is set.
        trace_sampled (Optional[bool]): The sampling decision of the trace
            associated with the log entry.
        source_location (Optional[dict]): Location in source code from which
            the entry was emitted.
        operation (Optional[dict]): Additional information about a potentially
            long-running operation associated with the log entry.
        logger (logging_v2.logger.Logger): the logger used
            to write the entry.
zR
    See:
    https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
c                   L    e Zd Zdez   ez   ZdZed        Zeddd       Z	d Z
y)r&   z
    Log entry.

    Nc                      y) Helper for :meth:`from_api_repr`Nr)   clsr   s     r   _extract_payloadzLogEntry._extract_payload   s     r   )loggersc                R   |i }|d   }|j                  |      }|-	 t        ||j                        }|j                  |      x}||<   | j                  |      }|j                  d      }|j                  d      }	|	t        |	      }	|j                  d      }
|j                  d      }|j                  d      }|j                  d      }|j                  d	      }|j                  d
      }|j                  d      }| |j                  dd      }t        |      |d<   |j                  d      }|j                  d      }d}|t        j                  |      } | |||	|
||||||||||      }|j                  d      }|t        |      |_        |S # t        $ r Y [w xY w)ay  Construct an entry given its API representation

        Args:
            resource (dict): text entry resource representation returned from
                the API
            client (~logging_v2.client.Client):
                Client which holds credentials and project configuration.
            loggers (Optional[dict]):
                A mapping of logger fullnames -> loggers.  If not
                passed, the entry will have a newly-created logger if possible,
                or an empty logger field if not.

        Returns:
            google.cloud.logging.entries.LogEntry: Log entry parsed from ``resource``.
        NlogNameinsertIdr   r   r   httpRequestr   spanIdtraceSampledsourceLocationliner#   r   )r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   receiveTimestamp)getr   r   r$   
ValueErrorr6   r   popr   r
   
_from_dictreceived_timestamp)r5   r   clientr7   logger_fullnamer$   logger_namer%   r   r   r   r   r   r   r    r!   r"   r?   r#   monitored_resource_dictmonitored_resourceinstreceiveds                          r   from_api_reprzLogEntry.from_api_repr   s   " ?G"9-_->3OV^^T4:MM+4NN1 &&x0LL,	LL-	 29=Ih'<<
+||M2W%,,x( ^4",,'78&"&&vt4D&24&8OF#LL-	"*,,z":!".!)!4!45L!M$%''+
  << 23&@&JD#Y  s   ,F 	F&%F&c                    i }| j                   | j                   |d<   | j                  | j                  j                         |d<   | j                  | j                  |d<   | j                  | j                  |d<   | j
                  Gt        | j
                  t              r| j
                  j                         |d<   n| j
                  |d<   | j                  | j                  |d<   | j                  t        | j                        |d<   | j                  | j                  |d<   | j                  | j                  |d	<   | j                  | j                  |d
<   | j                  =| j                  j!                         }t        |j#                  dd            |d<   ||d<   | j$                  | j$                  |d<   |S )!API repr (JSON format) for entry.r9   r   r   r:   r   r;   r   r   r<   r=   r?   r   r>   r#   )r   r   _to_dictr   r   r   
isinstancestrupperr   r   r   r   r    r!   r"   copyrC   r#   )selfinfor"   s      r   to_api_reprzLogEntry.to_api_repr   s   ==$"mmDO==$#}}557D;;"![[DN>>%#~~D==$$---#'==#6#6#8Z #'==Z ("&"3"3D>>% 4T^^ DD::! JJDM<<#!\\DN)#'#5#5D +"22779O&)/*=*=fa*H&IOF#%4D!">>% $Dr   )__name__
__module____qualname___LOG_ENTRY_PARAM_DOCSTRING_LOG_ENTRY_SEE_ALSO_DOCSTRING__doc__rE   classmethodr6   rM   rW   r)   r   r   r&   r&      sY    	 %		%
 (	(    8< E EN r   c                   D     e Zd Zdez   dz   ez   Zed        Z fdZ xZ	S )	TextEntryz'
    Log entry with text payload.

    z8

        payload (str): payload for the log entry.
    c                     |d   S )r3   textPayloadr)   r4   s     r   r6   zTextEntry._extract_payload       &&r   c                 J    t         t        |          }| j                  |d<   |S )rO   rb   )superr`   rW   r%   rU   rV   	__class__s     r   rW   zTextEntry.to_api_repr  s%    Y13"ll]r   
rX   rY   rZ   r[   r\   r]   r^   r6   rW   __classcell__rg   s   @r   r`   r`      I    	 %		%
	 (		(  ' ' r   r`   c                   D     e Zd Zdez   dz   ez   Zed        Z fdZ xZ	S )StructEntryz'
    Log entry with JSON payload.

    z9

        payload (dict): payload for the log entry.
    c                     |d   S )r3   jsonPayloadr)   r4   s     r   r6   zStructEntry._extract_payload(  rc   r   c                 J    t         t        |          }| j                  |d<   |S )rO   ro   )re   rm   rW   r%   rf   s     r   rW   zStructEntry.to_api_repr-  s%    [$35"ll]r   rh   rj   s   @r   rm   rm     rk   r   rm   c                   j     e Zd Zdez   dz   ez   Zed        Zed        Z	ed        Z
 fdZd Z xZS )ProtobufEntryz3
    Log entry with protobuf message payload.

    zL

        payload (google.protobuf.Message): payload for the log entry.
    c                     |d   S )r3   protoPayloadr)   r4   s     r   r6   zProtobufEntry._extract_payloadB  s     ''r   c                 P    t        | j                  t              r| j                  S y r(   )rQ   r%   r	   rU   s    r   
payload_pbzProtobufEntry.payload_pbG  s    dllG,<< -r   c                 x    t        | j                  t        j                  j                        r| j                  S y r(   )rQ   r%   collectionsabcMappingrv   s    r   payload_jsonzProtobufEntry.payload_jsonL  s)    dllKOO$;$;<<< =r   c                     t         t        |          }d}| j                  rt	        | j
                        }n!| j                  rt        | j
                        }||d<   |S )rO   Nrt   )re   rr   rW   rw   r   r%   r|   dict)rU   rV   proto_payloadrg   s      r   rW   zProtobufEntry.to_api_reprQ  sR    ]D57??)$,,7M .M,^r   c                 V    t        t        j                  | j                        |       y)zParse payload into a protobuf message.

        Mutates the passed-in ``message`` in place.

        Args:
            message (google.protobuf.Message): the message to be logged
        N)r   jsondumpsr%   )rU   messages     r   parse_messagezProtobufEntry.parse_message\  s     	djj&0r   )rX   rY   rZ   r[   r\   r]   r^   r6   propertyrw   r|   rW   r   ri   rj   s   @r   rr   rr   4  sq    	 %		%
	 (		(  ( (        	1r   rr   r(   )&r]   ry   r   regoogle.cloud.appengine_logginggoogle google.cloud.audit.audit_log_pb2google.cloud._helpersr   r   r   google.iam.v1.loggingr   google.protobuf.json_formatr   r   google.protobuf.messager	    google.cloud.logging_v2.resourcer
   _GLOBAL_RESOURCEcompileVERBOSEr   r   r   _LOG_ENTRY_FIELDS
namedtuple_LogEntryTupletuple__new____defaults__r[   r\   r&   r`   rm   rr   r)   r   r   <module>r      s%   7   	 % ( 
 1 < + 5"5  2:: JJ D" !" $ (''9'89 ',+XFW+X&X   # 4! y~ yx 4( 431H 31r   