
    IhC,                        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 Zd 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                r    t         t        d      t        |   |f||d| ||| _        y dg| _        y )Nzboto3 is not installed)region_namedebugApproximateReceiveCount)r	   ImportErrorsuper__init__fetch_message_attributes)selfsqs_connectionr   regionr   kwargs	__class__s         ^/var/www/html/planif/env/lib/python3.12/site-packages/kombu/asynchronous/aws/sqs/connection.pyr   zAsyncSQSConnection.__init__   sZ    =677	
e	
 	
 )A(L$ 	%+, 	%    c                    |j                         }|r||d<   d|i}i }|j                         dk(  rd|i}|j                         dk(  rd|d<   t        d	|||d|S )
NActiondatagetparamspostz0application/x-www-form-urlencoded; charset=utf-8Content-Type)methodurlheaders )copylowerr   )r   	operationr!   	queue_urlr$   param_payloadr&   s          r   _create_query_requestz(AsyncSQSConnection._create_query_request$   sr    (F8  (<<>U"%v.M<<>V#&XGN#YYY=YYr   c                   |j                         }||d<   | j                  j                  j                  }|j	                  |      }| j                  j
                  j                  }i }|j                  d   }d| }	|	|d<   dj                  |j                  d   |j                        }
|
|d<   t        j                  |      j                         |d}|j                  j                  d	t        j                         }t#        d||d
|S )NQueueUrljsonVersionzapplication/x-amz-json-r#   z{}.{}targetPrefixzX-Amz-Target)r   r&   r$   )r$   r%   r'   )r(   r   metaservice_modeloperation_model	_endpointhostmetadataformatnamejsondumpsencodehttpr    r   DEFAULT_METHODr   )r   r*   r!   r+   r3   r4   r%   r&   json_versioncontent_typetargetr,   r$   s                r   _create_json_requestz'AsyncSQSConnection._create_json_request5   s   &z++00>>'77	B!!++00&//>0?". $$^4  
 #) JJv&--/

 !%%))(J4M4MN 

 
 	
r   c                   | j                   j                  }| j                   j                  j                  }|j                  }	i |xs i |j                  |	i       }
|	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 )
a  Override make_request to support different protocols.

        botocore has changed 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.

        protocol_params: Optional[dict[str, dict]] of per-protocol additional parameters.
            Supported for the SQS query to json protocol transition.
        queryr:   zUnsupported protocol: .r    zpresign-urlstandard)signing_typecallback)r   _request_signerr2   r3   protocolr    r-   rB   	Exceptionr$   r)   signprepare_mexe)r   operation_namer!   r+   verbrI   protocol_paramssignerr3   rK   
all_paramsrequestrG   prepared_requests                 r   make_requestzAsyncSQSConnection.make_requestW   s    $$44++00>> ))L2L/*=*=h*KL
w00
It=G//
I7G 4XJa@AA(/(<(<(>%(G} 	 	NG,G"??,zz*Xz>>r   c                T    d|i}|rt        |d      |d<   | j                  d||      S )N	QueueNamedDefaultVisibilityTimeoutCreateQueuerH   )r8   
get_object)r   
queue_namevisibility_timeoutrI   r!   s        r   create_queuezAsyncSQSConnection.create_queuey   sC    z*17"C2F-. }f(0  2 	2r   c                @    | j                  dd |j                  |      S )NDeleteQueuerH   
get_statusid)r   queueforce_deletionrI   s       r   delete_queuezAsyncSQSConnection.delete_queue   s%    }dEHH(0  2 	2r   c                D    | j                   j                  |      }|d   S )N)rY   r/   )r   get_queue_url)r   rf   ress      r   rj   z AsyncSQSConnection.get_queue_url   s%    !!//%/@:r   c                D    | j                  dd|i|j                  |      S )NGetQueueAttributesAttributeNamerH   )r]   re   )r   rf   	attributerI   s       r   get_queue_attributesz'AsyncSQSConnection.get_queue_attributes   s+     ?I">HHx  
 	
r   c           
     V    | j                  di |j                  |d||ii||dd      S )NSetQueueAttribute
Attributes)zAttribute.NamezAttribute.Valuer:   rD   )rI   rR   rc   )r   rf   ro   valuerI   s        r   set_queue_attributez&AsyncSQSConnection.set_queue_attribute   sA    HHx%	5'9:,5%P	  
 	
r   c           	         d|i}i i d}	||n| j                   }
|r||d<   |
rG|	d   j                  dt        |
      i       |	d   j                  t        dt        |
      i             |||d<   | j	                  d	|d
t
        fg||||	      S )NMaxNumberOfMessages)rD   r:   VisibilityTimeoutr:   AttributeNamesrD   rn   WaitTimeSecondsReceiveMessageMessage)rI   parentrR   )r   updatelist_query_object_encodeget_listr
   )r   rf   r+   number_messagesr_   
attributeswait_time_secondsrI   r!   proto_paramsattrss              r   receive_messagez"AsyncSQSConnection.receive_message   s    
 (9!#R0(4
$:W:W*<F&' '')94;(GH!(()=PTUZP[>\)]^((9F$%}}f	<'@&A(  
 	
r   c                (    | j                  |||      S N)delete_message_from_handler   rf   receipt_handlerI   s       r   delete_messagez!AsyncSQSConnection.delete_message   s    ..>8
 	
r   c           
        d|D cg c]  }|j                   |j                  d c}it        d|D cg c]  }|j                   |j                  d c}i      d}| j                  di |j                   d||      S c c}w c c}w )NEntries)IdReceiptHandleDeleteMessageBatchRequestEntryrt   DeleteMessageBatchPOSTrQ   rI   rR   re   r   r   r]   )r   rf   messagesrI   mp_paramss         r   delete_message_batchz'AsyncSQSConnection.delete_message_batch   s     U]^PQ144!:J:JK^ *0%3 44!2B2BC3+ 	

  "ehh(H  
 	
 _3s
    A> Bc                0    | j                  dd|i||      S )NDeleteMessager   rH   )rd   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   rQ   rI   )intr]   re   )r   rf   message_contentdelay_secondsrI   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   z.Idr   z.MessageBodyz.DelaySeconds   SendMessageBatchr   r   )	enumerater   r]   re   )r   rf   r   rI   r!   imsgprefixs           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   ry   rH   rc   )r   rf   r   r_   rI   s        r   change_message_visibilityz,AsyncSQSConnection.change_message_visibility   s/    %,"46HHx	  
 	
r   c                    |D cg c]%  }|d   j                   |d   j                  |d   d' }}d|it        d|i      d}| j                  di |j                   d||	      S c c}w )
Nr   r   )r   r   ry   r   (ChangeMessageVisibilityBatchRequestEntryrt   ChangeMessageVisibilityBatchr   r   r   )r   rf   r   rI   tentriesr   s          r   change_message_visibility_batchz2AsyncSQSConnection.change_message_visibility_batch   s     
 Q477QqT-@-@WXYZW[\
 
 ()+UW^*_`

 *B($  
 	

s   *A$c                L    i }|r||d<   | j                  d|dt        fg|      S )NQueueNamePrefix
ListQueuesr/   rH   )r   r   )r   r   rI   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   r^   rI   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qr9   s     r   	<genexpr>z5AsyncSQSConnection._on_queue_ready.<locals>.<genexpr>  s      71!%%.."6Q7s    ++)next)r   r9   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/   rH   )r   r%   r   )r   rf   rI   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
ActionNamerH   rc   )r   rf   labelaws_account_idaction_namerI   s         r   add_permissionz!AsyncSQSConnection.add_permission   s4    +&( HHx  
 	
r   c                D    | j                  dd|i|j                  |      S )NRemovePermissionr   rH   rc   )r   rf   r   rI   s       r   remove_permissionz$AsyncSQSConnection.remove_permission*  s*    % 0%((X  
 	
r   )r   NN)NN)FN)AllNr   )r   NNNN) N)__name__
__module____qualname____doc__r   r-   rB   rW   r`   rh   rj   rp   rv   r   r   r   r   r   r   r   r   r   r   lookupr   r   r   r   __classcell__)r   s   @r   r   r      s    
Z" 
D ?F 8<22
	
 GK+/
.

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


 !%

r   r   c                t    i }t        |d|        |j                         D ci c]  \  }}||
 c}}S c c}}w )Nr   )_query_object_encode_partitems)r   r!   kvs       r   r   r   0  s5    Ffb%0#\\^,TQAqD,,,s   4c                "   |r| dn|}t        |t        t        f      r(t        |      D ]  \  }}t	        | | |dz    |        y t        |t
              r*|j                         D ]  \  }}t	        | | | |        y t        |      | |<   y )NrE   r   )
isinstancer   tupler   r   dictr   str)r!   r   partdottedr   itemkeyru   s           r   r   r   6  s    #xq\F$u&  	HGAt%fQ.@$G	H	D$	**, 	GJC%f.>F	G Tvr   )r   
__future__r   r:   botocore.serializer   viner   !kombu.asynchronous.aws.connectionr   kombu.asynchronous.aws.extr   extr	   messager
   rf   r   __all__r   r   r   r'   r   r   <module>r      sB     "  )  E 1  ! 
!Y
0 Y
x-
#r   