| OLD | NEW |
| 1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/ |
| 2 # | 2 # |
| 3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
| 4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
| 5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
| 6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
| 9 # lowing conditions: | 9 # lowing conditions: |
| 10 # | 10 # |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 """ | 33 """ |
| 34 DefaultRegionName = 'us-east-1' | 34 DefaultRegionName = 'us-east-1' |
| 35 DefaultRegionEndpoint = 'queue.amazonaws.com' | 35 DefaultRegionEndpoint = 'queue.amazonaws.com' |
| 36 APIVersion = '2009-02-01' | 36 APIVersion = '2009-02-01' |
| 37 DefaultContentType = 'text/plain' | 37 DefaultContentType = 'text/plain' |
| 38 ResponseError = SQSError | 38 ResponseError = SQSError |
| 39 | 39 |
| 40 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, | 40 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, |
| 41 is_secure=True, port=None, proxy=None, proxy_port=None, | 41 is_secure=True, port=None, proxy=None, proxy_port=None, |
| 42 proxy_user=None, proxy_pass=None, debug=0, | 42 proxy_user=None, proxy_pass=None, debug=0, |
| 43 https_connection_factory=None, region=None, path='/'): | 43 https_connection_factory=None, region=None, path='/', |
| 44 security_token=None): |
| 44 if not region: | 45 if not region: |
| 45 region = SQSRegionInfo(self, self.DefaultRegionName, self.DefaultReg
ionEndpoint) | 46 region = SQSRegionInfo(self, self.DefaultRegionName, |
| 47 self.DefaultRegionEndpoint) |
| 46 self.region = region | 48 self.region = region |
| 47 AWSQueryConnection.__init__(self, aws_access_key_id, aws_secret_access_k
ey, | 49 AWSQueryConnection.__init__(self, aws_access_key_id, |
| 48 is_secure, port, proxy, proxy_port, proxy_us
er, proxy_pass, | 50 aws_secret_access_key, |
| 49 self.region.endpoint, debug, https_connectio
n_factory, path) | 51 is_secure, port, |
| 52 proxy, proxy_port, |
| 53 proxy_user, proxy_pass, |
| 54 self.region.endpoint, debug, |
| 55 https_connection_factory, path, |
| 56 security_token=security_token) |
| 50 | 57 |
| 51 def _required_auth_capability(self): | 58 def _required_auth_capability(self): |
| 52 return ['sqs'] | 59 return ['sqs'] |
| 53 | 60 |
| 54 def create_queue(self, queue_name, visibility_timeout=None): | 61 def create_queue(self, queue_name, visibility_timeout=None): |
| 55 """ | 62 """ |
| 56 Create an SQS Queue. | 63 Create an SQS Queue. |
| 57 | 64 |
| 58 :type queue_name: str or unicode | 65 :type queue_name: str or unicode |
| 59 :param queue_name: The name of the new queue. Names are scoped to an ac
count and need to | 66 :param queue_name: The name of the new queue. Names are scoped to |
| 60 be unique within that account. Calling this method o
n an existing | 67 an account and need to be unique within that |
| 61 queue name will not return an error from SQS unless t
he value for | 68 account. Calling this method on an existing |
| 62 visibility_timeout is different than the value of the
existing queue | 69 queue name will not return an error from SQS |
| 63 of that name. This is still an expensive operation,
though, and not | 70 unless the value for visibility_timeout is |
| 64 the preferred way to check for the existence of a que
ue. See the | 71 different than the value of the existing queue |
| 72 of that name. This is still an expensive operation, |
| 73 though, and not the preferred way to check for |
| 74 the existence of a queue. See the |
| 65 :func:`boto.sqs.connection.SQSConnection.lookup` meth
od. | 75 :func:`boto.sqs.connection.SQSConnection.lookup` meth
od. |
| 66 | 76 |
| 67 :type visibility_timeout: int | 77 :type visibility_timeout: int |
| 68 :param visibility_timeout: The default visibility timeout for all messag
es written in the | 78 :param visibility_timeout: The default visibility timeout for all |
| 69 queue. This can be overridden on a per-messa
ge. | 79 messages written in the queue. This can |
| 80 be overridden on a per-message. |
| 70 | 81 |
| 71 :rtype: :class:`boto.sqs.queue.Queue` | 82 :rtype: :class:`boto.sqs.queue.Queue` |
| 72 :return: The newly created queue. | 83 :return: The newly created queue. |
| 73 | 84 |
| 74 """ | 85 """ |
| 75 params = {'QueueName': queue_name} | 86 params = {'QueueName': queue_name} |
| 76 if visibility_timeout: | 87 if visibility_timeout: |
| 77 params['DefaultVisibilityTimeout'] = '%d' % (visibility_timeout,) | 88 params['DefaultVisibilityTimeout'] = '%d' % (visibility_timeout,) |
| 78 return self.get_object('CreateQueue', params, Queue) | 89 return self.get_object('CreateQueue', params, Queue) |
| 79 | 90 |
| 80 def delete_queue(self, queue, force_deletion=False): | 91 def delete_queue(self, queue, force_deletion=False): |
| 81 """ | 92 """ |
| 82 Delete an SQS Queue. | 93 Delete an SQS Queue. |
| 83 | 94 |
| 84 :type queue: A Queue object | 95 :type queue: A Queue object |
| 85 :param queue: The SQS queue to be deleted | 96 :param queue: The SQS queue to be deleted |
| 86 | 97 |
| 87 :type force_deletion: Boolean | 98 :type force_deletion: Boolean |
| 88 :param force_deletion: Normally, SQS will not delete a queue that contai
ns messages. | 99 :param force_deletion: Normally, SQS will not delete a queue that |
| 89 However, if the force_deletion argument is True,
the | 100 contains messages. However, if the |
| 90 queue will be deleted regardless of whether there
are messages in | 101 force_deletion argument is True, the |
| 91 the queue or not. USE WITH CAUTION. This will d
elete all | 102 queue will be deleted regardless of whether |
| 103 there are messages in the queue or not. |
| 104 USE WITH CAUTION. This will delete all |
| 92 messages in the queue as well. | 105 messages in the queue as well. |
| 93 | 106 |
| 94 :rtype: bool | 107 :rtype: bool |
| 95 :return: True if the command succeeded, False otherwise | 108 :return: True if the command succeeded, False otherwise |
| 96 """ | 109 """ |
| 97 return self.get_status('DeleteQueue', None, queue.id) | 110 return self.get_status('DeleteQueue', None, queue.id) |
| 98 | 111 |
| 99 def get_queue_attributes(self, queue, attribute='All'): | 112 def get_queue_attributes(self, queue, attribute='All'): |
| 100 """ | 113 """ |
| 101 Gets one or all attributes of a Queue | 114 Gets one or all attributes of a Queue |
| 102 | 115 |
| 103 :type queue: A Queue object | 116 :type queue: A Queue object |
| 104 :param queue: The SQS queue to be deleted | 117 :param queue: The SQS queue to be deleted |
| 105 | 118 |
| 106 :type attribute: str | 119 :type attribute: str |
| 107 :type attribute: The specific attribute requested. If not supplied, the
default | 120 :type attribute: The specific attribute requested. If not supplied, |
| 108 is to return all attributes. Valid attributes are: | 121 the default is to return all attributes. |
| 109 ApproximateNumberOfMessages, | 122 Valid attributes are: |
| 110 ApproximateNumberOfMessagesNotVisible, | 123 |
| 111 VisibilityTimeout, | 124 ApproximateNumberOfMessages| |
| 112 CreatedTimestamp, | 125 ApproximateNumberOfMessagesNotVisible| |
| 113 LastModifiedTimestamp, | 126 VisibilityTimeout| |
| 127 CreatedTimestamp| |
| 128 LastModifiedTimestamp| |
| 114 Policy | 129 Policy |
| 115 | 130 |
| 116 :rtype: :class:`boto.sqs.attributes.Attributes` | 131 :rtype: :class:`boto.sqs.attributes.Attributes` |
| 117 :return: An Attributes object containing request value(s). | 132 :return: An Attributes object containing request value(s). |
| 118 """ | 133 """ |
| 119 params = {'AttributeName' : attribute} | 134 params = {'AttributeName' : attribute} |
| 120 return self.get_object('GetQueueAttributes', params, Attributes, queue.i
d) | 135 return self.get_object('GetQueueAttributes', params, |
| 136 Attributes, queue.id) |
| 121 | 137 |
| 122 def set_queue_attribute(self, queue, attribute, value): | 138 def set_queue_attribute(self, queue, attribute, value): |
| 123 params = {'Attribute.Name' : attribute, 'Attribute.Value' : value} | 139 params = {'Attribute.Name' : attribute, 'Attribute.Value' : value} |
| 124 return self.get_status('SetQueueAttributes', params, queue.id) | 140 return self.get_status('SetQueueAttributes', params, queue.id) |
| 125 | 141 |
| 126 def receive_message(self, queue, number_messages=1, visibility_timeout=None, | 142 def receive_message(self, queue, number_messages=1, |
| 127 attributes=None): | 143 visibility_timeout=None, attributes=None): |
| 128 """ | 144 """ |
| 129 Read messages from an SQS Queue. | 145 Read messages from an SQS Queue. |
| 130 | 146 |
| 131 :type queue: A Queue object | 147 :type queue: A Queue object |
| 132 :param queue: The Queue from which messages are read. | 148 :param queue: The Queue from which messages are read. |
| 133 | 149 |
| 134 :type number_messages: int | 150 :type number_messages: int |
| 135 :param number_messages: The maximum number of messages to read (default=
1) | 151 :param number_messages: The maximum number of messages to read |
| 152 (default=1) |
| 136 | 153 |
| 137 :type visibility_timeout: int | 154 :type visibility_timeout: int |
| 138 :param visibility_timeout: The number of seconds the message should rema
in invisible | 155 :param visibility_timeout: The number of seconds the message should |
| 139 to other queue readers (default=None which us
es the Queues default) | 156 remain invisible to other queue readers |
| 157 (default=None which uses the Queues default) |
| 140 | 158 |
| 141 :type attributes: str | 159 :type attributes: str |
| 142 :param attributes: The name of additional attribute to return with respo
nse | 160 :param attributes: The name of additional attribute to return |
| 143 or All if you want all attributes. The default is to | 161 with response or All if you want all attributes. |
| 144 return no additional attributes. Valid values: | 162 The default is to return no additional attributes. |
| 145 All | 163 Valid values: |
| 146 SenderId | 164 |
| 147 SentTimestamp | 165 All|SenderId|SentTimestamp| |
| 148 ApproximateReceiveCount | 166 ApproximateReceiveCount| |
| 149 ApproximateFirstReceiveTimestamp | 167 ApproximateFirstReceiveTimestamp |
| 150 | 168 |
| 151 :rtype: list | 169 :rtype: list |
| 152 :return: A list of :class:`boto.sqs.message.Message` objects. | 170 :return: A list of :class:`boto.sqs.message.Message` objects. |
| 153 """ | 171 """ |
| 154 params = {'MaxNumberOfMessages' : number_messages} | 172 params = {'MaxNumberOfMessages' : number_messages} |
| 155 if visibility_timeout: | 173 if visibility_timeout: |
| 156 params['VisibilityTimeout'] = visibility_timeout | 174 params['VisibilityTimeout'] = visibility_timeout |
| 157 if attributes: | 175 if attributes: |
| 158 self.build_list_params(params, attributes, 'AttributeName') | 176 self.build_list_params(params, attributes, 'AttributeName') |
| 159 return self.get_list('ReceiveMessage', params, [('Message', queue.messag
e_class)], | 177 return self.get_list('ReceiveMessage', params, |
| 178 [('Message', queue.message_class)], |
| 160 queue.id, queue) | 179 queue.id, queue) |
| 161 | 180 |
| 162 def delete_message(self, queue, message): | 181 def delete_message(self, queue, message): |
| 163 """ | 182 """ |
| 164 Delete a message from a queue. | 183 Delete a message from a queue. |
| 165 | 184 |
| 166 :type queue: A :class:`boto.sqs.queue.Queue` object | 185 :type queue: A :class:`boto.sqs.queue.Queue` object |
| 167 :param queue: The Queue from which messages are read. | 186 :param queue: The Queue from which messages are read. |
| 168 | 187 |
| 169 :type message: A :class:`boto.sqs.message.Message` object | 188 :type message: A :class:`boto.sqs.message.Message` object |
| (...skipping 16 matching lines...) Expand all Loading... |
| 186 :param receipt_handle: The receipt handle for the message | 205 :param receipt_handle: The receipt handle for the message |
| 187 | 206 |
| 188 :rtype: bool | 207 :rtype: bool |
| 189 :return: True if successful, False otherwise. | 208 :return: True if successful, False otherwise. |
| 190 """ | 209 """ |
| 191 params = {'ReceiptHandle' : receipt_handle} | 210 params = {'ReceiptHandle' : receipt_handle} |
| 192 return self.get_status('DeleteMessage', params, queue.id) | 211 return self.get_status('DeleteMessage', params, queue.id) |
| 193 | 212 |
| 194 def send_message(self, queue, message_content): | 213 def send_message(self, queue, message_content): |
| 195 params = {'MessageBody' : message_content} | 214 params = {'MessageBody' : message_content} |
| 196 return self.get_object('SendMessage', params, Message, queue.id, verb='P
OST') | 215 return self.get_object('SendMessage', params, Message, |
| 216 queue.id, verb='POST') |
| 197 | 217 |
| 198 def change_message_visibility(self, queue, receipt_handle, visibility_timeou
t): | 218 def change_message_visibility(self, queue, receipt_handle, |
| 219 visibility_timeout): |
| 199 """ | 220 """ |
| 200 Extends the read lock timeout for the specified message from the specifi
ed queue | 221 Extends the read lock timeout for the specified message from |
| 201 to the specified value. | 222 the specified queue to the specified value. |
| 202 | 223 |
| 203 :type queue: A :class:`boto.sqs.queue.Queue` object | 224 :type queue: A :class:`boto.sqs.queue.Queue` object |
| 204 :param queue: The Queue from which messages are read. | 225 :param queue: The Queue from which messages are read. |
| 205 | 226 |
| 206 :type receipt_handle: str | 227 :type receipt_handle: str |
| 207 :param queue: The receipt handle associated with the message whose | 228 :param queue: The receipt handle associated with the message whose |
| 208 visibility timeout will be changed. | 229 visibility timeout will be changed. |
| 209 | 230 |
| 210 :type visibility_timeout: int | 231 :type visibility_timeout: int |
| 211 :param visibility_timeout: The new value of the message's visibility tim
eout | 232 :param visibility_timeout: The new value of the message's visibility |
| 212 in seconds. | 233 timeout in seconds. |
| 213 """ | 234 """ |
| 214 params = {'ReceiptHandle' : receipt_handle, | 235 params = {'ReceiptHandle' : receipt_handle, |
| 215 'VisibilityTimeout' : visibility_timeout} | 236 'VisibilityTimeout' : visibility_timeout} |
| 216 return self.get_status('ChangeMessageVisibility', params, queue.id) | 237 return self.get_status('ChangeMessageVisibility', params, queue.id) |
| 217 | 238 |
| 218 def get_all_queues(self, prefix=''): | 239 def get_all_queues(self, prefix=''): |
| 219 params = {} | 240 params = {} |
| 220 if prefix: | 241 if prefix: |
| 221 params['QueueNamePrefix'] = prefix | 242 params['QueueNamePrefix'] = prefix |
| 222 return self.get_list('ListQueues', params, [('QueueUrl', Queue)]) | 243 return self.get_list('ListQueues', params, [('QueueUrl', Queue)]) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 240 | 261 |
| 241 :type queue: :class:`boto.sqs.queue.Queue` | 262 :type queue: :class:`boto.sqs.queue.Queue` |
| 242 :param queue: The queue object | 263 :param queue: The queue object |
| 243 | 264 |
| 244 :type label: str or unicode | 265 :type label: str or unicode |
| 245 :param label: A unique identification of the permission you are setting. | 266 :param label: A unique identification of the permission you are setting. |
| 246 Maximum of 80 characters ``[0-9a-zA-Z_-]`` | 267 Maximum of 80 characters ``[0-9a-zA-Z_-]`` |
| 247 Example, AliceSendMessage | 268 Example, AliceSendMessage |
| 248 | 269 |
| 249 :type aws_account_id: str or unicode | 270 :type aws_account_id: str or unicode |
| 250 :param principal_id: The AWS account number of the principal who will be
given | 271 :param principal_id: The AWS account number of the principal who will |
| 251 permission. The principal must have an AWS account
, but | 272 be given permission. The principal must have |
| 252 does not need to be signed up for Amazon SQS. For i
nformation | 273 an AWS account, but does not need to be signed |
| 274 up for Amazon SQS. For information |
| 253 about locating the AWS account identification. | 275 about locating the AWS account identification. |
| 254 | 276 |
| 255 :type action_name: str or unicode | 277 :type action_name: str or unicode |
| 256 :param action_name: The action. Valid choices are: | 278 :param action_name: The action. Valid choices are: |
| 257 \*|SendMessage|ReceiveMessage|DeleteMessage| | 279 \*|SendMessage|ReceiveMessage|DeleteMessage| |
| 258 ChangeMessageVisibility|GetQueueAttributes | 280 ChangeMessageVisibility|GetQueueAttributes |
| 259 | 281 |
| 260 :rtype: bool | 282 :rtype: bool |
| 261 :return: True if successful, False otherwise. | 283 :return: True if successful, False otherwise. |
| 262 | 284 |
| 263 """ | 285 """ |
| 264 params = {'Label': label, | 286 params = {'Label': label, |
| 265 'AWSAccountId' : aws_account_id, | 287 'AWSAccountId' : aws_account_id, |
| 266 'ActionName' : action_name} | 288 'ActionName' : action_name} |
| 267 return self.get_status('AddPermission', params, queue.id) | 289 return self.get_status('AddPermission', params, queue.id) |
| 268 | 290 |
| 269 def remove_permission(self, queue, label): | 291 def remove_permission(self, queue, label): |
| 270 """ | 292 """ |
| 271 Remove a permission from a queue. | 293 Remove a permission from a queue. |
| 272 | 294 |
| 273 :type queue: :class:`boto.sqs.queue.Queue` | 295 :type queue: :class:`boto.sqs.queue.Queue` |
| 274 :param queue: The queue object | 296 :param queue: The queue object |
| 275 | 297 |
| 276 :type label: str or unicode | 298 :type label: str or unicode |
| 277 :param label: The unique label associated with the permission being remo
ved. | 299 :param label: The unique label associated with the permission |
| 300 being removed. |
| 278 | 301 |
| 279 :rtype: bool | 302 :rtype: bool |
| 280 :return: True if successful, False otherwise. | 303 :return: True if successful, False otherwise. |
| 281 """ | 304 """ |
| 282 params = {'Label': label} | 305 params = {'Label': label} |
| 283 return self.get_status('RemovePermission', params, queue.id) | 306 return self.get_status('RemovePermission', params, queue.id) |
| 284 | 307 |
| 285 | 308 |
| 286 | 309 |
| 287 | 310 |
| 288 | 311 |
| OLD | NEW |