a
    !fC                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ edej	Z
dd ZG d	d
 d
eZG dd deZG dd deZG dd deZdS )z6Log entries within the Google Stackdriver Logging API.    N)Parse)_name_from_project_path)_rfc3339_nanos_to_datetimez
    projects/            # static prefix
    (?P<project>[^/]+)   # initial letter, wordchars + hyphen
    /logs/               # static midfix
    (?P<name>[^/]+)      # initial letter, wordchars + allowed punc
c                 C   s   t | dtS )an  Validate a logger URI path and get the logger name.

    :type path: str
    :param path: URI path for a logger API request.

    :rtype: str
    :returns: Logger name parsed from ``path``.
    :raises: :class:`ValueError` if the ``path`` is ill-formed or if
             the project from the ``path`` does not agree with the
             ``project`` passed in.
    N)r   _LOGGER_TEMPLATE)path r   W/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/logging/entries.pylogger_name_from_path"   s    r	   c                   @   s(   e Zd ZdZdddZedddZdS )	
_BaseEntrya  Base class for TextEntry, StructEntry.

    :type payload: text or dict
    :param payload: The payload passed as ``textPayload``, ``jsonPayload``,
                    or ``protoPayload``.

    :type logger: :class:`gcloud.logging.logger.Logger`
    :param logger: the logger used to write the entry.

    :type insert_id: text, or :class:`NoneType`
    :param insert_id: (optional) the ID used to identify an entry uniquely.

    :type timestamp: :class:`datetime.datetime`, or :class:`NoneType`
    :param timestamp: (optional) timestamp for the entry

    :type labels: dict or :class:`NoneType`
    :param labels: (optional) mapping of labels for the entry

    :type severity: string or :class:`NoneType`
    :param severity: (optional) severity of event being logged.

    :type http_request: dict or :class:`NoneType`
    :param http_request: (optional) info about HTTP request associated with
                         the entry
    Nc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S )N)payloadlogger	insert_id	timestamplabelsseverityhttp_request)selfr   r   r   r   r   r   r   r   r   r   __init__K   s    z_BaseEntry.__init__c              	   C   s   |du ri }|d }| |}|du r@t|}|| }||< || j }| d}| d}	|	durnt|	}	| d}
| d}| d}| ||||	|
||dS )	a  Factory:  construct an entry given its API representation

        :type resource: dict
        :param resource: text entry resource representation returned from
                         the API

        :type client: :class:`gcloud.logging.client.Client`
        :param client: Client which holds credentials and project
                       configuration.

        :type loggers: dict or None
        :param loggers: A mapping of logger fullnames -> loggers.  If not
                        passed, the entry will have a newly-created logger.

        :rtype: :class:`gcloud.logging.entries.TextEntry`
        :returns: Text entry parsed from ``resource``.
        NZlogNameZinsertIdr   r   r   ZhttpRequest)r   r   r   r   r   )getr	   r   _PAYLOAD_KEYr   )clsresourceclientloggersZlogger_fullnamer   Zlogger_namer   r   r   r   r   r   r   r   r   from_api_reprU   s$    







z_BaseEntry.from_api_repr)NNNNN)N)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r   r
   1   s     

r
   c                   @   s   e Zd ZdZdZdS )	TextEntryzEntry created with ``textPayload``.

    See:
    https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/LogEntry
    ZtextPayloadNr   r   r   r   r   r   r   r   r   r    {   s   r    c                   @   s   e Zd ZdZdZdS )StructEntryzEntry created with ``jsonPayload``.

    See:
    https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/LogEntry
    ZjsonPayloadNr!   r   r   r   r   r"      s   r"   c                   @   s   e Zd ZdZdZdd ZdS )ProtobufEntryzEntry created with ``protoPayload``.

    See:
    https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/LogEntry
    ZprotoPayloadc                 C   s   t t| j| dS )zParse payload into a protobuf message.

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

        :type message: Protobuf message
        :param message: the message to be logged
        N)r   jsondumpsr   )r   messager   r   r   parse_message   s    zProtobufEntry.parse_messageN)r   r   r   r   r   r'   r   r   r   r   r#      s   r#   )r   r$   reZgoogle.protobuf.json_formatr   Zgcloud._helpersr   r   compileVERBOSEr   r	   objectr
   r    r"   r#   r   r   r   r   <module>   s   J		