o ckF[`@stddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZGd d d eZdS) N)AWSQueryConnection) SQSRegionInfo)Queue)Message) Attributes) BatchResults)SQSErrorBotoServerErrorcseZdZdZejdddZejdddZejdddZ d Z e Z d Z  d;fdd ZddZdddZddZ  d?d d!Zd"d#Zd$d%Zd&d'Z d@d(d)Zd*d+Zd,d-Zd.d/ZdAd1d2Zd>> connection.set_queue_attribute(queue, 'DelaySeconds', 900) * For `MaximumMessageSize` the value must be an integer number of bytes from 1024 (1 KiB) to 262144 (256 KiB). >>> connection.set_queue_attribute(queue, 'MaximumMessageSize', 262144) * For `MessageRetentionPeriod` the value must be an integer number of seconds from 60 (1 minute) to 1209600 (14 days). >>> connection.set_queue_attribute(queue, 'MessageRetentionPeriod', 1209600) * For `Policy` the value must be an string that contains JSON formatted parameters and values. >>> connection.set_queue_attribute(queue, 'Policy', json.dumps({ ... 'Version': '2008-10-17', ... 'Id': '/123456789012/testQueue/SQSDefaultPolicy', ... 'Statement': [ ... { ... 'Sid': 'Queue1ReceiveMessage', ... 'Effect': 'Allow', ... 'Principal': { ... 'AWS': '*' ... }, ... 'Action': 'SQS:ReceiveMessage', ... 'Resource': 'arn:aws:aws:sqs:us-east-1:123456789012:testQueue' ... } ... ] ... })) * For `ReceiveMessageWaitTimeSeconds` the value must be an integer number of seconds from 0 to 20. >>> connection.set_queue_attribute(queue, 'ReceiveMessageWaitTimeSeconds', 20) * For `VisibilityTimeout` the value must be an integer number of seconds from 0 to 43200 (12 hours). >>> connection.set_queue_attribute(queue, 'VisibilityTimeout', 43200) * For `RedrivePolicy` the value must be an string that contains JSON formatted parameters and values. You can set maxReceiveCount to a value between 1 and 1000. The deadLetterTargetArn value is the Amazon Resource Name (ARN) of the queue that will receive the dead letter messages. >>> connection.set_queue_attribute(queue, 'RedrivePolicy', json.dumps({ ... 'maxReceiveCount': 5, ... 'deadLetterTargetArn': "arn:aws:aws:sqs:us-east-1:123456789012:testDeadLetterQueue" ... })) )zAttribute.NamezAttribute.ValueSetQueueAttributesr8)rr;rCvaluer4r*r*r+set_queue_attributes <z!SQSConnection.set_queue_attributecCspd|i}|dur ||d<|dur|||d|dur||d<|dur*|||d|d|d|jfg|j|S) a, Read messages from an SQS Queue. :type queue: A Queue object :param queue: The Queue from which messages are read. :type number_messages: int :param number_messages: The maximum number of messages to read (default=1) :type visibility_timeout: int :param visibility_timeout: The number of seconds the message should remain invisible to other queue readers (default=None which uses the Queues default) :type attributes: str :param attributes: The name of additional attribute to return with response or All if you want all attributes. The default is to return no additional attributes. Valid values: * All * SenderId * SentTimestamp * ApproximateReceiveCount * ApproximateFirstReceiveTimestamp :type wait_time_seconds: int :param wait_time_seconds: The duration (in seconds) for which the call will wait for a message to arrive in the queue before returning. If a message is available, the call will return sooner than wait_time_seconds. :type message_attributes: list :param message_attributes: The name(s) of additional message attributes to return. The default is to return no additional message attributes. Use ``['All']`` or ``['.*']`` to return all. :rtype: list :return: A list of :class:`boto.sqs.message.Message` objects. MaxNumberOfMessagesNr.rAWaitTimeSecondsMessageAttributeNameReceiveMessager)build_list_paramsget_list message_classr:)rr;number_messagesr3 attributeswait_time_secondsmessage_attributesr4r*r*r+receive_messages, zSQSConnection.receive_messagecCsd|ji}|d||jS)al Delete a message from a queue. :type queue: A :class:`boto.sqs.queue.Queue` object :param queue: The Queue from which messages are read. :type message: A :class:`boto.sqs.message.Message` object :param message: The Message to be deleted :rtype: bool :return: True if successful, False otherwise. ReceiptHandle DeleteMessage)receipt_handler9r:)rr;messager4r*r*r+delete_messages zSQSConnection.delete_messagecCsdi}t|D] \}}d}d||df}|j||<d||df}|j||<q|jd|t|jddS)aS Deletes a list of messages from a queue in a single request. :type queue: A :class:`boto.sqs.queue.Queue` object. :param queue: The Queue to which the messages will be written. :type messages: List of :class:`boto.sqs.message.Message` objects. :param messages: A list of message objects. DeleteMessageBatchRequestEntry%s.%i.IdrI%s.%i.ReceiptHandleDeleteMessageBatchPOSTverb enumerater:rXr1r)rr;messagesr4imsgprefixp_namer*r*r+delete_message_batch)s    z"SQSConnection.delete_message_batchcCd|i}|d||jS)at Delete a message from a queue, given a receipt handle. :type queue: A :class:`boto.sqs.queue.Queue` object :param queue: The Queue from which messages are read. :type receipt_handle: str :param receipt_handle: The receipt handle for the message :rtype: bool :return: True if successful, False otherwise. rVrWr8)rr;rXr4r*r*r+delete_message_from_handle=s z(SQSConnection.delete_message_from_handlec Csd|i}|r t||d<|durgt|}t|ddD]J\}}||} ||d|<d| vr6| d|d|<d | vrB| d |d |<d | vrN| d |d |<d | vrZ| d |d|<d| vrf| d|d|<q|jd|t|jddS)aT Send a new message to the queue. :type queue: A :class:`boto.sqs.queue.Queue` object. :param queue: The Queue to which the messages will be written. :type message_content: string :param message_content: The body of the message :type delay_seconds: int :param delay_seconds: Number of seconds (0 - 900) to delay this message from being processed. :type message_attributes: dict :param message_attributes: Message attributes to set. Should be of the form: { "name1": { "data_type": "Number", "string_value": "1" }, "name2": { "data_type": "String", "string_value": "Bob" } } MessageBody DelaySecondsNrI)startzMessageAttribute.%s.Name data_typez"MessageAttribute.%s.Value.DataType string_valuez%MessageAttribute.%s.Value.StringValue binary_valuez%MessageAttribute.%s.Value.BinaryValuestring_list_valuez)MessageAttribute.%s.Value.StringListValuebinary_list_valuez)MessageAttribute.%s.Value.BinaryListValue SendMessager_r`)r0sortedkeysrcr1rr:) rr;message_content delay_secondsrTr4rvrerrCr*r*r+ send_messageMs6         zSQSConnection.send_messagec Csvi}t|D]\}}d|d}|d|d|<|d|d|<|d|d|<t|dkr|d 7}t|d}t|D]p\}} |d| } d ||df} | || <d | vrfd ||df} | d || <d | vrxd||df} | d || <d| vrd||df} | d|| <d| vrd||df} | d|| <d| vrd||df} | d|| <q>q|jd|t|jddS)aC Delivers up to 10 messages to a queue in a single request. :type queue: A :class:`boto.sqs.queue.Queue` object. :param queue: The Queue to which the messages will be written. :type messages: List of lists. :param messages: A list of lists or tuples. Each inner tuple represents a single message to be written and consists of and ID (string) that must be unique within the list of messages, the message body itself which can be a maximum of 64K in length, an integer which represents the delay time (in seconds) for the message (0-900) before the message will be delivered to the queue, and an optional dict of message attributes like those passed to ``send_message`` above. zSendMessageBatchRequestEntry.%irIrz%s.Idz%s.MessageBodyz%s.DelaySecondsz.MessageAttributez %s.%i.Nameroz%s.%i.Value.DataTyperpz%s.%i.Value.StringValuerqz%s.%i.Value.BinaryValuerrz%s.%i.Value.StringListValuersz%s.%i.Value.BinaryListValueSendMessageBatchr_r`)rclenrurvr1rr:) rr;rdr4rerfbaservjrrCrhr*r*r+send_message_batchs@         z SQSConnection.send_message_batchcCrE)ab Extends the read lock timeout for the specified message from the specified queue to the specified value. :type queue: A :class:`boto.sqs.queue.Queue` object :param queue: The Queue from which messages are read. :type receipt_handle: str :param receipt_handle: The receipt handle associated with the message whose visibility timeout will be changed. :type visibility_timeout: int :param visibility_timeout: The new value of the message's visibility timeout in seconds. )rVr.ChangeMessageVisibilityr8)rr;rXr3r4r*r*r+change_message_visibilitysz'SQSConnection.change_message_visibilitycCsi}t|D]2\}}d}d||df}|dj||<d||df}|dj||<d||df}|d||<q|jd|t|jdd S) a A batch version of change_message_visibility that can act on up to 10 messages at a time. :type queue: A :class:`boto.sqs.queue.Queue` object. :param queue: The Queue to which the messages will be written. :type messages: List of tuples. :param messages: A list of tuples where each tuple consists of a :class:`boto.sqs.message.Message` object and an integer that represents the new visibility timeout for that message. (ChangeMessageVisibilityBatchRequestEntryr\rIrr]z%s.%i.VisibilityTimeoutChangeMessageVisibilityBatchr_r`rb)rr;rdr4retrgrhr*r*r+change_message_visibility_batchs z-SQSConnection.change_message_visibility_batchcCs$i}|r||d<|d|dtfgS)z Retrieves all queues. :keyword str prefix: Optionally, only return queues that start with this value. :rtype: list :returns: A list of :py:class:`boto.sqs.queue.Queue` instances. QueueNamePrefix ListQueuesQueueUrl)rOr)rrgr4r*r*r+get_all_queuess zSQSConnection.get_all_queuescCs:d|i}|r ||d<z|d|tWStyYdSw)a Retrieves the queue with the given name, or ``None`` if no match was found. :param str queue_name: The name of the queue to retrieve. :param str owner_acct_id: Optionally, the AWS account ID of the account that created the queue. :rtype: :py:class:`boto.sqs.queue.Queue` or ``None`` :returns: The requested queue, or ``None`` if no match was found. r-QueueOwnerAWSAccountId GetQueueUrlN)r1rr)rr2 owner_acct_idr4r*r*r+ get_queues  zSQSConnection.get_queuecCsd|ji}|d|dtfgS)a) Retrieves the dead letter source queues for a given queue. :type queue: A :class:`boto.sqs.queue.Queue` object. :param queue: The queue for which to get DL source queues :rtype: list :returns: A list of :py:class:`boto.sqs.queue.Queue` instances. rListDeadLetterSourceQueues)urlrOr)rr;r4r*r*r+get_dead_letter_source_queuess z+SQSConnection.get_dead_letter_source_queuescCs|||d}|d||jS)a Add a permission to a queue. :type queue: :class:`boto.sqs.queue.Queue` :param queue: The queue object :type label: str or unicode :param label: A unique identification of the permission you are setting. Maximum of 80 characters ``[0-9a-zA-Z_-]`` Example, AliceSendMessage :type aws_account_id: str or unicode :param principal_id: The AWS account number of the principal who will be given permission. The principal must have an AWS account, but does not need to be signed up for Amazon SQS. For information about locating the AWS account identification. :type action_name: str or unicode :param action_name: The action. Valid choices are: * * * SendMessage * ReceiveMessage * DeleteMessage * ChangeMessageVisibility * GetQueueAttributes :rtype: bool :return: True if successful, False otherwise. )Label AWSAccountId ActionName AddPermissionr8)rr;labelaws_account_id action_namer4r*r*r+add_permission s  zSQSConnection.add_permissioncCrj)aj Remove a permission from a queue. :type queue: :class:`boto.sqs.queue.Queue` :param queue: The queue object :type label: str or unicode :param label: The unique label associated with the permission being removed. :rtype: bool :return: True if successful, False otherwise. rRemovePermissionr8)rr;rr4r*r*r+remove_permissionEszSQSConnection.remove_permission)NNTNNNNNrNNrNTN)N)F)r@)rINNNN)NN)r)$__name__ __module__ __qualname____doc__botoconfiggetrr APIVersionDefaultContentTyper ResponseErrorAuthServiceNamerr,r5r=r?rDrHrUrZrirkryrrrrrlookuprrr __classcell__r*r*r(r+r sR    "? : ;6  %r )rboto.connectionrboto.sqs.regioninforboto.sqs.queuerboto.sqs.messagerboto.sqs.attributesrboto.sqs.batchresultsrboto.exceptionrr r r*r*r*r+s