o
    rMfb                     @   sl   d Z ddlZzddlmZ W n ey   ddlZY nw ddlZddlZG dd deZ	G dd deZ
dS )z
Provides NotificationMessage and Event classes, with utility methods, for
implementations of the Mechanical Turk Notification API.
    N)sha1c                   @   s:   e Zd ZdZdZdZdZdZe	eZ
dd Zdd	 Zd
S )NotificationMessagezlhttp://mechanicalturk.amazonaws.com/AWSMechanicalTurk/2006-05-05/AWSMechanicalTurkRequesterNotification.wsdlz
2006-05-05&AWSMechanicalTurkRequesterNotificationNotifyz!Event\.(?P<n>\d+)\.(?P<param>\w+)c                 C   s   |d | _ |d | _|d | _|d tjksJ dtj g | _i }d|v r+|d }n0|D ]-}|| }|drZtj|	 }t
|d }t|d	 }||vrTi ||< ||| |< q-|D ]}| jt||  q]d
S )z
        Constructor; expects parameter d to be a dict of string parameters from a REST transport notification message
        	Signature	TimestampVersionmethodzMethod should be '%s'EventzEvent.nparamN)	signature	timestampversionr   OPERATION_NAMEevents
startswithEVENT_REsearch	groupdictintstrappendr
   )selfdevents_dictkvedr   r    r   Y/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/boto/mturk/notification.py__init__.   s*   




zNotificationMessage.__init__c                 C   sJ   t j}|t j7 }|| j7 }tj|td}|| t	|
 }| j|kS )a  
        Verifies the authenticity of a notification message.

        TODO: This is doing a form of authentication and
              this functionality should really be merged
              with the pluggable authentication mechanism
              at some point.
        )key	digestmod)r   SERVICE_NAMEr   r   hmacnewshaupdatebase64	b64encodedigestr   )r   
secret_keyverification_inputhsignature_calcr   r   r    verifyJ   s   	



zNotificationMessage.verifyN)__name__
__module____qualname__NOTIFICATION_WSDLNOTIFICATION_VERSIONr$   r   EVENT_PATTERNrecompiler   r!   r0   r   r   r   r    r   #   s    
r   c                   @   s   e Zd Zdd Zdd ZdS )r
   c                 C   sB   |d | _ |d | _|d | _|d | _d|v r|d | _d S d S )N	EventType	EventTime	HITTypeIdHITIdAssignmentId)
event_typeevent_time_strhit_typehit_idassignment_id)r   r   r   r   r    r!   \   s   



zEvent.__init__c                 C   s   d| j | jf S )Nz0<boto.mturk.notification.Event: %s for HIT # %s>)r>   rA   )r   r   r   r    __repr__f   s   zEvent.__repr__N)r1   r2   r3   r!   rC   r   r   r   r    r
   [   s    
r
   )__doc__r%   hashlibr   r'   ImportErrorr)   r7   objectr   r
   r   r   r   r    <module>   s   8