HEX
Server: LiteSpeed
System: Linux server.nevid-deploma.com 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
User: smilepac (1037)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cppython/lib/python3.8/site-packages/botocore/__pycache__/monitoring.cpython-38.pyc
U

KD�guP�@s�ddlZddlZddlZddlZddlmZmZmZddlm	Z
e�e�Z
Gdd�d�ZGdd�d�ZGdd	�d	�ZGd
d�de�ZGdd
�d
e�ZGdd�d�ZGdd�d�ZdS)�N)�ensure_bytes�ensure_unicode�urlparse)�
EXCEPTION_MAPc@s2eZdZdddddgZdd�Zdd	�Zd
d�ZdS)
�Monitorzbefore-parameter-buildzrequest-createdzresponse-receivedz
after-callzafter-call-errorcCs||_||_dS)z�Abstraction for monitoring clients API calls

        :param adapter: An adapter that takes event emitter events
            and produces monitor events

        :param publisher: A publisher for generated monitor events
        N)�_adapter�
_publisher)�self�adapterZ	publisher�r�@/opt/cppython/lib/python3.8/site-packages/botocore/monitoring.py�__init__!szMonitor.__init__cCs|jD]}|�||j�qdS)z(Register an event emitter to the monitorN)�_EVENTS_TO_REGISTERZ
register_last�capture)r	Z
event_emitterZevent_to_registerrrr�register,s
zMonitor.registerc
Ks\z"|j�||�}|r |j�|�Wn4tk
rV}ztjd||dd�W5d}~XYnXdS)z�Captures an incoming event from the event emitter

        It will feed an event emitter event to the monitor's adaptor to create
        a monitor event and then publish that event to the monitor's publisher.
        z:Exception %s raised by client monitor in handling event %sT)�exc_infoN)r�feedr�publish�	Exception�logger�debug)r	�
event_name�payloadZ
monitor_event�errrr1s�zMonitor.captureN)�__name__�
__module__�__qualname__rr
rrrrrrrs�rc@sreZdZejfdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�MonitorEventAdaptercCs
||_dS)z�Adapts event emitter events to produce monitor events

        :type time: callable
        :param time: A callable that produces the current time
        N)�_time)r	�timerrrr
EszMonitorEventAdapter.__init__cCs|�|�f|�S)a�Feed an event emitter event to generate a monitor event

        :type emitter_event_name: str
        :param emitter_event_name: The name of the event emitted

        :type emitter_payload: dict
        :param emitter_payload: The payload to associated to the event
            emitted

        :rtype: BaseMonitorEvent
        :returns: A monitor event based on the event emitter events
            fired
        )�_get_handler)r	Zemitter_event_nameZemitter_payloadrrrrMszMonitorEventAdapter.feedcCs t|d|�d�d�dd��S)NZ_handle_�.r�-�_)�getattr�split�replace)r	rrrrr ]s�z MonitorEventAdapter._get_handlercKs t|jj|j|��d�|d<dS)N��service�	operation�	timestamp�current_api_call_event)�APICallEventZ
service_modelZ
service_idZ	wire_name�_get_current_time)r	�model�context�kwargsrrr�_handle_before_parameter_buildbs
�z2MonitorEventAdapter._handle_before_parameter_buildcKs6|j}|dj|��d�}|j|_|j|_||d<dS)Nr+)r*�current_api_call_attempt_event)r/�new_api_call_attemptr-�headers�request_headers�url)r	�requestr0r/Znew_attempt_eventrrr�_handle_request_createdis��z+MonitorEventAdapter._handle_request_createdcKsR|�d�}|�|�|_|dk	rH|dd|_|dd|_|�d�|_n||_|S)Nr2�ResponseMetadataZHTTPStatusCodeZHTTPHeaders�Error)�pop�_get_latency�latency�http_status_code�response_headers�get�parsed_error�wire_exception)r	Zparsed_responser/�	exceptionr0�
attempt_eventrrr�_handle_response_receivedrs 
����z-MonitorEventAdapter._handle_response_receivedcKs |d�dd�|d_|�|�S)Nr9ZMaxAttemptsReachedFr+)r@�retries_exceeded�_complete_api_call)r	r/�parsedr0rrr�_handle_after_call�s��
z&MonitorEventAdapter._handle_after_callcKs|�|�|d_|�|�S�Nr+)�_is_retryable_exceptionrFrG)r	r/rCr0rrr�_handle_after_call_error�s
��z,MonitorEventAdapter._handle_after_call_errorcCst|ttd��S)NZGENERAL_CONNECTION_ERROR)�
isinstance�tuple�RETRYABLE_EXCEPTIONS)r	rCrrrrK�s
�z+MonitorEventAdapter._is_retryable_exceptioncCs|�d�}|�|�|_|SrJ)r;r<r=)r	r/Z
call_eventrrrrG�s
z&MonitorEventAdapter._complete_api_callcCs|��|jS�N)r-r*�r	�eventrrrr<�sz MonitorEventAdapter._get_latencycCst|��d�S)Ni�)�intr�r	rrrr-�sz%MonitorEventAdapter._get_current_timeN)rrrrr
rr r1r8rErIrLrKrGr<r-rrrrrDs	
rc@s$eZdZdd�Zdd�Zdd�ZdS)�BaseMonitorEventcCs||_||_||_dS)a�Base monitor event

        :type service: str
        :param service: A string identifying the service associated to
            the event

        :type operation: str
        :param operation: A string identifying the operation of service
            associated to the event

        :type timestamp: int
        :param timestamp: Epoch time in milliseconds from when the event began
        Nr')r	r(r)r*rrrr
�szBaseMonitorEvent.__init__cCs|jj�d|j�d�S)N�(�))�	__class__r�__dict__rTrrr�__repr__�szBaseMonitorEvent.__repr__cCst||j�r|j|jkSdS)NF)rMrXrY)r	�otherrrr�__eq__�szBaseMonitorEvent.__eq__N)rrrr
rZr\rrrrrU�srUcs&eZdZd�fdd�	Zdd�Z�ZS)r,NFcs6t�j|||d�||_||_|dkr,g|_||_dS)a�Monitor event for a single API call

        This event corresponds to a single client method call, which includes
        every HTTP requests attempt made in order to complete the client call

        :type service: str
        :param service: A string identifying the service associated to
            the event

        :type operation: str
        :param operation: A string identifying the operation of service
            associated to the event

        :type timestamp: int
        :param timestamp: Epoch time in milliseconds from when the event began

        :type latency: int
        :param latency: The time in milliseconds to complete the client call

        :type attempts: list
        :param attempts: The list of APICallAttempts associated to the
            APICall

        :type retries_exceeded: bool
        :param retries_exceeded: True if API call exceeded retries. False
            otherwise
        r'N)�superr
r=�attemptsrF)r	r(r)r*r=r^rF�rXrrr
�s$�zAPICallEvent.__init__cCs"t|j|j|d�}|j�|�|S)z�Instantiates APICallAttemptEvent associated to the APICallEvent

        :type timestamp: int
        :param timestamp: Epoch time in milliseconds to associate to the
            APICallAttemptEvent
        r')�APICallAttemptEventr(r)r^�append)r	r*rDrrrr3�s�z!APICallEvent.new_api_call_attempt)NNF)rrrr
r3�
__classcell__rrr_rr,�s
�-r,cseZdZd�fdd�	Z�ZS)r`Ncs@t�j|||d�||_||_||_||_||_|	|_|
|_dS)a�Monitor event for a single API call attempt

        This event corresponds to a single HTTP request attempt in completing
        the entire client method call.

        :type service: str
        :param service: A string identifying the service associated to
            the event

        :type operation: str
        :param operation: A string identifying the operation of service
            associated to the event

        :type timestamp: int
        :param timestamp: Epoch time in milliseconds from when the HTTP request
            started

        :type latency: int
        :param latency: The time in milliseconds to complete the HTTP request
            whether it succeeded or failed

        :type url: str
        :param url: The URL the attempt was sent to

        :type http_status_code: int
        :param http_status_code: The HTTP status code of the HTTP response
            if there was a response

        :type request_headers: dict
        :param request_headers: The HTTP headers sent in making the HTTP
            request

        :type response_headers: dict
        :param response_headers: The HTTP headers returned in the HTTP response
            if there was a response

        :type parsed_error: dict
        :param parsed_error: The error parsed if the service returned an
            error back

        :type wire_exception: Exception
        :param wire_exception: The exception raised in sending the HTTP
            request (i.e. ConnectionError)
        r'N)	r]r
r=r6r>r5r?rArB)r	r(r)r*r=r6r>r5r?rArBr_rrr
�s9�zAPICallAttemptEvent.__init__)NNNNNNN)rrrr
rbrrr_rr`�s�r`c@s&eZdZdZdZdZdZdZdddd�Ze	�
d	�e	�
d
�d�Zdd
ddddddddddgZdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Z d@dA�Z!dBdC�Z"dDdE�Z#dFdG�Z$dHdI�Z%dJS)K�
CSMSerializer���iZXAmznRequestIdZ
XAmzRequestIdZXAmzId2)zx-amzn-requestidzx-amz-request-idz
x-amz-id-2zSAWS4-HMAC-SHA256 Credential=(?P<access_key>\w+)/\d+/(?P<signing_region>[a-z0-9-]+)/zAWS (?P<access_key>\w+):)�v4Zs3r(r)r*r^r=rFr6r5r>r?rArBcCs|�|�||_dS)z�Serializes monitor events to CSM (Client Side Monitoring) format

        :type csm_client_id: str
        :param csm_client_id: The application identifier to associate
            to the serialized events
        N)�_validate_client_id�
csm_client_id�r	rirrrr
ds
zCSMSerializer.__init__cCs*t|�|jkr&td|�d|j�d���dS)Nz&The value provided for csm_client_id: z exceeds the maximum length of z characters)�len�_MAX_CLIENT_ID_LENGTH�
ValueErrorrjrrrrhns�z!CSMSerializer._validate_client_idcCsf|�|�}|�|�}||d<|jD]0}t||d�}|dk	r"t|d|�|||d�q"ttj|dd��S)z�Serializes a monitor event to the CSM format

        :type event: BaseMonitorEvent
        :param event: The event to serialize to bytes

        :rtype: bytes
        :returns: The CSM serialized form of the event
        �TypeNZ_serialize_)�
event_type)�,�:)�
separators)�_get_base_event_dict�_get_event_type�_SERIALIZEABLE_EVENT_PROPERTIESr$r�json�dumps)r	rR�
event_dictro�attr�valuerrr�	serializeus	


�zCSMSerializer.serializecCsd|jd�S)N�)�VersionZClientId)rirQrrrrs�s�z"CSMSerializer._get_base_event_dictcKs||d<dS)NZServicer)r	r(rxr0rrr�_serialize_service�sz CSMSerializer._serialize_servicecKs||d<dS)NZApir)r	r)rxr0rrr�_serialize_operation�sz"CSMSerializer._serialize_operationcKs||d<dS)N�	Timestampr)r	r*rxr0rrr�_serialize_timestamp�sz"CSMSerializer._serialize_timestampcKs$t|�|d<|r |�||d�dS)NZAttemptCount���)rk�_add_fields_from_last_attempt)r	r^rxr0rrr�_serialize_attempts�sz!CSMSerializer._serialize_attemptscCs~|jr2|�|j�}|dk	r"||d<|�|j�|d<|jdk	rF|j|d<|jdk	r`|�|j|d�|jdk	rz|�|j|d�dS)N�Region�	UserAgentZFinalHttpStatusCode�ApiCall)r5�_get_region�_get_user_agentr>rA�_serialize_parsed_errorrB�_serialize_wire_exception)r	rxZlast_attempt�regionrrrr��s*�


�
�z+CSMSerializer._add_fields_from_last_attemptcCs&|dkr||d<n|dkr"||d<dS)Nr�ZLatency�ApiCallAttemptZAttemptLatencyr)r	r=rxrorrr�_serialize_latency�s
z CSMSerializer._serialize_latencycKs|rdnd|d<dS)Nr|rZMaxRetriesExceededr)r	rFrxr0rrr�_serialize_retries_exceeded�sz)CSMSerializer._serialize_retries_exceededcKst|�j|d<dS)NZFqdn)r�netloc)r	r6rxr0rrr�_serialize_url�szCSMSerializer._serialize_urlcKsX|�|�|d<|�|�r&|�|�|d<|�|�}|dk	r@||d<d|krT|d|d<dS)Nr�Z	AccessKeyr�zX-Amz-Security-TokenZSessionToken)r��
_is_signed�_get_access_keyr�)r	r5rxr0r�rrr�_serialize_request_headers�s

�z(CSMSerializer._serialize_request_headerscKs||d<dS)NZHttpStatusCoder)r	r>rxr0rrr�_serialize_http_status_code�sz)CSMSerializer._serialize_http_status_codecKs,|j��D]\}}||kr
||||<q
dSrP)�"_RESPONSE_HEADERS_TO_EVENT_ENTRIES�items)r	r?rxr0�header�entryrrr�_serialize_response_headers�sz)CSMSerializer._serialize_response_headerscKsH|dkrdnd}|�|d|j�||d<|�|d|j�||d<dS)Nr��Final�ZCodeZAwsException�MessageZAwsExceptionMessage)�	_truncate�_MAX_ERROR_CODE_LENGTH�_MAX_MESSAGE_LENGTH)r	rArxror0�field_prefixrrrr��s��z%CSMSerializer._serialize_parsed_errorcKsH|dkrdnd}|�|jj|j�||d<|�t|�|j�||d<dS)Nr�r�r�ZSdkExceptionZSdkExceptionMessage)r�rXr�_MAX_EXCEPTION_CLASS_LENGTH�strr�)r	rBrxror0r�rrrr��s��z'CSMSerializer._serialize_wire_exceptioncCs t|t�rdSt|t�rdSdS)Nr�r�)rMr,r`rQrrrrt�s

zCSMSerializer._get_event_typecCs"|�|�}|�|�\}}|�d�S)NZ
access_key)�_get_auth_value�_get_auth_match�group)r	r5�auth_valr#�
auth_matchrrrr��s
zCSMSerializer._get_access_keycCs<|�|�sdS|�|�}|�|�\}}|dkr2dS|�d�S)NrgZsigning_region)r�r�r�r�)r	r5r��signature_versionr�rrrr��s

zCSMSerializer._get_regioncCs|�t|�dd��|j�S)Nz
User-Agentr�)r�rr@�_MAX_USER_AGENT_LENGTH�r	r5rrrr�s�zCSMSerializer._get_user_agentcCsd|kS�N�
Authorizationrr�rrrr�
szCSMSerializer._is_signedcCst|d�Sr�)rr�rrrr�
szCSMSerializer._get_auth_valuecCs2|j��D]"\}}|�|�}|r
||fSq
dS)N)NN)�_AUTH_REGEXSr��match)r	r�r��regexr�rrrr�s

zCSMSerializer._get_auth_matchcCs*t|�|kr&t�d||�|d|�S|S)Nz6Truncating following value to maximum length of %s: %s)rkrr)r	�text�
max_lengthrrrr�s�zCSMSerializer._truncateN)&rrrrlr�r�r�r�r��re�compiler�rur
rhr{rsr~rr�r�r�r�r�r�r�r�r�r�r�rtr�r�r�r�r�r�r�rrrrrcBsh���	�
	rcc@s eZdZdZdd�Zdd�ZdS)�SocketPublisheri cCs||_||f|_||_dS)a)Publishes monitor events to a socket

        :type socket: socket.socket
        :param socket: The socket object to use to publish events

        :type host: string
        :param host: The host to send events to

        :type port: integer
        :param port: The port on the host to send events to

        :param serializer: The serializer to use to serialize the event
            to a form that can be published to the socket. This must
            have a `serialize()` method that accepts a monitor event
            and return bytes
        N)�_socket�_address�_serializer)r	�socket�host�port�
serializerrrrr
%s
zSocketPublisher.__init__cCsF|j�|�}t|�|jkr2t�dt|�|j�dS|j�||j�dS)z�Publishes a specified monitor event

        :type event: BaseMonitorEvent
        :param event: The monitor event to be sent
            over the publisher's socket to the desired address.
        z`Serialized event of size %s exceeds the maximum length allowed: %s. Not sending event to socket.N)	r�r{rk�_MAX_MONITOR_EVENT_LENGTHrrr��sendtor�)r	rRZserialized_eventrrrr:s�zSocketPublisher.publishN)rrrr�r
rrrrrr�"sr�)rv�loggingr�rZbotocore.compatrrrZbotocore.retryhandlerrrO�	getLoggerrrrrrUr,r`rcr�rrrr�<module>
s
,`<Fa