
    ^fV                       d Z ddlmZ ddlZddlZddl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mZmZ dd	lmZ dd
lmZ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 m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(  ee)          Z*d ej+        D             Z,de,d<   dZ-d Z. G d de/          Z0 G d de/          Z1 G d de/          Z2 G d d e(j3                  Z3 G d! d"e(j4                  Z4 G d# d$e(j5                  Z5dS )%a?  Amazon SQS transport module for Kombu.

This package implements an AMQP-like interface on top of Amazons SQS service,
with the goal of being optimized for high performance and reliability.

The default settings for this module are focused now on high performance in
task queue situations where tasks are small, idempotent and run very fast.

SQS Features supported by this transport
========================================
Long Polling
------------
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html

Long polling is enabled by setting the `wait_time_seconds` transport
option to a number > 1.  Amazon supports up to 20 seconds.  This is
enabled with 10 seconds by default.

Batch API Actions
-----------------
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-batch-api.html

The default behavior of the SQS Channel.drain_events() method is to
request up to the 'prefetch_count' messages on every request to SQS.
These messages are stored locally in a deque object and passed back
to the Transport until the deque is empty, before triggering a new
API call to Amazon.

This behavior dramatically speeds up the rate that you can pull tasks
from SQS when you have short-running tasks (or a large number of workers).

When a Celery worker has multiple queues to monitor, it will pull down
up to 'prefetch_count' messages from queueA and work on them all before
moving on to queueB.  If queueB is empty, it will wait up until
'polling_interval' expires before moving back and checking on queueA.

Message Attributes
-----------------
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html

SQS supports sending message attributes along with the message body.
To use this feature, you can pass a 'message_attributes' as keyword argument
to `basic_publish` method.

Other Features supported by this transport
==========================================
Predefined Queues
-----------------
The default behavior of this transport is to use a single AWS credential
pair in order to manage all SQS queues (e.g. listing queues, creating
queues, polling queues, deleting messages).

If it is preferable for your environment to use multiple AWS credentials, you
can use the 'predefined_queues' setting inside the 'transport_options' map.
This setting allows you to specify the SQS queue URL and AWS credentials for
each of your queues. For example, if you have two queues which both already
exist in AWS) you can tell this transport about them as follows:

.. code-block:: python

    transport_options = {
      'predefined_queues': {
        'queue-1': {
          'url': 'https://sqs.us-east-1.amazonaws.com/xxx/aaa',
          'access_key_id': 'a',
          'secret_access_key': 'b',
          'backoff_policy': {1: 10, 2: 20, 3: 40, 4: 80, 5: 320, 6: 640}, # optional
          'backoff_tasks': ['svc.tasks.tasks.task1'] # optional
        },
        'queue-2.fifo': {
          'url': 'https://sqs.us-east-1.amazonaws.com/xxx/bbb.fifo',
          'access_key_id': 'c',
          'secret_access_key': 'd',
          'backoff_policy': {1: 10, 2: 20, 3: 40, 4: 80, 5: 320, 6: 640}, # optional
          'backoff_tasks': ['svc.tasks.tasks.task2'] # optional
        },
      }
    'sts_role_arn': 'arn:aws:iam::<xxx>:role/STSTest', # optional
    'sts_token_timeout': 900 # optional
    }

Note that FIFO and standard queues must be named accordingly (the name of
a FIFO queue must end with the .fifo suffix).

backoff_policy & backoff_tasks are optional arguments. These arguments
automatically change the message visibility timeout, in order to have
different times between specific task retries. This would apply after
task failure.

AWS STS authentication is supported, by using sts_role_arn, and
sts_token_timeout. sts_role_arn is the assumed IAM role ARN we are trying
to access with. sts_token_timeout is the token timeout, defaults (and minimum)
to 900 seconds. After the mentioned period, a new token will be created.



If you authenticate using Okta_ (e.g. calling |gac|_), you can also specify
a 'session_token' to connect to a queue. Note that those tokens have a
limited lifetime and are therefore only suited for short-lived tests.

.. _Okta: https://www.okta.com/
.. _gac: https://github.com/Nike-Inc/gimme-aws-creds#readme
.. |gac| replace:: ``gimme-aws-creds``


Client config
-------------
In some cases you may need to override the botocore config. You can do it
as follows:

.. code-block:: python

    transport_option = {
      'client-config': {
          'connect_timeout': 5,
       },
    }

For a complete list of settings you can adjust using this option see
https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html

Features
========
* Type: Virtual
* Supports Direct: Yes
* Supports Topic: Yes
* Supports Fanout: Yes
* Supports Priority: No
* Supports TTL: No
    )annotationsN)datetime)Empty)Config)ClientError)ensure_promisepromise	transform)get_event_loop)boto3
exceptions)AsyncSQSConnection)AsyncMessage)
get_logger)
scheduling)bytes_to_strsafe_str)dumpsloads)cached_property   )virtualc                6    i | ]}|d vt          |          dS )z-_._   )ord).0cs     E/var/www/html/env/lib/python3.11/site-packages/kombu/transport/SQS.py
<dictcomp>r      s,       CFFD    -   .   
   c                F    	 t          |           S # t          $ r | cY S w xY w)z5Try to convert x' to int, or return x' if that fails.)int
ValueError)xs    r   	maybe_intr(      s6    1vv   s      c                      e Zd ZdZdS )UndefinedQueueExceptionzAPredefined queues are being used and an undefined queue was used.N__name__
__module____qualname____doc__ r    r   r*   r*      s        KKKKr    r*   c                      e Zd ZdZdS )InvalidQueueExceptionz@Predefined queues are being used and configuration is not valid.Nr+   r0   r    r   r2   r2      s        JJJJr    r2   c                      e Zd ZdZdS )AccessDeniedQueueExceptionzRaised when access to the AWS queue is denied.

    This may occur if the permissions are not correctly set or the
    credentials are invalid.
    Nr+   r0   r    r   r4   r4      s           r    r4   c                  6     e Zd ZdZd fd	Zd Zd Zd Z xZS )QoSz5Quality of Service guarantees implementation for SQS.Fc                    t                                          ||           |                     |          \  }}}}|r |r |r |r |                     ||||           d S d S d S d S d S )N)requeue)superreject1_extract_backoff_policy_configuration_and_messageapply_backoff_policy)selfdelivery_tagr8   routing_keymessagebackoff_tasksbackoff_policy	__class__s          r   r:   z
QoS.reject   s    |W555BB  	<Wm^  	J7 	J} 	J 	J%%\>=J J J J J	J 	J 	J 	J 	J 	J 	J 	Jr    c                   	 | j         |         }|j        d         }n# t          $ r Y dS w xY w|r|sdS | j        j                            |i           }|                    d          }|                    d          }||||fS )Nr?   )NNNNrA   rB   )
_delivereddelivery_infoKeyErrorchannelpredefined_queuesget)r=   r>   r@   r?   queue_configrA   rB   s          r   r;   z5QoS._extract_backoff_policy_configuration_and_message   s    	*ol3G!/>KK 	* 	* 	*)))	* 	*' 	*))|599+rJJ$((99%))*:;;G]NBBs    
++c                   | j         j        |         }|                     |          \  }}|r|sd S |                    |          }||v r6|6| j                             |          }	|	                    |||           d S d S d S )NQueueUrlReceiptHandleVisibilityTimeout)rH   _queue_cache'extract_task_name_and_number_of_retriesrJ   sqschange_message_visibility)
r=   r?   r>   rB   rA   	queue_url	task_namenumber_of_retriespolicy_valuer   s
             r   r<   zQoS.apply_backoff_policy   s    L-k:	88FF 	%	$ 	 1 	4%))*;<<%%,*B  --A''"*". (      &%*B*Br    c                    | j         |         }|j        }|d         }t          |j        d         d         d         d                   }||fS )NtaskrF   sqs_message
AttributesApproximateReceiveCount)rE   headersr%   
properties)r=   r>   r@   message_headersrV   rW   s         r   rR   z+QoS.extract_task_name_and_number_of_retries   s`    /,/!/#F+	/>+--FHI I +++r    F)	r,   r-   r.   r/   r:   r;   r<   rR   __classcell__rC   s   @r   r6   r6      sy        ??J J J J J JC C C   , , , , , , ,r    r6   c                      e Zd ZdZdZdZdZdZdZi Z	dZ
i Zi Z e            ZeZ fdZd Zd	 Z fd
Z fdZd:dZd ZefdZd Zd Zd Z fdZd Zed             Zd Z d Z!e"dfdZ#d Z$d;dZ%d Z&e"fdZ'e"dfdZ(d<dZ)d Z*	 d<d Z+	 d= fd"	Z,d> fd$	Z-d% Z.d& Z/ fd'Z0	 d;d(Z1d;d)Z2d* Z3d+ Z4d;d,Z5e6d-             Z7e6d.             Z8e9d/             Z:e9d0             Z;e9d1             Z<e9d2             Z=e9d3             Z>e9d4             Z?e9d5             Z@e9d6             ZAe9d7             ZBe9d8             ZCe9d9             ZD xZES )?ChannelzSQS Channel.z	us-east-1i  r#   zkombu%(vhost)sNc                   t           t          d           t                      j        |i | |                                  |                     | j                   |                    d          pt                      | _	        d S )Nzboto3 is not installedhub)
r   ImportErrorr9   __init___validate_predifined_queues_update_queue_cachequeue_name_prefixrJ   r   rg   )r=   argskwargsrC   s      r   ri   zChannel.__init__  s    =6777$)&)))((*** 	  !7888::e$$8(8(8r    c                V   | j                                         D ]\  }}|d                             d          }|                    d          }|r*|s(t          d                    |d                             |s+|r)t          d                    ||d                             dS )zCheck that standard and FIFO queues are named properly.

        AWS requires FIFO queues to have a name
        that ends with the .fifo suffix.
        url.fifoz6Queue with url '{}' must have a name ending with .fifoz.Queue with name '{}' is not a FIFO queue: '{}'N)rI   itemsendswithr2   format)r=   
queue_nameqfifo_url	fifo_names        r   rj   z#Channel._validate_predifined_queues  s     "399;; 	 	MJx((11H"++G44I 		 	+((.qx(8(8    ) +!6*ah77  	 	r    c                B   | j         r1| j                                         D ]\  }}|d         | j        |<   d S |                                                     |          }|                    dg           D ]'}|                    d          d         }|| j        |<   (d S )Nrp   )QueueNamePrefix	QueueUrls/)rI   rr   rQ   rS   list_queuesrJ   split)r=   rl   ru   rv   resprp   s         r   rk   zChannel._update_queue_cache'  s    ! 	!%!7!=!=!?!? 9 9
A01%!*--Fxxzz%%6G%HH88K,, 	0 	0C3+J,/Dj))	0 	0r    c                    |r| j                             |           | j        r|                     |            t	                      j        ||g|R i |S N)_noack_queuesaddrg   _loop1r9   basic_consume)r=   queueno_ackrm   rn   rC   s        r   r   zChannel.basic_consume2  sx     	*""5)))8 	KK$uww$6
 
 
 
$*
 
 	
r    c                    || j         v r'| j        |         }| j                            |           t	                                          |          S r   )
_consumers_tag_to_queuer   discardr9   basic_cancel)r=   consumer_tagr   rC   s      r   r   zChannel.basic_cancel;  sL    4?**&|4E&&u---ww##L111r    c                    | j         r| j                                        st                      |                     | j        ||           dS )zReturn a single payload message from one of our queues.

        Raises
        ------
            Queue.Empty: if no messages available.
        )timeoutN)r   qoscan_consumer   _pollcycle)r=   r   callbackrn   s       r   drain_eventszChannel.drain_eventsA  sN      	dh&:&:&<&< 	''M 	

4:x
99999r    c                Z    t          j        | j        | j        t                    | _        dS )aA  Reset the consume cycle.

        Returns
        -------
            FairCycle: object that points to our _get_bulk() method
                rather than the standard _get() method.  This allows for
                multiple messages to be returned at once from SQS (
                based on the prefetch limit).
        N)r   	FairCycle	_get_bulk_active_queuesr   _cycler=   s    r   _reset_cyclezChannel._reset_cycleO  s(     !*ND/
 
r    c                "   |                     d          rL|dt          d                    }t          t          |                                        |          }|dz   S t          t          |                                        |          S )z3Format AMQP queue name into a legal SQS queue name.rq   N)rs   lenstrr   	translate)r=   nametablepartials       r   entity_namezChannel.entity_name]  s|    ==!! 	8>S\\M>*G(7++,,66u==GW$$x~~&&00777r    c                <    |                      | j        |z             S r   )r   rl   )r=   ru   s     r   canonical_queue_namezChannel.canonical_queue_namef  s     6 CDDDr    c                   |                      |          }|| j        vr|                     |           	 | j        |         S # t          $ r | j        r"t          d                    |                    dt          | j                  i}|	                    d          rd|d<   | 
                    ||          }|d         | j        |<   |d         cY S w xY w)zEnsure a queue with given name exists in SQS.

        Arguments:
        ---------
            queue (str): the AMQP queue name
        Returns
            str: the SQS queue URL
        <Queue with name '{}' must be defined in 'predefined_queues'.rP   rq   true	FifoQueuerN   )r   rQ   rk   rG   rI   r*   rt   r   visibility_timeoutrs   _create_queue)r=   r   rn   	sqs_qname
attributesr   s         r   
_new_queuezChannel._new_queuei  s    --e44	 D---$$Y///	$$Y// 	$ 	$ 	$% %-6&##% % %
 .s43J/K/KLJ!!'** 1*0
;'%%i<<D+/
+;Di(
####	$s   A BCCc                    | j         rdS |                    | j                            d          pi            |                     |                              ||          S )z=Create an SQS queue with a given name and nominal attributes.Nzsqs-creation-attributesr   )	QueueNamer\   )rI   updatetransport_optionsrJ   rS   create_queue)r=   ru   r   s      r   r   zChannel._create_queue  sy     ! 	4"&&'@AAGR	
 	
 	
 xxjx))66 ! 7 
 
 	
r    c                    | j         rdS t                                          |           | j                            |d           dS )zDelete queue by name.N)rI   r9   _deleterQ   pop)r=   r   rm   rn   rC   s       r   r   zChannel._delete  sH    ! 	FeT*****r    c                (   |                      |          }d|i}d|v rd|d         v r|d                             d          |d<   |                    d          rad|d         v r|d         d         |d<   nd|d<   d|d         v r|d         d         |d<   n?t          t	          j                              |d<   nd	|d         v r|d         d	         |d	<   | j        r/t                                          t          |                    }nt          |          }||d
<   | 
                    |                     |                    }|                    d          r&|                    ||d         d         d           dS  |j        di | dS )zPut message onto queue.rN   r_   message_attributesMessageAttributesrq   MessageGroupIddefaultMessageDeduplicationIdDelaySecondsMessageBodyr   redeliveredr>   r   rM   Nr0   )r   r   rs   r   uuiduuid4sqs_base64_encodingr   encoder   rS   r   rJ   rT   send_message)r=   r   r@   rn   q_urlbodyr   s          r   _putzChannel._put  s   &&e$7""#w|'<<< L)--.BCC *+~~g&& >#w|'<<<-.>? +,, 09F+,+w|/DDD-.FG 344 8;4:<<7H7HF344!W\%:::-n= >* # 	">>((w88DD>>D $}HH444U;;H<<;;}%% 	%''%l3NC"# (      AN$$V$$$$$r    c                    	 t          j        |           }t          j        |          | k    r|S n# t          $ r Y nw xY w| S r   )base64	b64decode	b64encode	Exception)byte_stringdatas     r   _optional_b64_decodezChannel._optional_b64_decode  s_    	#K00D%%44 5  	 	 	D	s   -1 
>>c                "   |                      |d                                                   }t          t          |                    }|| j        v rF|                     |          }|                     |                              ||d                    nv	 |d         }|d         d         }n;# t          $ r. i }d|i}|	                    t          |          |d           Y nw xY w|	                    ||d           |d         |d<   |S )	NBodyr   rO   r_   rF   )r   r_   r[   	sqs_queuer>   )
r   r   r   r   r   r   asynsqsdelete_messagerG   r   )r=   r@   ru   r   r   payloadr_   rF   s           r   _message_to_pythonzChannel._message_to_python  sP   (()?)?)A)ABBT**+++++OOJ//ELLzL**99(   

$\2
 ' 5o F    "-}=
(..",        	   &U" "    *1)AJ~&s   B1 15C)(C)c                R                                      fd|D             S )a  Convert a list of SQS Message objects into Payloads.

        This method handles converting SQS Message objects into
        Payloads, and appropriately updating the queue depending on
        the 'ack' settings for that queue.

        Arguments:
        ---------
            messages (SQSMessage): A list of SQS Message objects.
            queue (str): Name representing the queue they came from.

        Returns
        -------
            List: A list of Payload objects
        c                >    g | ]}                     |          S r0   )r   )r   mr   r   r=   s     r   
<listcomp>z/Channel._messages_to_python.<locals>.<listcomp>  s+    KKKQ''5%88KKKr    )r   )r=   messagesr   r   s   ` `@r   _messages_to_pythonzChannel._messages_to_python  s8      &&KKKKKK(KKKKr    c                   |                                  }|r|                     |          }|                     |                              ||| j                  }|                    d          rr|d         D ]-}t          |d                                                   |d<   .|                     |d         |          D ]}| j	        
                    ||           dS t                      )a;  Try to retrieve multiple messages off ``queue``.

        Where :meth:`_get` returns a single Payload object, this method
        returns a list of Payload objects.  The number of objects returned
        is determined by the total number of messages available in the queue
        and the number of messages the QoS object allows (based on the
        prefetch_count).

        Note:
        ----
            Ignores QoS limits so caller is responsible for checking
            that we are allowed to consume at least one message from the
            queue.  get_bulk will then ask QoS for an estimate of
            the number of extra messages that we can consume.

        Arguments:
        ---------
            queue (str): The queue name to pull from.

        Returns
        -------
            List[Message]
        r   rN   MaxNumberOfMessagesWaitTimeSecondsMessagesr   r   N)_get_message_estimater   rS   receive_messagewait_time_secondsrJ   r   decoder   
connection_deliverr   )	r=   r   max_if_unlimitedr   	max_countr   r   r   msgs	            r   r   zChannel._get_bulk  s    < ..00	 
	OOE**E88%8((88I $ 6 9 8 8D xx
## j) F FA ,!F) < < < C C E EAfII33D4DeLL 9 9CO,,S%8888ggr    c                   |                      |          }|                     |                              |d| j                  }|                    d          rgt          |d         d         d                                                   }||d         d         d<   |                     |d         |          d         S t                      )z/Try to retrieve a single message off ``queue``.r   r   r   r   r   r   r   )	r   rS   r   r   rJ   r   r   r   r   )r=   r   r   r   r   s        r   _getzChannel._get4  s    &&xxex$$44 2 5 4 4 88J 	HT*%5a%8%@AAAHHJJD*.DQ'++D,<eDDQGGggr    c                F    | j                             | j        |           d S r   )rg   	call_soon_schedule_queue)r=   r   _s      r   r   zChannel._loop1@  s#    4/77777r    c                    || j         v r]| j                                        r-|                     |t	          | j        |f                     d S |                     |           d S d S N)r   )r   r   r   _get_bulk_asyncr	   r   )r=   r   s     r   r   zChannel._schedule_queueC  s    D'''x##%% #$$GDK%$B$B %      E""""" ('r    c                x    | j                                         }t          ||nt          |d          |          S )Nr   )r   can_consume_max_estimateminmax)r=   r   maxcounts      r   r   zChannel._get_message_estimateL  sB    84466 ( 0c(A6F6F
 
 	
r    c                    |                                  }|r|                     |||          S t          |          } |g            |S r   )r   
_get_asyncr   )r=   r   r   r   r   s        r   r   zChannel._get_bulk_asyncS  sS    --// 	G??5(X?FFF!(++r    r   c                    |                      |          }|                     |          }|                     ||||                     |          t	          | j        |||                    S )Nr   )ru   rU   countr   r   )r   r   _get_from_sqsr   r
   _on_messages_ready)r=   r   r  r   r   qnames         r   r   zChannel._get_async]  st    &&))%00!!U||%|00'5%  " 
 
 	
r    c                    d|v rG|d         rA| j         j        }|d         D ].}|                     |||          } ||         |           +d S d S d S )Nr   )r   
_callbacksr   )r=   r   r  r   	callbacksr   
msg_parseds          r   r  zChannel._on_messages_readyh  s|    !!hz&:!2I
+ - -!44S%GG
 	% ,,,,	 "!!!- -r    c                @    |                     |||| j        |          S )zwRetrieve and handle messages from SQS.

        Uses long polling and returns :class:`~vine.promises.promise`.
        )number_messagesr   r   )r   r   )r=   ru   rU   r   r  r   s         r   r  zChannel._get_from_sqso  s1     ))	5"4 * 
 
 	
r    r   c                    |D ]}|j                             |d            t                                          |          S r   )rF   r   r9   _restore)r=   r@   unwanted_delivery_infounwanted_keyrC   s       r   r  zChannel._restore{  sF    2 	: 	:L!%%lD9999ww(((r    Fc                   	 | j                             |          j        }|d         }d }d|v r|                     |d                   }	 |                     |                              |d         |d                    t                                          |           d S # t          $ rc}|j	        d         d         d	k    r t          |j	        d         d
                   t                                          |           Y d }~d S d }~ww xY w# t          $ r% t                                          |           Y d S w xY w)Nr[   r?   r   r   rO   )rN   rO   ErrorCodeAccessDeniedMessage)r   rJ   rF   r   rS   r   r9   	basic_ackr   responser4   basic_rejectrG   )r=   r>   multipler@   r[   r   	exceptionrC   s          r   r  zChannel.basic_ack  sw   	0hll<00>G!-0K E''11'-2HII0u%%44$[1"-o"> 5    !!,/////  3 3 3%g.v6.HH4!*73I>   $$\2222222223  	, 	, 	,GGl++++++	,s*   'D 7B& &
D0ADD+EEc                    |                      |          }|                     |                     |                    }|                    |dg          }t	          |d         d                   S )z)Return the number of messages in a queue.r   ApproximateNumberOfMessages)rN   AttributeNamesr\   )r   rS   r   get_queue_attributesr%   )r=   r   r   r   r   s        r   _sizezChannel._size  sr    &&HH444U;;H<<%%9: & < < 4%&CDEEEr    c                    |                      |          }d}t          d          D ]+}|t          |                     |                    z  }|s n,|                     |                              |           |S )z'Delete all current messages in a queue.r   r#   r   )rN   )r   ranger%   r  rS   purge_queue)r=   r   r   sizeis        r   _purgezChannel._purge  s    && r 	 	AC

5))***D u))5)999r    c                H    t                                                       d S r   )r9   close)r=   rC   s    r   r%  zChannel.close  s    r    c                    t           j                            ||||          }| j        | j        nd}d|i}| j        
| j        |d<   | j                            d          pi }t          di |}	 |j        d	d|	i|S )
N)region_nameaws_access_key_idaws_secret_access_keyaws_session_tokenTuse_sslendpoint_urlzclient-configrS   configr0   )rS   )	r   sessionSession	is_securer,  r   rJ   r   client)
r=   regionaccess_key_idsecret_access_keysession_tokenr.  r0  client_kwargsclient_configr-  s
             r   new_sqs_clientzChannel.new_sqs_client  s    -''+"3+	 ( 
 
 '+n&@DNNd	y
 (,0,=M.).22?CCIr((-((w~DDFDmDDDr    c                   |
| j         r|| j         vrt          d| d          | j         |         }| j                            d          r|                     ||          S | j                            d          s|| j        v r| j        |         S |                     |                    d| j                  |                    d| j        j	                  |                    d| j        j
                            x}| j        |<   |S | j        | j        S |                     | j        | j        j	        | j        j
                  x}| _        |S )NzQueue with name 'z)' must be defined in 'predefined_queues'.sts_role_arnr2  r3  r4  )r2  r3  r4  )rI   r*   r   rJ   _handle_sts_session_predefined_queue_clientsr8  r2  conninfouseridpassword_sqsr=   r   rv   r   s       r   rS   zChannel.sqs  s   !7D222-/ / / /0 0 0 &u-A%)).99 ://q999)--n== D:::9%@@ ++#$554;#?#?*+%% /1E+G +G./ee 3T]5K/M /M	 ,  A6u= H9 9++;-."m4 , 
 
 	
DI
 r    c                ,   t          | d          s|                     | j                            d          | j                            dd                    }|d         | _        |                     |                    d| j                  |d         |d         |d	         
          x}| j        |<   |S | j                            d           t          j
                    k     r|                     | j                            d          | j                            dd                    }|d         | _        |                     |                    d| j                  |d         |d         |d	         
          x}| j        |<   |S | j        |         S )Nsts_expirationr:  sts_token_timeouti  
Expirationr2  AccessKeyIdSecretAccessKeySessionToken)r2  r3  r4  r5  )tzinfo)hasattrgenerate_sts_session_tokenr   rJ   rC  r8  r2  r<  replacer   utcnow)r=   r   rv   	sts_credsr   s        r   r;  zChannel._handle_sts_session  s   t-.. 	977&**>::&**+>DDF FI #,L"9D8<8K8KuuXt{33'6"+,=">'7	 9L 9 9 A.u5 H (((558I8III77&**>::&**+>DDF FI #,L"9D8<8K8KuuXt{33'6"+,=">'7	 9L 9 9 A.u5 H1%88r    c                j    t          j        d          }|                    |d|          }|d         S )NstsCelery)RoleArnRoleSessionNameDurationSecondsCredentials)r   r1  assume_role)r=   role_arntoken_expiry_seconds
sts_client
sts_policys        r   rK  z"Channel.generate_sts_session_token  sA    \%((
++$0 , 
 


 -((r    c                   || j         r|| j        v rt          | d          s| j        |         S || j         vr"t          d                    |                    | j         |         }t          |                     |          |                    d| j                            x}| j        |<   |S | j	        | j	        S t          |                     |          | j                  x}| _	        |S )NrC  r   r   r2  )sqs_connectionr2  )
rI   _predefined_queue_async_clientsrJ  r*   rt   r   rS   rJ   r2  _asynsqsrA  s       r   r   zChannel.asynsqs  s   !7<<<4!122 =;EBBD222-+&--! ! ! &u-A"#'88%8#8#8554;77  A4U;
 H=$= .88%800;
 
 
 	
DM r    c                    | j         j        S r   )r   r1  r   s    r   r=  zChannel.conninfo/  s    %%r    c                $    | j         j        j        S r   )r   r1  r   r   s    r   r   zChannel.transport_options3  s    %77r    c                D    | j                             d          p| j        S )Nr   )r   rJ   default_visibility_timeoutr   s    r   r   zChannel.visibility_timeout7  s'    &**+?@@ 0/	1r    c                8    | j                             di           S )z/Map of queue_name to predefined queue settings.rI   r   rJ   r   s    r   rI   zChannel.predefined_queues<  s     %))*=rBBBr    c                8    | j                             dd          S )Nrl    rd  r   s    r   rl   zChannel.queue_name_prefixA  s    %))*=rBBBr    c                    dS )NFr0   r   s    r   supports_fanoutzChannel.supports_fanoutE  s    ur    c                t    | j                             d          pt          j                    j        p| j        S )Nr2  )r   rJ   r   r/  r'  default_regionr   s    r   r2  zChannel.regionI  s7    &**844 $+$#	%r    c                6    | j                             d          S )N
regioninford  r   s    r   rl  zChannel.regioninfoO  s    %)),777r    c                6    | j                             d          S )Nr0  rd  r   s    r   r0  zChannel.is_secureS  s    %))+666r    c                6    | j                             d          S Nportrd  r   s    r   rp  zChannel.portW  s    %))&111r    c                    | j         j        J| j        rdnd}| j         j        d| j         j         }nd}d                    || j         j        |          S d S )Nhttpshttp:rf  z	{}://{}{})r=  hostnamer0  rp  rt   )r=   schemerp  s      r   r,  zChannel.endpoint_url[  so    =!- $:WWFF}!-/4=-//%%&   .-r    c                B    | j                             d| j                  S )Nr   )r   rJ   default_wait_time_secondsr   s    r   r   zChannel.wait_time_secondsi  s)    %))*=*.*HJ J 	Jr    c                8    | j                             dd          S )Nr   Trd  r   s    r   r   zChannel.sqs_base64_encodingn  s    %))*?FFFr    )NNr   )r   N)r   ra   )Fr,   r-   r.   r/   rj  rb  rx  domain_formatr^  r]  r@  r<  rQ   setr   r6   ri   rj   rk   r   r   r   r   CHARS_REPLACE_TABLEr   r   r   r   r   r   staticmethodr   r   r   SQS_MAX_MESSAGESr   r   r   r   r   r   r   r  r  r  r  r  r#  r%  r8  rS   r;  rK  r   propertyr=  r   r   r   rI   rl   rh  r2  rl  r0  rp  r,  r   r   rb   rc   s   @r   re   re      s        N!% "$MH&(#D "LCEEM
C9 9 9 9 9  (	0 	0 	0
 
 
 
 
2 2 2 2 2: : : :
 
 
 ': 8 8 8 8E E E"$ "$ "$H
 
 
 + + + + +'% '% '%R 	 	 \	  8L L L( $4d* * * *X
 
 
8 8 8 8# # # 6F 
 
 
 
 *:D   	
 	
 	
 	
- - - 59

 

 

 

 )E) ) ) ) ) )0 0 0 0 0 02F F F       9=E E E E$       D9 9 9:) ) )   6 & & X& 8 8 X8 1 1 _1 C C _C C C _C   _ % % _%
 8 8 _8 7 7 _7 2 2 _2   _ J J _J G G _G G G G Gr    re   c                      e Zd ZdZeZdZdZdZej	        j
        ej        ej        fz   Z
ej	        j        ej        fz   ZdZdZej	        j                            d edg                    Zed	             ZdS )
	Transporta  SQS Transport.

    Additional queue attributes can be supplied to SQS during queue
    creation by passing an ``sqs-creation-attributes`` key in
    transport_options. ``sqs-creation-attributes`` must be a dict whose
    key-value pairs correspond with Attributes in the
    `CreateQueue SQS API`_.

    For example, to have SQS queues created with server-side encryption
    enabled using the default Amazon Managed Customer Master Key, you
    can set ``KmsMasterKeyId`` Attribute. When the queue is initially
    created by Kombu, encryption will be enabled.

    .. code-block:: python

        from kombu.transport.SQS import Transport

        transport = Transport(
            ...,
            transport_options={
                'sqs-creation-attributes': {
                    'KmsMasterKeyId': 'alias/aws/sqs',
                },
            }
        )

    .. _CreateQueue SQS API: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_CreateQueue.html#API_CreateQueue_RequestParameters
    r   r   NrS   Tdirect)asynchronousexchange_typec                    d| j         iS ro  )default_portr   s    r   default_connection_paramsz#Transport.default_connection_params  s    )**r    )r,   r-   r.   r/   re   polling_intervalr   r  r   r  connection_errorsr   BotoCoreErrorsocketerrorchannel_errorsdriver_typedriver_name
implementsextend	frozensetr  r  r0   r    r   r  r  s  s         : GL+		!6<0	1 
 	(J,D+FF  KK"-44i
++ 5  J
 + + X+ + +r    r  )6r/   
__future__r   r   r  stringr   r   r   r   botocore.clientr   botocore.exceptionsr   viner   r	   r
   kombu.asynchronousr   kombu.asynchronous.aws.extr   r   %kombu.asynchronous.aws.sqs.connectionr   "kombu.asynchronous.aws.sqs.messager   	kombu.logr   kombu.utilsr   kombu.utils.encodingr   r   kombu.utils.jsonr   r   kombu.utils.objectsr   rf  r   r,   loggerpunctuationr|  r~  r(   r   r*   r2   r4   r6   re   r  r0   r    r   <module>r     s  A AH # " " " " "                 " " " " " " + + + + + + 3 3 3 3 3 3 3 3 3 3 - - - - - - 8 8 8 8 8 8 8 8 D D D D D D ; ; ; ; ; ;             " " " " " " 7 7 7 7 7 7 7 7 ) ) ) ) ) ) ) ) / / / / / /      	H		  ,    ! D     L L L L Li L L LK K K K KI K K K       0, 0, 0, 0, 0,'+ 0, 0, 0,fz	G z	G z	G z	G z	Ggo z	G z	G z	Gz4+ 4+ 4+ 4+ 4+! 4+ 4+ 4+ 4+ 4+r    