+
     IirP  c                   s    ^ RI t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIH	t
 ]P                  ! ]4      t ! R R4      t ! R R4      t ! R R	4      t ! R
 R]4      t ! R R]4      t ! R R4      t ! R R4      tR# )i    N)ensure_bytesensure_unicodeurlparse)EXCEPTION_MAPc                   s:   a  ] tR t^t o . ROtR tR tR tRtV t	R# )Monitorc                s    Wn         W n        R# )zAbstraction 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)selfZadapterZ	publisher   &&&8/usr/lib/python3.14/site-packages/botocore/monitoring.py__init__ZMonitor.__init__!   s      #    c                sb    V P                    F  pVP                  W P                  4       K   	  R# )z(Register an event emitter to the monitorN)_EVENTS_TO_REGISTERZregister_lastcapture)r   Zevent_emitterZevent_to_register   && r
   registerZMonitor.register,   s&    !%!9!9''(9<<H ":r   c                s     V P                   P                  W4      pV'       d   V P                  P                  V4       R# R#   \         d%   p\
        P                  RTTRR7        Rp?R# Rp?ii ; i)zCaptures 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)Zexc_infoN)r   feedr   publishZ	Exceptionloggerdebug)r   
event_nameZpayloadZmonitor_eventZe   &&,  r
   r   ZMonitor.capture1   sg    
	 MM..zCM''6  	LLL	   	s   >A A3A..A3r   N)zbefore-parameter-buildzrequest-createdzresponse-receivedz
after-callzafter-call-error)
__name__
__module____qualname____firstlineno__r   r   r   r   __static_attributes____classdictcell____classdict__   @r
   r   r      s"     	$I
 r   r   c                   s   a  ] tR t^Dt o ]P                  3R ltR tR tR tR t	R t
R tR tR	 tR
 tR tR tRtV tR# )MonitorEventAdapterc                s    Wn         R# )zAdapts event emitter events to produce monitor events

:type time: callable
:param time: A callable that produces the current time
N_time)r   time   &&r
   r   ZMonitorEventAdapter.__init__E   s	     
r   c                s0    V P                  V4      ! R/ VB # )aX  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   Zemitter_event_nameZemitter_payloadr	   r
   r   ZMonitorEventAdapter.feedM   s       !34GGGr   c                st    \        V R VP                  R4      ^ ,          P                  RR4      ,           4      # )Z_handle_Z.Z-_)getattrZsplitZreplace)r   r   r$   r
   r&   Z MonitorEventAdapter._get_handler]   s6    *z//4Q7??SII
 	
r   c                s    \        VP                  P                  VP                  V P	                  4       R 7      VR&   R# )service	operation	timestampcurrent_api_call_eventN)APICallEventZservice_modelZ
service_idZ	wire_name_get_current_time)r   Zmodelcontextkwargs   &&&,r
   _handle_before_parameter_buildZ2MonitorEventAdapter._handle_before_parameter_buildb   s4    ,8''22oo,,.-
()r   c                s    VP                   pVR ,          P                  V P                  4       R7      pVP                  Vn        VP
                  Vn        WCR&   R# )r-   )r,   current_api_call_attempt_eventN)r0   new_api_call_attemptr/   Zheadersrequest_headersurl)r   Zrequestr1   r0   Znew_attempt_eventr   r
   _handle_request_createdZ+MonitorEventAdapter._handle_request_createdi   sW    //#$


)?)?)A

B 	 -4OO) '4E01r   c                s    VP                  R 4      pV P                  V4      Vn        VeC   VR,          R,          Vn        VR,          R,          Vn        VP                  R4      Vn        V# W5n        V# )r4   ResponseMetadataZHTTPStatusCodeZHTTPHeadersZError)pop_get_latencylatencyhttp_status_coderesponse_headersgetparsed_errorwire_exception)r   Zparsed_responser0   	exceptionr1   attempt_event   &&&&, r
   _handle_response_receivedZ-MonitorEventAdapter._handle_response_receivedr   s      $DE $ 1 1- @&-<".. M* .="..M* *9)<)<W)EM&  ,5(r   c                sn    VR ,          P                  RR4      VR,          n        V P                  V4      # )r9   ZMaxAttemptsReachedFr-   )r?   retries_exceeded_complete_api_call)r   r0   Zparsedr1   r2   r
   _handle_after_callZ&MonitorEventAdapter._handle_after_call   s;    =C>

#"E
* 	(): &&w//r   c                s^    V P                  V4      VR ,          n        V P                  V4      # r-   )_is_retryable_exceptionrF   rG   )r   r0   rB   r1   r2   r
   _handle_after_call_errorZ,MonitorEventAdapter._handle_after_call_error   s3     "99)D 	$	

&&w//r   c                sB    \        V\        \        R ,          4      4      # )ZGENERAL_CONNECTION_ERROR)
isinstanceZtupleRETRYABLE_EXCEPTIONS)r   rB   r$   r
   rJ   Z+MonitorEventAdapter._is_retryable_exception   s     u12LMN
 	
r   c                sT    VP                  R 4      pV P                  V4      Vn        V# rI   )r:   r;   r<   )r   r0   Z
call_eventr   r
   rG   Z&MonitorEventAdapter._complete_api_call   s*    [[!9:
!..z:
r   c                sD    V P                  4       VP                  ,
          # N)r/   r,   r   eventr$   r
   r;   Z MonitorEventAdapter._get_latency   s    %%'%//99r   c                sB    \        V P                  4       R ,          4      # )i  )Zintr"   r      &r
   r/   Z%MonitorEventAdapter._get_current_time   s    4::<$&''r   r!   N)r   r   r   r   r#   r   r   r&   r3   r8   rE   rH   rK   rJ   rG   r;   r/   r   r   r   r   r
   r    r    D   sO      II H 


F"00


:( (r   r    c                   s2   a  ] tR t^t o R tR tR tRtV tR# )BaseMonitorEventc                s*    Wn         W n        W0n        R# )aC  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,      &&&&r
   r   ZBaseMonitorEvent.__init__   s     ""r   c                sP    V P                   P                   R V P                  : R2# )Z(Z))	__class__r   __dict__rQ   rR   r
   __repr__ZBaseMonitorEvent.__repr__   s%    ..))*!DMM+<A>>r   c                sn    \        WP                  4      '       d   V P                  VP                  8H  # R # )F)rL   rU   rV   )r   Zotherr$   r
   __eq__ZBaseMonitorEvent.__eq__   s'    e^^,,==ENN22r   )r+   r*   r,   N)	r   r   r   r   r   rW   rX   r   r   r   r   r
   rS   rS      s     #$? r   rS   c                   s<   a a ] tR t^t oRV 3R lltR tRtVtV ;t# )r.   c                sd   < \         SV `  WVR7       W@n        WPn        Vf   . V n        W`n        R# )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<   rZ   rF   rU   s   &&&&&&&r
   r   ZAPICallEvent.__init__   s<    H 	I 	 	
  DM 0r   c                s    \        V P                  V P                  VR7      pV P                  P	                  V4       V# )zInstantiates APICallAttemptEvent associated to the APICallEvent

:type timestamp: int
:param timestamp: Epoch time in milliseconds to associate to the
    APICallAttemptEvent
r)   )APICallAttemptEventr*   r+   rZ   Zappend)r   r,   rC   r   r
   r5   Z!APICallEvent.new_api_call_attempt   s7     ,LLDNNi
 	]+r   )rZ   r<   rF   )NNF)	r   r   r   r   r   r5   r   r   __classcell__rU   r      @@r
   r.   r.      s     +1Z r   r.   c                   s6   a a ] tR t^t oRV 3R lltRtVtV ;t# )r[   c                s~   < \         SV `  WVR7       W@n        WPn        W`n        Wpn        Wn        Wn        Wn        R# )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)	rY   r   r<   r7   r=   r6   r>   r@   rA   )r   r*   r+   r,   r<   r7   r=   r6   r>   r@   rA   rU   s   &&&&&&&&&&&r
   r   ZAPICallAttemptEvent.__init__   sG    r 	I 	 	
  0. 0(,r   )r=   r<   r@   r6   r>   r7   rA   )NNNNNNN)r   r   r   r   r   r   r   r\   r]   r^   r
   r[   r[      s     B- B-r   r[   c                   s.  a  ] tR tRt o ^t^t^tRtRtRRRRRR	/t	R
]
P                  ! R4      R]
P                  ! R4      /t. R)OtR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR  t R! t!R" t"R# t#R$ t$R% t%R& t&R't'V t(R(# )*CSMSerializeriB  i   i   zx-amzn-requestidZXAmznRequestIdzx-amz-request-idZXAmzRequestIdz
x-amz-id-2ZXAmzId2v4zSAWS4-HMAC-SHA256 Credential=(?P<access_key>\w+)/\d+/(?P<signing_region>[a-z0-9-]+)/Zs3zAWS (?P<access_key>\w+):c                s4    V P                  V4       Wn        R# )zSerializes 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   rb   r$   r
   r   ZCSMSerializer.__init__d  s     	  /*r   c                sr    \        V4      V P                  8  d   \        R V RV P                   R24      hR# )z&The value provided for csm_client_id: z exceeds the maximum length of z charactersN)len_MAX_CLIENT_ID_LENGTHZ
ValueErrorrc   r$   r
   ra   Z!CSMSerializer._validate_client_idn  sH    } : ::8 H))-)C)C(DKQ  ;r   c                s   V P                  V4      pV P                  V4      pW2R&   V P                   F0  p\        WR4      pVf   K  \        V RV,           4      ! WRVR7       K2  	  \	        \
        P                  ! VRR7      4      # )zSerializes 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
ZTypeNZ_serialize_)
event_type)Z
separators)Z,Z:)_get_base_event_dict_get_event_type_SERIALIZEABLE_EVENT_PROPERTIESr(   r    jsonZdumps)r   rP   
event_dictrf   ZattrZvalues   &&    r
   	serializeZCSMSerializer.serializeu  s     ..u5
))%0
'688DE.E md23* 9 DJJzjIJJr   c                s"    R ^RV P                   /# )ZVersionZClientIdrb   rO   r$   r
   rg   Z"CSMSerializer._get_base_event_dict  s    q**
 	
r   c                    WR &   R# )ZServiceNr%   )r   r*   rk   r1   r2   r
   _serialize_serviceZ CSMSerializer._serialize_service  s
     '9r   c                rn   )ZApiNr%   )r   r+   rk   r1   r2   r
   _serialize_operationZ"CSMSerializer._serialize_operation  s
    %5r   c                rn   )Z	TimestampNr%   )r   r,   rk   r1   r2   r
   _serialize_timestampZ"CSMSerializer._serialize_timestamp  s
    "+;r   c                sf    \        V4      VR &   V'       d   V P                  W!R,          4       R# R# )ZAttemptCountNi)rd   _add_fields_from_last_attempt)r   rZ   rk   r1   r2   r
   _serialize_attemptsZ!CSMSerializer._serialize_attempts  s*    %(]
>"..zB<H r   c                s   VP                   '       dB   V P                  VP                   4      pVe   W1R&   V P                  VP                   4      VR&   VP                  e   VP                  VR&   VP                  e   V P                  VP                  VR4       VP                  e    V P                  VP                  VR4       R # R # )NRegion	UserAgentZFinalHttpStatusCodeApiCall)r6   _get_region_get_user_agentr=   r@   _serialize_parsed_errorrA   _serialize_wire_exception)r   rk   Zlast_attemptregions   &&& r
   rr   Z+CSMSerializer._add_fields_from_last_attempt  s    ''' %%l&B&BCF!'-8$&*&:&:,,'J{# ((40<0M0MJ,-$$0(()):y &&2**++Z 3r   c                s:    VR 8X  d   WR&   R# VR8X  d   WR&   R# R# )rv   ZLatencyApiCallAttemptZAttemptLatencyNr%   )r   r<   rk   rf   rT   r
   _serialize_latencyZ CSMSerializer._serialize_latency  s)    "$+y!+++2'( ,r   c                s$    V'       d   ^M^ VR&   R# )i   ZMaxRetriesExceededNr%   )r   rF   rk   r1   r2   r
   _serialize_retries_exceededZ)CSMSerializer._serialize_retries_exceeded  s     1A1a
'(r   c                s6    \        V4      P                  VR &   R# )ZFqdnN)r   Znetloc)r   r7   rk   r1   r2   r
   _serialize_urlZCSMSerializer._serialize_url  s    %c]11
6r   c                s    V P                  V4      VR &   V P                  V4      '       d   V P                  V4      VR&   V P                  V4      pVe   WBR&   RV9   d   VR,          VR&   R# R# )ru   Z	AccessKeyNrt   zX-Amz-Security-TokenZSessionToken)rx   
_is_signed_get_access_keyrw   )r   r6   rk   r1   r{   s   &&&, r
   _serialize_request_headersZ(CSMSerializer._serialize_request_headers  sz     #'"6"6"G
;???++&*&:&:?&KJ{#!!/2#)x !_4)8&*J~& 5r   c                rn   )ZHttpStatusCodeNr%   )r   r=   rk   r1   r2   r
   _serialize_http_status_codeZ)CSMSerializer._serialize_http_status_code  s     (8#$r   c                sp    V P                   P                  4        F  w  rEWA9   g   K  W,          W%&   K  	  R # rN   )"_RESPONSE_HEADERS_TO_EVENT_ENTRIESitems)r   r>   rk   r1   ZheaderZentrys   &&&,  r
   _serialize_response_headersZ)CSMSerializer._serialize_response_headers  s1     "DDJJLMF)$4$<
! Mr   c                s    VR 8X  d   RMRpV P                  VR,          V P                  4      W%R,           &   V P                  VR,          V P                  4      W%R,           &   R# )rv   Final ZCodeZAwsExceptionZMessageZAwsExceptionMessageN)	_truncate_MAX_ERROR_CODE_LENGTH_MAX_MESSAGE_LENGTH)r   r@   rk   rf   r1   field_prefixrD   r
   ry   Z%CSMSerializer._serialize_parsed_error  sb     #-	"9wr48NN $"="=5

.01 <@>>#T%=%=<

"778r   c                s    VR 8X  d   RMRpV P                  VP                  P                  V P                  4      W%R,           &   V P                  \	        V4      V P
                  4      W%R,           &   R# )rv   r   r   ZSdkExceptionZSdkExceptionMessageN)r   rU   r   _MAX_EXCEPTION_CLASS_LENGTHZstrr   )r   rA   rk   rf   r1   r   rD   r
   rz   Z'CSMSerializer._serialize_wire_exception  si     #-	"9wr48NN$$--t/O/O5

.01 <@>>!9!9<

"778r   c                sf    \        V\        4      '       d   R # \        V\        4      '       d   R# R# )rv   r|   N)rL   r.   r[   rO   r$   r
   rh   ZCSMSerializer._get_event_type  s(    e\**233# 4r   c                sl    V P                  V4      pV P                  V4      w  r4VP                  R 4      # )Z
access_key)_get_auth_value_get_auth_matchgroup)r   r6   auth_valr'   
auth_match   &&   r
   r   ZCSMSerializer._get_access_key  s5    ''8,,X6--r   c                s    V P                  V4      '       g   R # V P                  V4      pV P                  V4      w  r4VR8w  d   R # VP                  R4      # )Nr`   Zsigning_region)r   r   r   r   )r   r6   r   signature_versionr   r   r
   rw   ZCSMSerializer._get_region  sU    //''8(,(<(<X(F%$ 011r   c                sl    V P                  \        VP                  R R4      4      V P                  4      # )z
User-Agentr   )r   r   r?   _MAX_USER_AGENT_LENGTHr   r6   r$   r
   rx   ZCSMSerializer._get_user_agent  s1    ~~?..|R@A''
 	
r   c                s    R V9   # ZAuthorizationr%   r   r$   r
   r   ZCSMSerializer._is_signed
  s    /11r   c                s&    \        VR ,          4      # r   )r   r   r$   r
   r   ZCSMSerializer._get_auth_value  s    oo>??r   c                s    V P                   P                  4        F#  w  r#VP                  V4      pV'       g   K   W$3u # 	  R# )N)NN)_AUTH_REGEXSr   match)r   r   r   Zregexr   r   r
   r   ZCSMSerializer._get_auth_match  sD    (,(9(9(?(?(A$KK)Eu(// )B r   c                s^    \        V4      V8  d   \        P                  R VV4       VRV # V# )z6Truncating following value to maximum length of %s: %sN)rd   r   r   )r   ZtextZ
max_lengthr	   r
   r   ZCSMSerializer._truncate  s7    t9z!LLH
 $$r   rm   N)r*   r+   r,   rZ   r<   rF   r7   r6   r=   r>   r@   rA   ))r   r   r   r   re   r   r   r   r   r   reZcompiler   ri   r   ra   rl   rg   ro   rp   rq   rs   rr   r}   r~   r   r   r   r   ry   rz   rh   r   rw   rx   r   r   r   r   r   r   r   r   r
   r_   r_   B  s     "%  ,Oi*& 	bjj/

 	bjj45L'#+K(
(&,I
*3H
28
=	
	
$.
2
2@ r   r_   c                   s0   a  ] tR tRt o RtR tR tRtV tR# )SocketPublisheri"  c                s.    Wn         W#3V n        W@n        R# )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   ZsocketZhostZportZ
serializers   &&&&&r
   r   ZSocketPublisher.__init__%  s    " %r   c                s   V P                   P                  V4      p\        V4      V P                  8  d-   \        P                  R\        V4      V P                  4       R# V P                  P                  W P                  4       R# )zPublishes 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   rl   rd   _MAX_MONITOR_EVENT_LENGTHr   r   r   Zsendtor   )r   rP   Zserialized_eventr   r
   r   ZSocketPublisher.publish:  sn      ++55e< 4#A#AALL<$%..	 ,mm<r   )r   r   r   Ni    )	r   r   r   r   r   r   r   r   r   r   r   r
   r   r   "  s      (&*= =r   r   )rj   Zloggingr   r#   Zbotocore.compatr    r   r   Zbotocore.retryhandlerr   rM   Z	getLoggerr   r   r   r    rS   r.   r[   r_   r   r%   r   r
   <module>r      s      	  B B G			8	$) )X]( ](@ 89# 9xC-* C-L] ]@(= (=r   