o
    Mf                     @   s$   d Z ddlmZ G dd deZdS )z!Define Cloud Logging API Metrics.    )NotFoundc                   @   s   e Zd ZdZddddddZedd Zed	d
 Zedd Zedd Z	e
dd Zdd ZddddZddddZddddZddddZddddZdS )MetriczMetrics represent named filters for log entries.

    See
    https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics
    N filter_clientdescriptionc                C   s   || _ || _|| _|| _dS )a.  
        Args:
            name (str): The name of the metric.
            filter_ (str): the advanced logs filter expression defining the entries
                   tracked by the metric.  If not passed, the instance should
                   already exist, to be refreshed via :meth:`reload`.
            client (Optional[~logging_v2.client.Client]): A client which holds
                credentials and project configuration for the sink (which requires a project).
            description (Optional[str]): An optional description of the metric.

        N)name_clientr   r   )selfr	   r   r   r    r   `/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/google/cloud/logging_v2/metric.py__init__   s   
zMetric.__init__c                 C   s   | j S )zClent bound to the logger.r
   r   r   r   r   r   ,   s   zMetric.clientc                 C   s   | j jS )zProject bound to the logger.)r
   projectr   r   r   r   r   1   s   zMetric.projectc                 C   s   d| j  d| j S )z(Fully-qualified name used in metric APIsz	projects/z	/metrics/)r   r	   r   r   r   r   	full_name6   s   zMetric.full_namec                 C   s   d| j  S )zURL path for the metric's APIs/)r   r   r   r   r   path;   s   zMetric.pathc                 C   s,   |d }|d }| dd}| ||||dS )ad  Construct a metric given its API representation

        Args:
            resource (dict): metric resource representation returned from the API
            client (~logging_v2.client.Client): Client which holds
                credentials and project configuration for the sink.

        Returns:
            google.cloud.logging_v2.metric.Metric
        r	   filterr   r   r   )get)clsresourcer   metric_namer   r   r   r   r   from_api_repr@   s   zMetric.from_api_reprc                 C   s   |du r| j }|S )a  Check client or verify over-ride. Also sets ``parent``.

        Args:
            client (Union[None, ~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.

        Returns:
            google.cloud.logging_v2.client.Client: The client passed in
                or the currently bound client.
        Nr   r   r   r   r   r   _require_clientQ   s   zMetric._require_client)r   c                C   (   |  |}|j| j| j| j| j dS )aY  Create the metric via a PUT request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/create

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        N)r   metrics_apimetric_creater   r	   r   r   r   r   r   r   createa      
zMetric.createc                C   s8   |  |}z|j| j| j W dS  ty   Y dS w )a  Test for the existence of the metric via a GET request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/get

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.

        Returns:
            bool: Boolean indicating existence of the metric.
        FT)r   r   
metric_getr   r	   r   r   r   r   r   existsq   s   
zMetric.existsc                C   s8   |  |}|j| j| j}|dd| _|d | _dS )ao  API call:  sync local metric configuration via a GET request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/get

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        r   r   r   N)r   r   r"   r   r	   r   r   r   )r   r   datar   r   r   reload   s   
zMetric.reloadc                C   r   )an  API call:  update metric configuration via a PUT request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/update

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        N)r   r   metric_updater   r	   r   r   r   r   r   r   update   r!   zMetric.updatec                C   s    |  |}|j| j| j dS )ae  API call:  delete a metric via a DELETE request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.metrics/delete

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        N)r   r   metric_deleter   r	   r   r   r   r   delete   s   
zMetric.delete)__name__
__module____qualname____doc__r   propertyr   r   r   r   classmethodr   r   r    r#   r%   r'   r)   r   r   r   r   r      s&    




r   N)r-   google.cloud.exceptionsr   objectr   r   r   r   r   <module>   s   