
    >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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                    t         t        d      t        |   |f||d| |r|ndg| _        t        |t              r	|g| _        y |xs g | _        y )Nzboto3 is not installed)region_namedebugApproximateReceiveCount)r	   ImportErrorsuper__init__message_system_attribute_names
isinstancestrmessage_attribute_names)selfsqs_connectionr   regionr   r   kwargs	__class__s          /var/www/html/wine-match-dev/backend/winematch-backend/venv/lib/python3.12/site-packages/kombu/asynchronous/aws/sqs/connection.pyr   zAsyncSQSConnection.__init__   s|     =677	
e	
 	
 /M*SlRm 	+ *44KS)Q$% 	$)/R 	$    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.   r6   r7   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                  }	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_signerr5   r6   protocolr#   r0   rE   	Exceptionr'   r,   signprepare_mexe)r   operation_namer$   r.   verbrL   protocol_paramssignerr6   rN   
all_paramsrequestrJ   prepared_requests                 r   make_requestzAsyncSQSConnection.make_requestb   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CreateQueuerK   )r;   
get_object)r   
queue_namevisibility_timeoutrL   r$   s        r   create_queuezAsyncSQSConnection.create_queue   sC    z*17"C2F-. }f(0  2 	2r   c                @    | j                  dd |j                  |      S )NDeleteQueuerK   
get_statusid)r   queueforce_deletionrL   s       r   delete_queuezAsyncSQSConnection.delete_queue   s%    }dEHH(0  2 	2r   c                D    | j                   j                  |      }|d   S )N)r\   r2   )r   get_queue_url)r   ri   ress      r   rm   z AsyncSQSConnection.get_queue_url   s%    !!//%/@:r   c                D    | j                  dd|i|j                  |      S )NGetQueueAttributesAttributeNamerK   )r`   rh   )r   ri   	attributerL   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=   rG   )rL   rU   rf   )r   ri   rr   valuerL   s        r   set_queue_attributez&AsyncSQSConnection.set_queue_attribute   sA    HHx%	5'9:,5%P	  
 	
r   c           	        d|i}i i d}	||n| j                   }
| j                  r| j                  nd }|r||d<   |
rG|	d   j                  dt        |
      i       |	d   j                  t	        dt        |
      i             |rG|	d   j                  dt        |      i       |	d   j                  t	        dt        |      i             |||d	<   | j                  d
|dt        fg||||	      S )NMaxNumberOfMessages)rG   r=   VisibilityTimeoutr=   MessageSystemAttributeNamesrG   MessageSystemAttributeNameMessageAttributeNamesWaitTimeSecondsReceiveMessageMessage)rL   parentrU   )r   r   updatelist_query_object_encodeget_listr
   )r   ri   r.   number_messagesrb   
attributeswait_time_secondsrL   r$   proto_paramsattrsmsg_attr_namess               r   receive_messagez"AsyncSQSConnection.receive_message   s   
 (9!#R0(4
$:]:]9=9U9U55[_*<F&' '')FU(TU!(()=?[]abg]h>i)jk '')@$~BV(WX!(()=?VX\]kXl>m)no((9F$%}}f	<'@&A(  
 	
r   c                (    | j                  |||      S N)delete_message_from_handler   ri   receipt_handlerL   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DeleteMessageBatchRequestEntryrw   DeleteMessageBatchPOSTrT   rL   rU   rh   r   r   r`   )r   ri   messagesrL   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   rK   )rg   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   rT   rL   )intr`   rh   )r   ri   message_contentdelay_secondsrL   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`   rh   )r   ri   r   rL   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   r|   rK   rf   )r   ri   r   rb   rL   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   r|   r   (ChangeMessageVisibilityBatchRequestEntryrw   ChangeMessageVisibilityBatchr   r   r   )r   ri   r   rL   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
ListQueuesr2   rK   )r   r   )r   r   rL   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   ra   rL   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qr<   s     r   	<genexpr>z5AsyncSQSConnection._on_queue_ready.<locals>.<genexpr>%  s      71!%%.."6Q7s    ++)next)r   r<   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ListDeadLetterSourceQueuesr2   rK   )r   r(   r   )r   ri   rL   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
ActionNamerK   rf   )r   ri   labelaws_account_idaction_namerL   s         r   add_permissionz!AsyncSQSConnection.add_permission/  s4    +&( HHx  
 	
r   c                D    | j                  dd|i|j                  |      S )NRemovePermissionr   rK   rf   )r   ri   r   rL   s       r   remove_permissionz$AsyncSQSConnection.remove_permission9  s*    % 0%((X  
 	
r   )r   NNN)NN)FN)AllNr   )r   NNNN) N)__name__
__module____qualname____doc__r   r0   rE   rZ   rc   rk   rm   rs   ry   r   r   r   r   r   r   r   r   r   r   lookupr   r   r   r   __classcell__)r   s   @r   r   r      s    
 '+ $
0Z" 
D ?F 8<22
	
 GK+/
6


& -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   ?  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 )NrH   r   )r   r   tupler   r   dictr   r   )r$   r   partdottedr   itemkeyrx   s           r   r   r   E  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
   ri   r   __all__r   r   r   r*   r   r   <module>r      sB     "  )  E 1  ! 
!h
0 h
V	-
#r   