+
    irP                         ^ 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# )    N)ensure_bytesensure_unicodeurlparse)EXCEPTION_MAPc                   :   a  ] tR t^t o . ROtR tR tR tRtV t	R# )Monitorc                    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)selfadapter	publishers   &&&5/usr/lib/python3/dist-packages/botocore/monitoring.py__init__Monitor.__init__!   s      #    c                b    V P                    F  pVP                  W P                  4       K   	  R# )z(Register an event emitter to the monitorN)_EVENTS_TO_REGISTERregister_lastcapture)r   event_emitterevent_to_registers   && r   registerMonitor.register,   s&    !%!9!9''(9<<H ":r   c                     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)exc_infoN)r   feedr   publish	Exceptionloggerdebug)r   
event_namepayloadmonitor_eventes   &&,  r   r   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__s   @r   r   r      s"     	$I
 r   r   c                      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                    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   times   &&r   r   MonitorEventAdapter.__init__E   s	     
r   c                0    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   emitter_event_nameemitter_payloads   &&&r   r   MonitorEventAdapter.feedM   s       !34GGGr   c                t    \        V R VP                  R4      ^ ,          P                  RR4      ,           4      # )_handle_.-_)getattrsplitreplace)r   r#   s   &&r   r9    MonitorEventAdapter._get_handler]   s6    *z//4Q7??SII
 	
r   c                    \        VP                  P                  VP                  V P	                  4       R 7      VR&   R# )service	operation	timestampcurrent_api_call_eventN)APICallEventservice_model
service_id	wire_name_get_current_time)r   modelcontextkwargss   &&&,r   _handle_before_parameter_build2MonitorEventAdapter._handle_before_parameter_buildb   s4    ,8''22oo,,.-
()r   c                    VP                   pVR ,          P                  V P                  4       R7      pVP                  Vn        VP
                  Vn        WCR&   R# )rK   )rJ   current_api_call_attempt_eventN)rR   new_api_call_attemptrP   headersrequest_headersurl)r   requestrS   rR   new_attempt_events   &&,  r   _handle_request_created+MonitorEventAdapter._handle_request_createdi   sW    //#$


)?)?)A

B 	 -4OO) '4E01r   c                    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# )rW   ResponseMetadataHTTPStatusCodeHTTPHeadersError)pop_get_latencylatencyhttp_status_coderesponse_headersgetparsed_errorwire_exception)r   parsed_responserR   	exceptionrS   attempt_events   &&&&, r   _handle_response_received-MonitorEventAdapter._handle_response_receivedr   s      $DE $ 1 1- @&-<".. M* .="..M* *9)<)<W)EM&  ,5(r   c                n    VR ,          P                  RR4      VR,          n        V P                  V4      # )ra   MaxAttemptsReachedFrK   )rj   retries_exceeded_complete_api_call)r   rR   parsedrS   s   &&&,r   _handle_after_call&MonitorEventAdapter._handle_after_call   s;    =C>

#"E
* 	(): &&w//r   c                ^    V P                  V4      VR ,          n        V P                  V4      # rK   )_is_retryable_exceptionrt   ru   )r   rR   rn   rS   s   &&&,r   _handle_after_call_error,MonitorEventAdapter._handle_after_call_error   s3     "99)D 	$	

&&w//r   c                B    \        V\        \        R ,          4      4      # )GENERAL_CONNECTION_ERROR)
isinstancetupleRETRYABLE_EXCEPTIONS)r   rn   s   &&r   r{   +MonitorEventAdapter._is_retryable_exception   s     u12LMN
 	
r   c                T    VP                  R 4      pV P                  V4      Vn        V# rz   )re   rf   rg   )r   rR   
call_events   && r   ru   &MonitorEventAdapter._complete_api_call   s*    [[!9:
!..z:
r   c                D    V P                  4       VP                  ,
          # N)rP   rJ   r   events   &&r   rf    MonitorEventAdapter._get_latency   s    %%'%//99r   c                B    \        V P                  4       R ,          4      # )i  )intr4   r   s   &r   rP   %MonitorEventAdapter._get_current_time   s    4::<$&''r   r3   N)r(   r)   r*   r+   r5   r   r   r9   rT   r^   rp   rw   r|   r{   ru   rf   rP   r,   r-   r.   s   @r   r1   r1   D   sO      II H 

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


:( (r   r1   c                   2   a  ] tR t^t o R tR tR tRtV tR# )BaseMonitorEventc                *    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
NrG   )r   rH   rI   rJ   s   &&&&r   r   BaseMonitorEvent.__init__   s     ""r   c                P    V P                   P                   R V P                  : R2# )())	__class__r(   __dict__r   s   &r   __repr__BaseMonitorEvent.__repr__   s%    ..))*!DMM+<A>>r   c                n    \        WP                  4      '       d   V P                  VP                  8H  # R # )F)r   r   r   )r   others   &&r   __eq__BaseMonitorEvent.__eq__   s'    e^^,,==ENN22r   )rI   rH   rJ   N)	r(   r)   r*   r+   r   r   r   r,   r-   r.   s   @r   r   r      s     #$? r   r   c                   <   a a ] tR t^t oRV 3R lltR tRtVtV ;t# )rL   c                d   < \         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
rG   N)superr   rg   attemptsrt   )r   rH   rI   rJ   rg   r   rt   r   s   &&&&&&&r   r   APICallEvent.__init__   s<    H 	I 	 	
  DM 0r   c                    \        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
rG   )APICallAttemptEventrH   rI   r   append)r   rJ   ro   s   && r   rX   !APICallEvent.new_api_call_attempt   s7     ,LLDNNi
 	]+r   )r   rg   rt   )NNF)	r(   r)   r*   r+   r   rX   r,   r-   __classcell__r   r/   s   @@r   rL   rL      s     +1Z r   rL   c                   6   a a ] tR t^t oRV 3R lltRtVtV ;t# )r   c                ~   < \         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)
rG   N)	r   r   rg   r[   rh   rZ   ri   rk   rl   )r   rH   rI   rJ   rg   r[   rh   rZ   ri   rk   rl   r   s   &&&&&&&&&&&r   r   APICallAttemptEvent.__init__   sG    r 	I 	 	
  0. 0(,r   )rh   rg   rk   rZ   ri   r[   rl   )NNNNNNN)r(   r)   r*   r+   r   r,   r-   r   r   s   @@r   r   r      s     B- B-r   r   c                   .  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   zx-amzn-requestidXAmznRequestIdzx-amz-request-idXAmzRequestIdz
x-amz-id-2XAmzId2v4zSAWS4-HMAC-SHA256 Credential=(?P<access_key>\w+)/\d+/(?P<signing_region>[a-z0-9-]+)/s3zAWS (?P<access_key>\w+):c                4    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   r   s   &&r   r   CSMSerializer.__init__d  s     	  /*r   c                r    \        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_LENGTH
ValueErrorr   s   &&r   r   !CSMSerializer._validate_client_idn  sH    } : ::8 H))-)C)C(DKQ  ;r   c                   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
TypeN_serialize_)
event_type)
separators),:)_get_base_event_dict_get_event_type_SERIALIZEABLE_EVENT_PROPERTIESrB   r   jsondumps)r   r   
event_dictr   attrvalues   &&    r   	serializeCSMSerializer.serializeu  s     ..u5
))%0
'688DE.E md23* 9 DJJzjIJJr   c                "    R ^RV P                   /# )VersionClientIdr   r   s   &&r   r   "CSMSerializer._get_base_event_dict  s    q**
 	
r   c                    WR &   R# )ServiceNr8   )r   rH   r   rS   s   &&&,r   _serialize_service CSMSerializer._serialize_service  s
     '9r   c                    WR &   R# )ApiNr8   )r   rI   r   rS   s   &&&,r   _serialize_operation"CSMSerializer._serialize_operation  s
    %5r   c                    WR &   R# )	TimestampNr8   )r   rJ   r   rS   s   &&&,r   _serialize_timestamp"CSMSerializer._serialize_timestamp  s
    "+;r   c                f    \        V4      VR &   V'       d   V P                  W!R,          4       R# R# )AttemptCountN)r   _add_fields_from_last_attempt)r   r   r   rS   s   &&&,r   _serialize_attempts!CSMSerializer._serialize_attempts  s*    %(]
>"..zB<H r   c                   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	UserAgentFinalHttpStatusCodeApiCall)rZ   _get_region_get_user_agentrh   rk   _serialize_parsed_errorrl   _serialize_wire_exception)r   r   last_attemptregions   &&& r   r   +CSMSerializer._add_fields_from_last_attempt  s    ''' %%l&B&BCF!'-8$&*&:&:,,'J{# ((40<0M0MJ,-$$0(()):y &&2**++Z 3r   c                :    VR 8X  d   WR&   R# VR8X  d   WR&   R# R# )r   LatencyApiCallAttemptAttemptLatencyNr8   )r   rg   r   r   s   &&&&r   _serialize_latency CSMSerializer._serialize_latency  s)    "$+y!+++2'( ,r   c                $    V'       d   ^M^ VR&   R# )   MaxRetriesExceededNr8   )r   rt   r   rS   s   &&&,r   _serialize_retries_exceeded)CSMSerializer._serialize_retries_exceeded  s     1A1a
'(r   c                6    \        V4      P                  VR &   R# )FqdnN)r   netloc)r   r[   r   rS   s   &&&,r   _serialize_urlCSMSerializer._serialize_url  s    %c]11
6r   c                    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# )r   	AccessKeyNr   zX-Amz-Security-TokenSessionToken)r   
_is_signed_get_access_keyr   )r   rZ   r   rS   r   s   &&&, r   _serialize_request_headers(CSMSerializer._serialize_request_headers  sz     #'"6"6"G
;???++&*&:&:?&KJ{#!!/2#)x !_4)8&*J~& 5r   c                    WR &   R# )HttpStatusCodeNr8   )r   rh   r   rS   s   &&&,r   _serialize_http_status_code)CSMSerializer._serialize_http_status_code  s     (8#$r   c                p    V P                   P                  4        F  w  rEWA9   g   K  W,          W%&   K  	  R # r   )"_RESPONSE_HEADERS_TO_EVENT_ENTRIESitems)r   ri   r   rS   headerentrys   &&&,  r   _serialize_response_headers)CSMSerializer._serialize_response_headers  s1     "DDJJLMF)$4$<
! Mr   c                    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# )r   Final CodeAwsExceptionMessageAwsExceptionMessageN)	_truncate_MAX_ERROR_CODE_LENGTH_MAX_MESSAGE_LENGTH)r   rk   r   r   rS   field_prefixs   &&&&, r   r   %CSMSerializer._serialize_parsed_error  sb     #-	"9wr48NN $"="=5

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

"778r   c                    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# )r   r  r  SdkExceptionSdkExceptionMessageN)r  r   r(   _MAX_EXCEPTION_CLASS_LENGTHstrr  )r   rl   r   r   rS   r  s   &&&&, r   r   'CSMSerializer._serialize_wire_exception  si     #-	"9wr48NN$$--t/O/O5

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

"778r   c                f    \        V\        4      '       d   R # \        V\        4      '       d   R# R# )r   r   N)r   rL   r   r   s   &&r   r   CSMSerializer._get_event_type  s(    e\**233# 4r   c                l    V P                  V4      pV P                  V4      w  r4VP                  R 4      # )
access_key)_get_auth_value_get_auth_matchgroup)r   rZ   auth_valrA   
auth_matchs   &&   r   r  CSMSerializer._get_access_key  s5    ''8,,X6--r   c                    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   signing_region)r  r+  r,  r-  )r   rZ   r.  signature_versionr/  s   &&   r   r   CSMSerializer._get_region  sU    //''8(,(<(<X(F%$ 011r   c                l    V P                  \        VP                  R R4      4      V P                  4      # )z
User-Agentr  )r  r   rj   _MAX_USER_AGENT_LENGTHr   rZ   s   &&r   r   CSMSerializer._get_user_agent  s1    ~~?..|R@A''
 	
r   c                    R V9   # Authorizationr8   r7  s   &&r   r  CSMSerializer._is_signed
  s    /11r   c                &    \        VR ,          4      # r:  )r   r7  s   &&r   r+  CSMSerializer._get_auth_value  s    oo>??r   c                    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.  r3  regexrA  s   &&   r   r,  CSMSerializer._get_auth_match  sD    (,(9(9(?(?(A$KK)Eu(// )B r   c                ^    \        V4      V8  d   \        P                  R VV4       VRV # V# )z6Truncating following value to maximum length of %s: %sN)r   r!   r"   )r   text
max_lengths   &&&r   r  CSMSerializer._truncate  s7    t9z!LLH
 $$r   r   N)rH   rI   rJ   r   rg   rt   r[   rZ   rh   ri   rk   rl   ))r(   r)   r*   r+   r   r$  r  r6  r  r  recompiler@  r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r   r   r  r   r   r  r+  r,  r  r,   r-   r.   s   @r   r   r   B  s     "%  ,Oi*& 	bjj/

 	bjj45L'#+K(
(&,I
*3H
28
=	
	
$.
2
2@ r   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )SocketPublisheri"  c                .    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   sockethostport
serializers   &&&&&r   r   SocketPublisher.__init__%  s    " %r   c                   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)	rO  r   r   _MAX_MONITOR_EVENT_LENGTHr!   r"   rM  sendtorN  )r   r   serialized_events   && r   r   SocketPublisher.publish:  sn      ++55e< 4#A#AALL<$%..	 ,mm<r   )rN  rO  rM  Ni    )	r(   r)   r*   r+   rV  r   r   r,   r-   r.   s   @r   rK  rK  "  s      (&*= =r   rK  )r   loggingrH  r5   botocore.compatr   r   r   botocore.retryhandlerr   r   	getLoggerr(   r!   r   r1   r   rL   r   r   rK  r8   r   r   <module>r^     s      	  B B G			8	$) )X]( ](@ 89# 9xC-* C-L] ]@(= (=r   