a
    !f.(                     @   s@   d Z ddlZddlZddlZG dd deZG dd deZdS )z7Client for interacting with the Stackdriver Logging API    Nc                   @   s   e Zd ZdZdddZdS )HTTPContexta  HTTPContext defines an object that captures the parameter for the
    httpRequest part of Error Reporting API

    :type method: string
    :param method: The type of HTTP request, such as GET, POST, etc.

    :type url: string
    :param url: The URL of the request

    :type user_agent: string
    :param user_agent: The user agent information that is provided with the
                       request.

    :type referrer: string
    :param referrer: The referrer information that is provided with the
                     request.

    :type response_status_code: int
    :param response_status_code: The HTTP response status code for the request.

    :type remote_ip: string
    :param remote_ip: The IP address from which the request originated. This
                      can be IPv4, IPv6, or a token which is derived from
                      the IP address, depending on the data that has been
                      provided in the error report.
    Nc                 C   s(   || _ || _|| _|| _|| _|| _d S N)methodurlZ	userAgentreferrerZresponseStatusCodeZremoteIp)selfr   r   
user_agentr   Zresponse_status_codeZ	remote_ip r	   ^/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/error_reporting/client.py__init__3   s    zHTTPContext.__init__)NNNNNN)__name__
__module____qualname____doc__r   r	   r	   r	   r
   r      s
      r   c                   @   s<   e Zd ZdZdddZdZdddZddd	Zdd
dZdS )Clienta   Error Reporting client. Currently Error Reporting is done by creating
    a Logging client.

    :type project: string
    :param project: the project which the client acts on behalf of. If not
                    passed falls back to the default inferred from the
                    environment.

    :type credentials: :class:`oauth2client.client.OAuth2Credentials` or
                       :class:`NoneType`
    :param credentials: The OAuth2 Credentials to use for the connection
                        owned by this client. If not passed (and if no ``http``
                        object is passed), falls back to the default inferred
                        from the environment.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: An optional HTTP object to make requests. If not passed, an
                 ``http`` object is created that is bound to the
                 ``credentials`` for the current object.

    :type service: str
    :param service: An identifier of the service, such as the name of the
                    executable, job, or Google App Engine service name. This
                    field is expected to have a low number of values that are
                    relatively stable over time, as opposed to version,
                    which can be changed whenever new code is deployed.


    :type version: str
    :param version: Represents the source code version that the developer
                    provided, which could represent a version label or a Git
                    SHA-1 hash, for example. If the developer did not provide
                    a version, the value is set to default.

    :raises: :class:`ValueError` if the project is neither passed in nor
             set in the environment.
    Nc                 C   s.   t jj|||| _|r|n| j| _|| _d S r   )gcloudloggingclientr   logging_clientDEFAULT_SERVICEserviceversion)r   projectcredentialshttpr   r   r	   r	   r
   r   g   s
    zClient.__init__pythonc                 C   s   d| j id|d}| jr*| j|d d< |s6|s6|r>i |d< |rN||d d< |rx|j}tdd	 t|D |d d
< |r||d d< | jd}|	| dS )a)  Makes the call to the Error Reporting API via the log stream.

        This is the lower-level interface to build the payload, generally
        users will use either report() or report_exception() to automatically
        gather the parameters for this method.

        Currently this method sends the Error Report by formatting a structured
        log message according to

        https://cloud.google.com/error-reporting/docs/formatting-error-messages

        :type message: string
        :param message: The stack trace that was reported or logged by the
                   service.

        :type report_location: dict
        :param report_location:  The location in the source code where the
               decision was made to report the error, usually the place
               where it was logged. For a logged exception this would be the
               source line where the exception is logged, usually close to
               the place where it was caught.

               This should be a Python dict that contains the keys 'filePath',
               'lineNumber', and 'functionName'

        :type http_context: :class`gcloud.error_reporting.HTTPContext`
        :param http_context: The HTTP request which was processed when the
                             error was triggered.

        :type user: string
        :param user: The user who caused or was affected by the crash. This can
                     be a user ID, an email address, or an arbitrary token that
                     uniquely identifies the user. When sending an error
                     report, leave this field empty if the user was not
                     logged in. In this  case the Error Reporting system will
                     use other data, such as remote IP address,
                     to distinguish affected users.
        r   z{0})serviceContextmessager   r   contextZreportLocationc                 s   s"   | ]\}}|d ur||fV  qd S r   r	   ).0kvr	   r	   r
   	<genexpr>   s   z,Client._send_error_report.<locals>.<genexpr>ZhttpContextusererrorsN)
r   formatr   __dict__dictsix	iteritemsr   loggerZ
log_struct)r   r   report_locationhttp_contextr#   payloadZhttp_context_dictr*   r	   r	   r
   _send_error_reports   s&    *zClient._send_error_reportc           
      C   sJ   t  }|d }|d }|d }|d }|||d}	| j||||	d dS )a"   Reports a message to Stackdriver Error Reporting
        https://cloud.google.com/error-reporting/docs/formatting-error-messages

           :type message: str
           :param message: A user-supplied message to report


          :type http_context: :class`gcloud.error_reporting.HTTPContext`
          :param http_context: The HTTP request which was processed when the
                               error was triggered.

          :type user: string
          :param user: The user who caused or was affected by the crash. This
                       can be a user ID, an email address, or an arbitrary
                       token that uniquely identifies the user. When sending
                       an error report, leave this field empty if the user
                       was not logged in. In this case the Error Reporting
                       system will use other data, such as remote IP address,
                       to distinguish affected users.

           Example::
                >>>  client.report("Something went wrong!")
        r         )ZfilePathZ
lineNumberZfunctionName)r,   r#   r+   N)	tracebackextract_stackr.   )
r   r   r,   r#   stackZ	last_call	file_pathline_numberZfunction_namer+   r	   r	   r
   report   s    zClient.reportc                 C   s   | j t ||d dS )a   Reports the details of the latest exceptions to Stackdriver Error
            Reporting.

          :type http_context: :class`gcloud.error_reporting.HTTPContext`
          :param http_context: The HTTP request which was processed when the
                               error was triggered.

          :type user: string
          :param user: The user who caused or was affected by the crash. This
                       can be a user ID, an email address, or an arbitrary
                       token that uniquely identifies the user. When sending an
                       error report, leave this field empty if the user was
                       not logged in. In this case the Error Reporting system
                       will use other data, such as remote IP address,
                       to distinguish affected users.

           Example::

                >>>     try:
                >>>         raise NameError
                >>>     except Exception:
                >>>         client.report_exception()
        )r,   r#   N)r.   r2   
format_exc)r   r,   r#   r	   r	   r
   report_exception   s    
zClient.report_exception)NNNNN)NNN)NN)NN)	r   r   r   r   r   r   r.   r7   r9   r	   r	   r	   r
   r   @   s   &     

 
G
(r   )r   r2   Zgcloud.logging.clientr   r(   objectr   r   r	   r	   r	   r
   <module>   s
   )