
    i%                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ dd	lmZ dd
lmZ ddlmZ dZ G d de	      Zy)zAmazon SQS Connection.    )annotationsN)
Serializer)	transform)AsyncAWSQueryConnection)
AWSRequest   )boto3)AsyncMessage)
AsyncQueue)AsyncSQSConnectionc                       e Zd ZdZd fd	Zd Zd ZddZ	 ddZddZ	d Z
dd	Zdd
Z	 	 	 ddZddZddZ	 ddZ	 ddZddZ	 ddZddZddZddZeZd ZddZ	 ddZddZ xZS ) r   zAsync SQS Connection.c                N    t         t        d      t        |   |f||d| y )Nzboto3 is not installed)region_namedebug)r	   ImportErrorsuper__init__)selfsqs_connectionr   regionkwargs	__class__s        /var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/kombu/asynchronous/aws/sqs/connection.pyr   zAsyncSQSConnection.__init__   s8    =677	
e	
 	
    c                    |j                         }|r||d<   d|i}|j                         dk(  rd|i}t        d||d|S )NActiondatagetparamsmethodurl )copylowerr   )r   	operationr   	queue_urlr!   param_payloads         r   _create_query_requestz(AsyncSQSConnection._create_query_request    sS    (F8  (<<>U"%v.MHYH-HHr   c                    |j                         }||d<   | j                  j                  j                  }|j	                  |      }| j                  j
                  j                  }i }|j                  d   }d| }	|	|d<   dj                  |j                  d   |j                        }
|
|d<   t        j                  |      |d}|j                  j                  d	t        j                        }t!        d||d
|S )NQueueUrljsonVersionzapplication/x-amz-json-zContent-Typez{}.{}targetPrefixzX-Amz-Target)r   headersr!   r    r#   )r$   r   metaservice_modeloperation_model	_endpointhostmetadataformatnamejsondumpshttpr   r   DEFAULT_METHODr   )r   r&   r   r'   r0   r1   r"   r.   json_versioncontent_typetargetr(   r!   s                r   _create_json_requestz'AsyncSQSConnection._create_json_request-   s   &z++00>>'77	B!!++00&//>0?". $$^4  
 #) JJv&

 !%%))(J4M4MN 

 
 	
r   c                   | j                   j                  }| j                   j                  j                  }|j                  }|dk(  r| j                  ||||      }	n(|dk(  r| j                  |||      }	nt        d| d      |	j                  j                         dk(  rdnd}
|j                  ||	|
       |	j                         }| j                  ||	      S )
ai  
        Overide make_request to support different protocols.

        botocore is soon going to change the default protocol of communicating
        with SQS backend from 'query' to 'json', so we need a special
        implementation of make_request for SQS. More information on this can
        be found in: https://github.com/celery/kombu/pull/1807.
        queryr7   zUnsupported protocol: .r   zpresign-urlstandard)signing_typecallback)r   _request_signerr/   r0   protocolr)   r>   	Exceptionr!   r%   signprepare_mexe)r   operation_namer   r'   verbrE   signerr0   rG   requestrC   prepared_requests               r   make_requestzAsyncSQSConnection.make_requestO   s     $$44++00>> ))w00	49G//	3G 4XJa@AA(/(<(<(>%(G} 	 	NG,G"??,zz*Xz>>r   c                T    d|i}|rt        |d      |d<   | j                  d||      S )N	QueueNamedDefaultVisibilityTimeoutCreateQueuerD   )r5   
get_object)r   
queue_namevisibility_timeoutrE   r   s        r   create_queuezAsyncSQSConnection.create_queuen   sC    z*17"C2F-. }f(0  2 	2r   c                @    | j                  dd |j                  |      S )NDeleteQueuerD   
get_statusid)r   queueforce_deletionrE   s       r   delete_queuezAsyncSQSConnection.delete_queuex   s%    }dEHH(0  2 	2r   c                D    | j                   j                  |      }|d   S )N)rS   r+   )r   get_queue_url)r   r`   ress      r   rd   z AsyncSQSConnection.get_queue_url|   s%    !!//%/@:r   c                D    | j                  dd|i|j                  |      S )NGetQueueAttributesAttributeNamerD   )rW   r_   )r   r`   	attributerE   s       r   get_queue_attributesz'AsyncSQSConnection.get_queue_attributes   s+     ?I">HHx  
 	
r   c                F    | j                  d||d|j                  |      S )NSetQueueAttribute)zAttribute.NamezAttribute.ValuerD   r]   )r   r`   ri   valuerE   s        r   set_queue_attributez&AsyncSQSConnection.set_queue_attribute   s,    (UCHHx  
 	
r   c                    d|i}|r||d<   |r:i }	t        |      D ]  \  }
}||	dt        |
dz         z   <    |j                  |	       |||d<   | j                  d|dt        fg|||      S )	NMaxNumberOfMessagesVisibilityTimeoutzAttributeName.r   WaitTimeSecondsReceiveMessageMessage)rE   parent)	enumeratestrupdateget_listr
   )r   r`   r'   number_messagesrY   
attributeswait_time_secondsrE   r   attrsidxattrs               r   receive_messagez"AsyncSQSConnection.receive_message   s    
 (9*<F&'E&z2 >	T9=&S1W56>MM% ((9F$%}}f	<'@&A  
 	
r   c                (    | j                  |||      S N)delete_message_from_handler   r`   receipt_handlerE   s       r   delete_messagez!AsyncSQSConnection.delete_message   s    ..>8
 	
r   c                    i }t        |      D ]<  \  }}d|dz    }|j                  | d|j                  | d|j                  i       > | j	                  d||j                  d|      S )NzDeleteMessageBatchRequestEntry.r   .Id.ReceiptHandleDeleteMessageBatchPOSTrM   rE   rv   rx   r_   r   rW   )r   r`   messagesrE   r   imprefixs           r   delete_message_batchz'AsyncSQSConnection.delete_message_batch   s    h' 	DAq6q1ug>FMM(#(.)1+;+; 	  &%(((  
 	
r   c                0    | j                  dd|i||      S )NDeleteMessageReceiptHandlerD   )r^   r   s       r   r   z-AsyncSQSConnection.delete_message_from_handle   s'    o~>H  
 	
r   c                j    d|i}|rt        |      |d<   | j                  d||j                  d|      S )NMessageBodyDelaySecondsSendMessager   r   )intrW   r_   )r   r`   message_contentdelay_secondsrE   r   s         r   send_messagezAsyncSQSConnection.send_message   sD    1%(%7F>"6588(  
 	
r   c           
         i }t        |      D ]6  \  }}d|dz    }|j                  | d|d   | d|d   | d|d   i       8 | j                  d||j                  d	|
      S )NzSendMessageBatchRequestEntry.r   r   r   z.MessageBodyz.DelaySeconds   SendMessageBatchr   r   )rv   rx   rW   r_   )r   r`   r   rE   r   r   msgr   s           r   send_message_batchz%AsyncSQSConnection.send_message_batch   s    ) 	FAs4QUG<FMM(#A(,'Q(-(#a& 	 (  
 	
r   c                F    | j                  d||d|j                  |      S )NChangeMessageVisibility)r   rq   rD   r]   )r   r`   r   rY   rE   s        r   change_message_visibilityz,AsyncSQSConnection.change_message_visibility   s/    %,"46HHx	  
 	
r   c           
         i }t        |      D ]J  \  }}d|dz    }|j                  | d|d   j                  | d|d   j                  | d|d   i       L | j	                  d||j                  d|	      S )
Nz)ChangeMessageVisibilityBatchRequestEntry.r   r   r   r   z.VisibilityTimeoutChangeMessageVisibilityBatchr   r   r   )r   r`   r   rE   r   r   tpres           r   change_message_visibility_batchz2AsyncSQSConnection.change_message_visibility_batch   s    h' 	DAq=a!eWECMM%sQqTWW%~&!(;(;%)*AaD 	 *FEHH(  
 	
r   c                L    i }|r||d<   | j                  d|dt        fg|      S )NQueueNamePrefix
ListQueuesr+   rD   )ry   r   )r   r   rE   r   s       r   get_all_queuesz!AsyncSQSConnection.get_all_queues   s=    (.F$%}}&J
#;"<  
 	
r   c                P    | j                  |t        | j                  ||            S r   )r   r   _on_queue_ready)r   rX   rE   s      r   	get_queuezAsyncSQSConnection.get_queue   s*    ""d**HjA
 	
r   c                .    t        fd|D        d       S )Nc              3  Z   K   | ]"  }|j                   j                        s| $ y wr   )r"   endswith).0qr6   s     r   	<genexpr>z5AsyncSQSConnection._on_queue_ready.<locals>.<genexpr>   s      71!%%.."6Q7s    ++)next)r   r6   queuess    ` r   r   z"AsyncSQSConnection._on_queue_ready   s    77
 	
r   c                R    | j                  dd|j                  idt        fg|      S )NListDeadLetterSourceQueuesr+   rD   )ry   r"   r   )r   r`   rE   s      r   get_dead_letter_source_queuesz0AsyncSQSConnection.get_dead_letter_source_queues   s4    }}(:uyy*A*%&  
 	
r   c                H    | j                  d|||d|j                  |      S )NAddPermission)LabelAWSAccountId
ActionNamerD   r]   )r   r`   labelaws_account_idaction_namerE   s         r   add_permissionz!AsyncSQSConnection.add_permission  s4    +&( HHx  
 	
r   c                D    | j                  dd|i|j                  |      S )NRemovePermissionr   rD   r]   )r   r`   r   rE   s       r   remove_permissionz$AsyncSQSConnection.remove_permission  s*    % 0%((X  
 	
r   )r   Nr   )NN)FN)AllN)r   N)ApproximateReceiveCountNN) N)__name__
__module____qualname____doc__r   r)   r>   rQ   rZ   rb   rd   rj   rn   r   r   r   r   r   r   r   r   r   r   lookupr   r   r   r   __classcell__)r   s   @r   r   r      s    
I 
D?@ 8<22

 GKCG
(


 -1
 37

 @D



 F


 !%

r   r   )r   
__future__r   r7   botocore.serializer   viner   !kombu.asynchronous.aws.connectionr   kombu.asynchronous.aws.extr   extr	   messager
   r`   r   __all__r   r#   r   r   <module>r      s7     "  )  E 1  ! 
!
0 
r   