t_c@s ddlZddlZddlZddlZddlmZmZmZddlm Z ej e Z defdYZdefdYZdefd YZd efd YZd efd YZdefdYZdefdYZdS(iN(tensure_unicodet ensure_bytesturlparse(t EXCEPTION_MAPtMonitorcBs8eZdddddgZdZdZdZRS(sbefore-parameter-buildsrequest-createdsresponse-receiveds after-callsafter-call-errorcCs||_||_dS(sAbstraction 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(t_adaptert _publisher(tselftadaptert publisher((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt__init__"s cCs+x$|jD]}|j||jq WdS(s(Register an event emitter to the monitorN(t_EVENTS_TO_REGISTERt register_lasttcapture(Rt event_emittertevent_to_register((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pytregister-scKsey2|jj||}|r1|jj|nWn,tk r`}tjd||dtnXdS(sCaptures 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. s:Exception %s raised by client monitor in handling event %stexc_infoN(RtfeedRtpublisht ExceptiontloggertdebugtTrue(Rt event_nametpayloadt monitor_eventte((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR 2s(t__name__t __module__R R RR (((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs  tMonitorEventAdaptercBszeZejdZdZdZdZdZdZdZ dZ dZ d Z d Z d ZRS( cCs ||_dS(sAdapts event emitter events to produce monitor events :type time: callable :param time: A callable that produces the current time N(t_time(Rttime((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR CscCs|j||S(sFeed 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 (t _get_handler(Rtemitter_event_nametemitter_payload((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRKscCs*t|d|jddjddS(Nt_handle_t.it-t_(tgetattrtsplittreplace(RR((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR![scKs2td|jjd|jd|j|d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_handle_before_parameter_build`s  cKsK|j}|djd|j}|j|_|j|_||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_handle_request_createdgs    cKsq|jd}|j||_|dk rd|dd|_|dd|_|jd|_n ||_|S(NR8tResponseMetadatatHTTPStatusCodet HTTPHeaderstError( tpopt _get_latencytlatencytNonethttp_status_codetresponse_headerstgett parsed_errortwire_exception(Rtparsed_responseR5t exceptionR6t attempt_event((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_handle_response_receivedps  cKs*|djdt|d_|j|S(NR@tMaxAttemptsReachedR.(RJtFalsetretries_exceededt_complete_api_call(RR5tparsedR6((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_handle_after_call~scKs#|j||d_|j|S(NR.(t_is_retryable_exceptionRSRT(RR5RNR6((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_handle_after_call_errorscCst|ttdS(NtGENERAL_CONNECTION_ERROR(t isinstancettupletRETRYABLE_EXCEPTIONS(RRN((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRWscCs%|jd}|j||_|S(NR.(RDRERF(RR5t call_event((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRTscCs|j|jS(N(R3R-(Rtevent((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyREscCst|jdS(Ni(tintR(R((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR3s(RRR R RR!R7R?RPRVRXRWRTRER3(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRBs        tBaseMonitorEventcBs#eZdZdZdZRS(cCs||_||_||_dS(sBase 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 N(R+R,R-(RR+R,R-((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR s  cCsd|jj|jfS(Ns%s(%r)(t __class__Rt__dict__(R((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt__repr__scCs&t||jr"|j|jkStS(N(RZRaRbRR(Rtother((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt__eq__s(RRR RcRe(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR`s  R/cBs#eZddedZdZRS(cCs\tt|jd|d|d|||_||_|dkrOg|_n||_dS(sMonitor 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+R,R-N(tsuperR/R RFtattemptsRGRS(RR+R,R-RFRgRS((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR s    cCs5td|jd|jd|}|jj||S(sInstantiates APICallAttemptEvent associated to the APICallEvent :type timestamp: int :param timestamp: Epoch time in milliseconds to associate to the APICallAttemptEvent R+R,R-(tAPICallAttemptEventR+R,Rgtappend(RR-RO((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR9s    N(RRRGRRR R9(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR/s$RhcBs&eZddddddddZRS(c Cshtt|jd|d|d|||_||_||_||_||_| |_| |_ dS(sMonitor 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+R,R-N( RfRhR RFR<RHR;RIRKRL( RR+R,R-RFR<RHR;RIRKRL((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR s0      N(RRRGR (((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRhs t CSMSerializerc BsreZdZdZdZdZdZidd6dd6dd 6Ziej d d 6ej d d 6Z ddddddddddddg Z dZ dZ dZdZdZdZd Zd!Zd"Zd#Zd$Zd%Zd&Zd'Zd(Zd)Zd*Zd+Zd,Zd-Zd.Z d/Z!d0Z"d1Z#d2Z$RS(3iiiitXAmznRequestIdsx-amzn-requestidt XAmzRequestIdsx-amz-request-idtXAmzId2s x-amz-id-2sSAWS4-HMAC-SHA256 Credential=(?P\w+)/\d+/(?P[a-z0-9-]+)/tv4sAWS (?P\w+):ts3R+R,R-RgRFRSR<R;RHRIRKRLcCs|j|||_dS(sSerializes 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(t_validate_client_idt csm_client_id(RRq((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR Os cCs5t||jkr1td||jfndS(NsTThe value provided for csm_client_id: %s exceeds the maximum length of %s characters(tlent_MAX_CLIENT_ID_LENGTHt ValueError(RRq((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRpYscCs|j|}|j|}||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt serializeas   cCsidd6|jd6S(NitVersiontClientId(Rq(RR^((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR{uscKs||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_service{scKs||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_operation~scKs||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_timestampscKs1t||d<|r-|j||dndS(Nt AttemptCounti(Rrt_add_fields_from_last_attempt(RRgRR6((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_attemptsscCs|jrM|j|j}|dk r4||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs   cCs6|dkr||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_latencys   cKs|r dnd|d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_retries_exceededscKst|j|d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_urlscKs|j||d<|j|r8|j||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_request_headerss   cKs||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_http_status_codescKsAx:|jjD])\}}||kr||||/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt_serialize_response_headerss cKs^|dkrdnd}|j|d|j||d<|j|d|j||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs cKsb|dkrdnd}|j|jj|j||d<|jt||j||d/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs  cCs*t|trdSt|tr&dSdS(NRR(RZR/Rh(RR^((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR|scCs1|j|}|j|\}}|jdS(Nt access_key(t_get_auth_valuet_get_auth_matchtgroup(RR;tauth_valR't auth_match((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRscCsT|j|sdS|j|}|j|\}}|dkrGdS|jdS(NRntsigning_region(RRGRRR(RR;Rtsignature_versionR((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs cCs%|jt|jdd|jS(Ns User-AgentR(RRRJt_MAX_USER_AGENT_LENGTH(RR;((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRscCs d|kS(Nt Authorization((RR;((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRscCst|dS(NR(R(RR;((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRscCsCx<|jjD]+\}}|j|}|r||fSqWdS(N(NN(t _AUTH_REGEXSRtmatchRG(RRRtregexR((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs cCs1t||kr-tjd|||| S|S(Ns6Truncating following value to maximum length of %s: %s(RrRR(Rttextt max_length((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs  (%RRRsRRRRRtretcompileRR}R RpRR{RRRRRRRRRRRRRR|RRRRRRR(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRj+sf                        tSocketPublishercBs eZdZdZdZRS(iicCs%||_||f|_||_dS(s)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(t_sockett_addresst _serializer(Rtsocketthosttportt serializer((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyR s cCsa|jj|}t||jkrGtjdt||jdS|jj||jdS(sPublishes a specified monitor event :type event: BaseMonitorEvent :param event: The monitor event to be sent over the publisher's socket to the desired address. s`Serialized event of size %s exceeds the maximum length allowed: %s. Not sending event to socket.N( RRRrt_MAX_MONITOR_EVENT_LENGTHRRRtsendtoR(RR^tserialized_event((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRsi (RRRR R(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyRs (R~tloggingRR tbotocore.compatRRRtbotocore.retryhandlerRR\t getLoggerRRtobjectRRR`R/RhRjR(((s>/opt/awscli/lib/python2.7/site-packages/botocore/monitoring.pyt s    )Z6=