
    ^f%                        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dS )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.r   Nc                n    t           t          d           t                      j        |f||d| d S )Nzboto3 is not installed)region_namedebug)r	   ImportErrorsuper__init__)selfsqs_connectionr   regionkwargs	__class__s        W/var/www/html/env/lib/python3.11/site-packages/kombu/asynchronous/aws/sqs/connection.pyr   zAsyncSQSConnection.__init__   sX    =6777	
e	
 	
 	
 	
 	
 	
 	
    c                    |                                 }|r||d<   d|i}|                                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    se     	)(F8  (<<>>U""%v.MHYHH-HHHr   c                   |                                 }||d<   | j        j        j        }|                    |          }| j        j        j        }i }|j        d         }d| }	|	|d<   d                    |j        d         |j	                  }
|
|d<   t          j        |          |d}|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>'77	BB!+0&/>???". $^4 
 
 #) Jv&&
 

 !%))(J4MNN 

 
 
 
 	
r   c                   | j         j        }| j         j        j        }|j        }|dk    r|                     ||||          }	n1|dk    r|                     |||          }	nt          d| d          |	j        	                                dk    rdnd}
|
                    ||	|
           |	                                }|                     ||	          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+0> )w00	49 9GG//	3 3GG @X@@@AAA(/(<(<(>(>%(G(G}} 	 	NG,GGG"??,,zz*Xz>>>r   c                d    d|i}|rt          |d          |d<   |                     d||          S )N	QueueNamedDefaultVisibilityTimeoutCreateQueuerD   )r5   
get_object)r   
queue_namevisibility_timeoutrE   r   s        r   create_queuezAsyncSQSConnection.create_queuen   sR    z* 	17"C2 2F-. }f(0  2 2 	2r   Fc                >    |                      dd |j        |          S )NDeleteQueuerD   
get_statusid)r   queueforce_deletionrE   s       r   delete_queuezAsyncSQSConnection.delete_queuex   s(    }dEH(0  2 2 	2r   c                H    | j                             |          }|d         S )N)rS   r+   )r   get_queue_url)r   r`   ress      r   rd   z AsyncSQSConnection.get_queue_url|   s%    !//%/@@:r   Allc                B    |                      dd|i|j        |          S )NGetQueueAttributesAttributeNamerD   )rW   r_   )r   r`   	attributerE   s       r   get_queue_attributesz'AsyncSQSConnection.get_queue_attributes   s.     ?I">Hx  
 
 	
r   c                D    |                      d||d|j        |          S )NSetQueueAttribute)zAttribute.NamezAttribute.ValuerD   r]   )r   r`   rj   valuerE   s        r   set_queue_attributez&AsyncSQSConnection.set_queue_attribute   s2    (UCCHx  
 
 	
r   r   ApproximateReceiveCountc                    d|i}|r||d<   |rDi }	t          |          D ]\  }
}||	dt          |
dz             z   <   |                    |	           |||d<   |                     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2 > >	T9=&S1W566MM%   ((9F$%}}f	<'@&A  
 
 	
r   c                0    |                      |||          S N)delete_message_from_handler   r`   receipt_handlerE   s       r   delete_messagez!AsyncSQSConnection.delete_message   s!    ..>8
 
 	
r   c                    i }t          |          D ]6\  }}d|dz    }|                    | d|j        | d|j        i           7|                     d||j        d|          S )NzDeleteMessageBatchRequestEntry.r   .Id.ReceiptHandleDeleteMessageBatchPOSTrM   rE   ry   r{   r_   r   rW   )r   r`   messagesrE   r   imprefixs           r   delete_message_batchz'AsyncSQSConnection.delete_message_batch   s    h'' 	 	DAq>q1u>>FMM)))1+;      &%((  
 
 	
r   c                8    |                      dd|i||          S )NDeleteMessageReceiptHandlerD   )r^   r   s       r   r   z-AsyncSQSConnection.delete_message_from_handle   s,    o~>H  
 
 	
r   c                p    d|i}|rt          |          |d<   |                     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   sO    1 	8%(%7%7F>"658(  
 
 	
r   c           
         i }t          |          D ]C\  }}d|dz    }|                    | d|d         | d|d         | d|d         i           D|                     d||j        d	|
          S )NzSendMessageBatchRequestEntry.r   r   r   z.MessageBodyz.DelaySeconds   SendMessageBatchr   r   )ry   r{   rW   r_   )r   r`   r   rE   r   r   msgr   s           r   send_message_batchz%AsyncSQSConnection.send_message_batch   s    )) 	 	FAs<QU<<FMMA'''Q(((#a&    
 (  
 
 	
r   c                D    |                      d||d|j        |          S )NChangeMessageVisibility)r   rt   rD   r]   )r   r`   r   rY   rE   s        r   change_message_visibilityz,AsyncSQSConnection.change_message_visibility   s7    %,"46 6Hx	  
 
 	
r   c           
         i }t          |          D ]M\  }}d|dz    }|                    | d|d         j        | d|d         j        | d|d         i           N|                     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Ea!eEECMMQqTW&&&!(;***AaD    
 *FEH(  
 
 	
r    c                V    i }|r||d<   |                      d|dt          fg|          S )NQueueNamePrefix
ListQueuesr+   rD   )r|   r   )r   r   rE   r   s       r   get_all_queuesz!AsyncSQSConnection.get_all_queues   sG     	/(.F$%}}&J
#;"<  
 
 	
r   c                V    |                      |t          | j        ||                    S r   )r   r   _on_queue_ready)r   rX   rE   s      r   	get_queuezAsyncSQSConnection.get_queue   s/    ""d*HjAA
 
 	
r   c                <    t          fd|D             d           S )Nc              3  P   K   | ] }|j                                       |V  !d S r   )r"   endswith).0qr6   s     r   	<genexpr>z5AsyncSQSConnection._on_queue_ready.<locals>.<genexpr>   s6      771!%.."6"67Q777777r   )next)r   r6   queuess    ` r   r   z"AsyncSQSConnection._on_queue_ready   s.    7777777
 
 	
r   c                R    |                      dd|j        idt          fg|          S )NListDeadLetterSourceQueuesr+   rD   )r|   r"   r   )r   r`   rE   s      r   get_dead_letter_source_queuesz0AsyncSQSConnection.get_dead_letter_source_queues   s7    }}(:uy*A*%&  
 
 	
r   c                F    |                      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  s<    +&( ( Hx  
 
 	
r   c                B    |                      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)rf   N)r   Nrp   NN)r   N)__name__
__module____qualname____doc__r   r)   r>   rQ   rZ   rb   rd   rk   ro   r   r   r   r   r   r   r   r   r   r   lookupr   r   r   r   __classcell__)r   s   @r   r   r      s       
 
 
 
 
 
I I I 
  
  
D? ? ? ?@ 8<2 2 2 22 2 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      s      " " " " " "  ) ) ) ) ) )       E E E E E E 1 1 1 1 1 1       ! ! ! ! ! !      
!
 
 
 
 
0 
 
 
 
 
r   