Skip to content
Browse files

PEP8 cleanup.

  • Loading branch information...
1 parent ee94b00 commit b4083978da43118274ff3c65dda2d085e30fc5ab @garnaat garnaat committed Mar 28, 2012
View
2 boto/route53/__init__.py
@@ -15,7 +15,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
View
37 boto/route53/connection.py
@@ -15,23 +15,20 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
import xml.sax
-import time
import uuid
import boto
from boto.connection import AWSAuthConnection
from boto import handler
-from boto.resultset import ResultSet
import boto.jsonresponse
import boto.compat as compat
from . import exception
-from . import hostedzone
HZXML = """<?xml version="1.0" encoding="UTF-8"?>
<CreateHostedZoneRequest xmlns="%(xmlns)s">
@@ -41,9 +38,10 @@
<Comment>%(comment)s</Comment>
</HostedZoneConfig>
</CreateHostedZoneRequest>"""
-
+
#boto.set_stream_logger('dns')
+
class Route53Connection(AWSAuthConnection):
DefaultHost = 'route53.amazonaws.com'
"""The default Route53 API endpoint to connect to."""
@@ -68,10 +66,12 @@ def make_request(self, action, path, headers=None, data='', params=None):
if params:
pairs = []
for key, val in params.items():
- if val is None: continue
+ if val is None:
+ continue
pairs.append(key + '=' + compat.quote(str(val)))
path += '?' + '&'.join(pairs)
- return AWSAuthConnection.make_request(self, action, path, headers, data)
+ return AWSAuthConnection.make_request(self, action, path,
+ headers, data)
# Hosted Zones
@@ -110,10 +110,9 @@ def get_all_hosted_zones(self, start_marker=None, zone_list=None):
def get_hosted_zone(self, hosted_zone_id):
"""
Get detailed information about a particular Hosted Zone.
-
+
:type hosted_zone_id: str
:param hosted_zone_id: The unique identifier for the Hosted Zone
-
"""
uri = '/%s/hostedzone/%s' % (self.Version, hosted_zone_id)
response = self.make_request('GET', uri)
@@ -133,7 +132,7 @@ def create_hosted_zone(self, domain_name, caller_ref=None, comment=''):
"""
Create a new Hosted Zone. Returns a Python data structure with
information about the newly created Hosted Zone.
-
+
:type domain_name: str
:param domain_name: The name of the domain. This should be a
fully-specified domain, and should end with a final period
@@ -153,20 +152,20 @@ def create_hosted_zone(self, domain_name, caller_ref=None, comment=''):
use that.
:type comment: str
- :param comment: Any comments you want to include about the hosted
+ :param comment: Any comments you want to include about the hosted
zone.
"""
if caller_ref is None:
caller_ref = str(uuid.uuid4())
- params = {'name' : domain_name,
- 'caller_ref' : caller_ref,
- 'comment' : comment,
- 'xmlns' : self.XMLNameSpace}
+ params = {'name': domain_name,
+ 'caller_ref': caller_ref,
+ 'comment': comment,
+ 'xmlns': self.XMLNameSpace}
xml = HZXML % params
uri = '/%s/hostedzone' % self.Version
response = self.make_request('POST', uri,
- {'Content-Type' : 'text/xml'}, xml)
+ {'Content-Type': 'text/xml'}, xml)
body = response.read()
boto.log.debug(body)
if response.status == 201:
@@ -179,7 +178,7 @@ def create_hosted_zone(self, domain_name, caller_ref=None, comment=''):
raise exception.DNSServerError(response.status,
response.reason,
body)
-
+
def delete_hosted_zone(self, hosted_zone_id):
uri = '/%s/hostedzone/%s' % (self.Version, hosted_zone_id)
response = self.make_request('DELETE', uri)
@@ -201,7 +200,7 @@ def get_all_rrsets(self, hosted_zone_id, type=None,
"""
Retrieve the Resource Record Sets defined for this Hosted Zone.
Returns the raw XML data returned by the Route53 call.
-
+
:type hosted_zone_id: str
:param hosted_zone_id: The unique identifier for the Hosted Zone
@@ -281,7 +280,7 @@ def change_rrsets(self, hosted_zone_id, xml_body):
"""
uri = '/%s/hostedzone/%s/rrset' % (self.Version, hosted_zone_id)
response = self.make_request('POST', uri,
- {'Content-Type' : 'text/xml'},
+ {'Content-Type': 'text/xml'},
xml_body)
body = response.read()
boto.log.debug(body)
View
3 boto/route53/exception.py
@@ -15,13 +15,14 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from boto.exception import BotoServerError
+
class DNSServerError(BotoServerError):
pass
View
2 boto/route53/hostedzone.py
@@ -22,6 +22,7 @@
# IN THE SOFTWARE.
#
+
class HostedZone(object):
def __init__(self, id=None, name=None, owner=None, version=None,
@@ -53,4 +54,3 @@ def endElement(self, name, value, connection):
self.caller_reference = value
else:
setattr(self, name, value)
-
View
14 boto/route53/record.py
@@ -23,6 +23,8 @@
RECORD_TYPES = ['A', 'AAAA', 'TXT', 'CNAME', 'MX', 'PTR', 'SRV', 'SPF']
from boto.resultset import ResultSet
+
+
class ResourceRecordSets(ResultSet):
"""
A list of resource records.
@@ -159,7 +161,6 @@ def __iter__(self):
results = None
-
class Record(object):
"""An individual ResourceRecordSet"""
@@ -195,8 +196,6 @@ class Record(object):
<DNSName>%s</DNSName>
</AliasTarget>"""
-
-
def __init__(self, name=None, type=None, ttl=600, resource_records=None,
alias_hosted_zone_id=None, alias_dns_name=None, identifier=None,
weight=None, region=None):
@@ -225,7 +224,8 @@ def to_xml(self):
"""Spit this resource record set out as XML"""
if self.alias_hosted_zone_id != None and self.alias_dns_name != None:
# Use alias
- body = self.AliasBody % (self.alias_hosted_zone_id, self.alias_dns_name)
+ body = self.AliasBody % (self.alias_hosted_zone_id,
+ self.alias_dns_name)
else:
# Use resource record(s)
records = ""
@@ -241,8 +241,8 @@ def to_xml(self):
self.weight}
elif self.identifier != None and self.region != None:
weight = self.RRRBody % {"identifier": self.identifier, "region":
- self.region}
-
+ self.region}
+
params = {
"name": self.name,
"type": self.type,
@@ -258,7 +258,7 @@ def to_print(self):
rr = 'ALIAS ' + self.alias_hosted_zone_id + ' ' + self.alias_dns_name
else:
# Show resource record(s)
- rr = ",".join(self.resource_records)
+ rr = ",".join(self.resource_records)
if self.identifier != None and self.weight != None:
rr += ' (WRR id=%s, w=%s)' % (self.identifier, self.weight)
View
9 boto/sdb/__init__.py
@@ -14,14 +14,15 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
from .regioninfo import SDBRegionInfo
+
def regions():
"""
Get all available regions for the SDB service.
@@ -45,14 +46,15 @@ def regions():
endpoint='sdb.ap-southeast-1.amazonaws.com')
]
+
def connect_to_region(region_name, **kw_params):
"""
- Given a valid region name, return a
+ Given a valid region name, return a
:class:`boto.sdb.connection.SDBConnection`.
:type: str
:param region_name: The name of the region to connect to.
-
+
:rtype: :class:`boto.sdb.connection.SDBConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
@@ -62,6 +64,7 @@ def connect_to_region(region_name, **kw_params):
return region.connect(**kw_params)
return None
+
def get_region(region_name, **kw_params):
"""
Find and return a :class:`boto.sdb.regioninfo.RegionInfo` object
View
159 boto/sdb/connection.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -26,26 +26,31 @@
from boto.connection import AWSQueryConnection
from boto.sdb.domain import Domain, DomainMetaData
from boto.sdb.item import Item
-from boto.sdb.regioninfo import SDBRegionInfo
from boto.exception import SDBResponseError
+
class ItemThread(threading.Thread):
"""
- A threaded :class:`Item <boto.sdb.item.Item>` retriever utility class.
+ A threaded :class:`Item <boto.sdb.item.Item>` retriever utility class.
Retrieved :class:`Item <boto.sdb.item.Item>` objects are stored in the
``items`` instance variable after :py:meth:`run() <run>` is called.
-
+
.. tip:: The item retrieval will not start until
- the :func:`run() <boto.sdb.connection.ItemThread.run>` method is called.
+ the :func:`run() <boto.sdb.connection.ItemThread.run>` method
+ is called.
"""
+
def __init__(self, name, domain_name, item_names):
"""
:param str name: A thread name. Used for identification.
- :param str domain_name: The name of a SimpleDB
+
+ :param str domain_name: The name of a SimpleDB
:class:`Domain <boto.sdb.domain.Domain>`
+
:type item_names: string or list of strings
- :param item_names: The name(s) of the items to retrieve from the specified
- :class:`Domain <boto.sdb.domain.Domain>`.
+ :param item_names: The name(s) of the items to retrieve from
+ the specified :class:`Domain <boto.sdb.domain.Domain>`.
+
:ivar list items: A list of items retrieved. Starts as empty list.
"""
threading.Thread.__init__(self, name=name)
@@ -56,7 +61,7 @@ def __init__(self, name, domain_name, item_names):
def run(self):
"""
- Start the threaded retrieval of items. Populates the
+ Start the threaded retrieval of items. Populates the
``items`` list with :class:`Item <boto.sdb.item.Item>` objects.
"""
for item_name in self.item_names:
@@ -65,13 +70,14 @@ def run(self):
#boto.set_stream_logger('sdb')
+
class SDBConnection(AWSQueryConnection):
"""
This class serves as a gateway to your SimpleDB region (defaults to
- us-east-1). Methods within allow access to SimpleDB
+ us-east-1). Methods within allow access to SimpleDB
:class:`Domain <boto.sdb.domain.Domain>` objects and their associated
:class:`Item <boto.sdb.item.Item>` objects.
-
+
.. tip::
While you may instantiate this class directly, it may be easier to
go through :py:func:`boto.connect_sdb`.
@@ -91,19 +97,20 @@ def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
:py:class:`boto.connection.AWSAuthConnection`. You can avoid having
to worry about these keyword arguments by instantiating these objects
via :py:func:`boto.connect_sdb`.
-
+
:type region: :class:`boto.sdb.regioninfo.SDBRegionInfo`
- :keyword region: Explicitly specify a region. Defaults to ``us-east-1``
- if not specified. You may also specify the region in your ``boto.cfg``:
+ :keyword region: Explicitly specify a region.
+ Defaults to ``us-east-1`` if not specified. You may also
+ specify the region in your ``boto.cfg``:
.. code-block:: cfg
[SDB]
region = eu-west-1
-
"""
if not region:
- region_name = boto.config.get('SDB', 'region', self.DefaultRegionName)
+ region_name = boto.config.get('SDB', 'region',
+ self.DefaultRegionName)
for reg in boto.sdb.regions():
if reg.name == region_name:
region = reg
@@ -129,7 +136,7 @@ def set_item_cls(self, cls):
While the default item class is :py:class:`boto.sdb.item.Item`, this
default may be overridden. Use this method to change a connection's
item class.
-
+
:param object cls: The new class to set as this connection's item
class. See the default item class for inspiration as to what your
replacement should/could look like.
@@ -208,24 +215,25 @@ def _build_name_list(self, params, attribute_names):
def get_usage(self):
"""
- Returns the BoxUsage (in USD) accumulated on this specific SDBConnection
- instance.
+ Returns the BoxUsage (in USD) accumulated on this specific
+ SDBConnection instance.
.. tip:: This can be out of date, and should only be treated as a
rough estimate. Also note that this estimate only applies to the
requests made on this specific connection instance. It is by
no means an account-wide estimate.
:rtype: float
- :return: The accumulated BoxUsage of all requests made on the connection.
+ :return: The accumulated BoxUsage of all requests made on the
+ connection.
"""
return self.box_usage
def print_usage(self):
"""
Print the BoxUsage and approximate costs of all requests made on
this specific SDBConnection instance.
-
+
.. tip:: This can be out of date, and should only be treated as a
rough estimate. Also note that this estimate only applies to the
requests made on this specific connection instance. It is by
@@ -239,14 +247,14 @@ def get_domain(self, domain_name, validate=True):
"""
Retrieves a :py:class:`boto.sdb.domain.Domain` object whose name
matches ``domain_name``.
-
+
:param str domain_name: The name of the domain to retrieve
:keyword bool validate: When ``True``, check to see if the domain
actually exists. If ``False``, blindly return a
- :py:class:`Domain <boto.sdb.domain.Domain>` object with the
+ :py:class:`Domain <boto.sdb.domain.Domain>` object with the
specified name set.
- :raises:
+ :raises:
:py:class:`boto.exception.SDBResponseError` if ``validate`` is
``True`` and no match could be found.
@@ -260,12 +268,12 @@ def get_domain(self, domain_name, validate=True):
def lookup(self, domain_name, validate=True):
"""
- Lookup an existing SimpleDB domain. This differs from
+ Lookup an existing SimpleDB domain. This differs from
:py:meth:`get_domain` in that ``None`` is returned if ``validate`` is
``True`` and no match was found (instead of raising an exception).
:param str domain_name: The name of the domain to retrieve
-
+
:param bool validate: If ``True``, a ``None`` value will be returned
if the specified domain can't be found. If ``False``, a
:py:class:`Domain <boto.sdb.domain.Domain>` object will be dumbly
@@ -285,8 +293,8 @@ def get_all_domains(self, max_domains=None, next_token=None):
Returns a :py:class:`boto.resultset.ResultSet` containing
all :py:class:`boto.sdb.domain.Domain` objects associated with
this connection's Access Key ID.
-
- :keyword int max_domains: Limit the returned
+
+ :keyword int max_domains: Limit the returned
:py:class:`ResultSet <boto.resultset.ResultSet>` to the specified
number of members.
:keyword str next_token: A token string that was returned in an
@@ -314,7 +322,7 @@ def create_domain(self, domain_name):
:rtype: :class:`boto.sdb.domain.Domain` object
:return: The newly created domain
"""
- params = {'DomainName':domain_name}
+ params = {'DomainName': domain_name}
d = self.get_object('CreateDomain', params, Domain)
d.name = domain_name
return d
@@ -323,18 +331,18 @@ def get_domain_and_name(self, domain_or_name):
"""
Given a ``str`` or :class:`boto.sdb.domain.Domain`, return a
``tuple`` with the following members (in order):
-
+
* In instance of :class:`boto.sdb.domain.Domain` for the requested
domain
* The domain's name as a ``str``
-
+
:type domain_or_name: ``str`` or :class:`boto.sdb.domain.Domain`
:param domain_or_name: The domain or domain name to get the domain
and name for.
-
+
:raises: :class:`boto.exception.SDBResponseError` when an invalid
domain name is specified.
-
+
:rtype: tuple
:return: A ``tuple`` with contents outlined as per above.
"""
@@ -354,10 +362,10 @@ def delete_domain(self, domain_or_name):
:rtype: bool
:return: True if successful
-
+
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName':domain_name}
+ params = {'DomainName': domain_name}
return self.get_status('DeleteDomain', params)
def domain_metadata(self, domain_or_name):
@@ -371,7 +379,7 @@ def domain_metadata(self, domain_or_name):
:return: The newly created domain metadata object
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName':domain_name}
+ params = {'DomainName': domain_name}
d = self.get_object('DomainMetadata', params, DomainMetaData)
d.domain = domain
return d
@@ -380,45 +388,45 @@ def put_attributes(self, domain_or_name, item_name, attributes,
replace=True, expected_value=None):
"""
Store attributes for a given item in a domain.
-
+
:type domain_or_name: string or :class:`boto.sdb.domain.Domain` object.
:param domain_or_name: Either the name of a domain or a Domain object
-
+
:type item_name: string
:param item_name: The name of the item whose attributes are being
stored.
-
+
:type attribute_names: dict or dict-like object
:param attribute_names: The name/value pairs to store as attributes
-
+
:type expected_value: list
:param expected_value: If supplied, this is a list or tuple consisting
- of a single attribute name and expected value. The list can be
+ of a single attribute name and expected value. The list can be
of the form:
-
+
* ['name', 'value']
-
- In which case the call will first verify that the attribute "name"
+
+ In which case the call will first verify that the attribute "name"
of this item has a value of "value". If it does, the delete
- will proceed, otherwise a ConditionalCheckFailed error will be
+ will proceed, otherwise a ConditionalCheckFailed error will be
returned. The list can also be of the form:
-
+
* ['name', True|False]
-
- which will simply check for the existence (True) or
+
+ which will simply check for the existence (True) or
non-existence (False) of the attribute.
-
+
:type replace: bool
:param replace: Whether the attribute values passed in will replace
existing values or will be added as addition values.
Defaults to True.
-
+
:rtype: bool
:return: True if successful
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName' : domain_name,
- 'ItemName' : item_name}
+ params = {'DomainName': domain_name,
+ 'ItemName': item_name}
self._build_name_value_list(params, attributes, replace)
if expected_value:
self._build_expected_value(params, expected_value)
@@ -427,7 +435,7 @@ def put_attributes(self, domain_or_name, item_name, attributes,
def batch_put_attributes(self, domain_or_name, items, replace=True):
"""
Store attributes for multiple items in a domain.
-
+
:type domain_or_name: string or :class:`boto.sdb.domain.Domain` object.
:param domain_or_name: Either the name of a domain or a Domain object
@@ -437,17 +445,17 @@ def batch_put_attributes(self, domain_or_name, items, replace=True):
of attribute names/values, exactly the same as the
attribute_names parameter of the scalar put_attributes
call.
-
+
:type replace: bool
:param replace: Whether the attribute values passed in will replace
existing values or will be added as addition values.
Defaults to True.
-
+
:rtype: bool
:return: True if successful
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName' : domain_name}
+ params = {'DomainName': domain_name}
self._build_batch_list(params, items, replace)
return self.get_status('BatchPutAttributes', params, verb='POST')
@@ -460,18 +468,18 @@ def get_attributes(self, domain_or_name, item_name, attribute_names=None,
:param domain_or_name: Either the name of a domain or a Domain object
:type item_name: string
- :param item_name: The name of the item whose attributes are
+ :param item_name: The name of the item whose attributes are
being retrieved.
:type attribute_names: string or list of strings
:param attribute_names: An attribute name or list of attribute names.
- This parameter is optional. If not supplied, all attributes will
+ This parameter is optional. If not supplied, all attributes will
be retrieved for the item.
:type consistent_read: bool
:param consistent_read: When set to true, ensures that the most recent
data is returned.
-
+
:type item: :class:`boto.sdb.item.Item`
:keyword item: Instead of instantiating a new Item object, you may
specify one to update.
@@ -480,8 +488,8 @@ def get_attributes(self, domain_or_name, item_name, attribute_names=None,
:return: An Item with the requested attribute name/values set on it
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName' : domain_name,
- 'ItemName' : item_name}
+ params = {'DomainName': domain_name,
+ 'ItemName': item_name}
if consistent_read:
params['ConsistentRead'] = 'true'
if attribute_names:
@@ -519,34 +527,35 @@ def delete_attributes(self, domain_or_name, item_name, attr_names=None,
delete as the value. If no value is supplied,
all attribute name/values for the item will be
deleted.
-
+
:type expected_value: list
:param expected_value: If supplied, this is a list or tuple consisting
- of a single attribute name and expected value. The list can be
+ of a single attribute name and expected value. The list can be
of the form:
* ['name', 'value']
- In which case the call will first verify that the attribute "name"
+ In which case the call will first verify that the attribute "name"
of this item has a value of "value". If it does, the delete
- will proceed, otherwise a ConditionalCheckFailed error will be
+ will proceed, otherwise a ConditionalCheckFailed error will be
returned. The list can also be of the form:
* ['name', True|False]
- which will simply check for the existence (True) or
+ which will simply check for the existence (True) or
non-existence (False) of the attribute.
:rtype: bool
:return: True if successful
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName':domain_name,
- 'ItemName' : item_name}
+ params = {'DomainName': domain_name,
+ 'ItemName': item_name}
if attr_names:
if isinstance(attr_names, list):
self._build_name_list(params, attr_names)
- elif isinstance(attr_names, dict) or isinstance(attr_names, self.item_cls):
+ elif isinstance(attr_names, dict) or isinstance(attr_names,
+ self.item_cls):
self._build_name_value_list(params, attr_names)
if expected_value:
self._build_expected_value(params, expected_value)
@@ -555,26 +564,26 @@ def delete_attributes(self, domain_or_name, item_name, attr_names=None,
def batch_delete_attributes(self, domain_or_name, items):
"""
Delete multiple items in a domain.
-
+
:type domain_or_name: string or :class:`boto.sdb.domain.Domain` object.
:param domain_or_name: Either the name of a domain or a Domain object
:type items: dict or dict-like object
:param items: A dictionary-like object. The keys of the dictionary are
the item names and the values are either:
-
+
* dictionaries of attribute names/values, exactly the
same as the attribute_names parameter of the scalar
put_attributes call. The attribute name/value pairs
will only be deleted if they match the name/value
pairs passed in.
* None which means that all attributes associated
- with the item should be deleted.
+ with the item should be deleted.
:return: True if successful
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'DomainName' : domain_name}
+ params = {'DomainName': domain_name}
self._build_batch_list(params, items, False)
return self.get_status('BatchDeleteAttributes', params, verb='POST')
@@ -587,7 +596,7 @@ def select(self, domain_or_name, query='', next_token=None,
Even though the select request does not require a domain object,
a domain object must be passed into this method so the Item objects
returned can point to the appropriate domain.
-
+
:type domain_or_name: string or :class:`boto.sdb.domain.Domain` object
:param domain_or_name: Either the name of a domain or a Domain object
@@ -602,7 +611,7 @@ def select(self, domain_or_name, query='', next_token=None,
:return: An iterator containing the results.
"""
domain, domain_name = self.get_domain_and_name(domain_or_name)
- params = {'SelectExpression' : query}
+ params = {'SelectExpression': query}
if consistent_read:
params['ConsistentRead'] = 'true'
if next_token:
View
112 boto/sdb/domain.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -23,7 +23,6 @@
Represents an SDB Domain
"""
from boto.sdb.queryresultset import SelectResultSet
-import boto.compat as compat
class Domain:
@@ -59,32 +58,33 @@ def put_attributes(self, item_name, attributes,
Store attributes for a given item.
:type item_name: string
- :param item_name: The name of the item whose attributes are being stored.
+ :param item_name: The name of the item whose attributes are being
+ stored.
:type attribute_names: dict or dict-like object
:param attribute_names: The name/value pairs to store as attributes
:type expected_value: list
:param expected_value: If supplied, this is a list or tuple consisting
- of a single attribute name and expected value. The list can be
+ of a single attribute name and expected value. The list can be
of the form:
* ['name', 'value']
- In which case the call will first verify that the attribute
- "name" of this item has a value of "value". If it does, the delete
- will proceed, otherwise a ConditionalCheckFailed error will be
- returned. The list can also be of the form:
-
+ In which case the call will first verify that the attribute
+ "name" of this item has a value of "value". If it does, the
+ delete will proceed, otherwise a ConditionalCheckFailed error
+ will be returned. The list can also be of the form:
+
* ['name', True|False]
-
- which will simply check for the existence (True) or non-existence
+
+ which will simply check for the existence (True) or non-existence
(False) of the attribute.
:type replace: bool
:param replace: Whether the attribute values passed in will replace
- existing values or will be added as addition values.
- Defaults to True.
+ existing values or will be added as addition values.
+ Defaults to True.
:rtype: bool
:return: True if successful
@@ -97,16 +97,16 @@ def batch_put_attributes(self, items, replace=True):
Store attributes for multiple items.
:type items: dict or dict-like object
- :param items: A dictionary-like object. The keys of the dictionary are
- the item names and the values are themselves dictionaries
- of attribute names/values, exactly the same as the
- attribute_names parameter of the scalar put_attributes
- call.
+ :param items: A dictionary-like object. The keys of the
+ dictionary are the item names and the values are
+ themselves dictionaries of attribute names/values, exactly
+ the same as the attribute_names parameter of the scalar
+ put_attributes call.
:type replace: bool
:param replace: Whether the attribute values passed in will replace
- existing values or will be added as addition values.
- Defaults to True.
+ existing values or will be added as addition values.
+ Defaults to True.
:rtype: bool
:return: True if successful
@@ -119,15 +119,17 @@ def get_attributes(self, item_name, attribute_name=None,
Retrieve attributes for a given item.
:type item_name: string
- :param item_name: The name of the item whose attributes are being retrieved.
+ :param item_name: The name of the item whose attributes are
+ being retrieved.
:type attribute_names: string or list of strings
- :param attribute_names: An attribute name or list of attribute names. This
- parameter is optional. If not supplied, all attributes
- will be retrieved for the item.
+ :param attribute_names: An attribute name or list of attribute
+ names. This parameter is optional. If not supplied, all
+ attributes will be retrieved for the item.
:rtype: :class:`boto.sdb.item.Item`
- :return: An Item mapping type containing the requested attribute name/values
+ :return: An Item mapping type containing the requested attribute
+ name/values
"""
return self.connection.get_attributes(self, item_name, attribute_name,
consistent_read, item)
@@ -138,30 +140,32 @@ def delete_attributes(self, item_name, attributes=None,
Delete attributes from a given item.
:type item_name: string
- :param item_name: The name of the item whose attributes are being deleted.
+ :param item_name: The name of the item whose attributes are
+ being deleted.
:type attributes: dict, list or :class:`boto.sdb.item.Item`
- :param attributes: Either a list containing attribute names which will cause
- all values associated with that attribute name to be deleted or
- a dict or Item containing the attribute names and keys and list
- of values to delete as the value. If no value is supplied,
- all attribute name/values for the item will be deleted.
-
+ :param attributes: Either a list containing attribute names
+ which will cause all values associated with that attribute
+ name to be deleted or a dict or Item containing the
+ attribute names and keys and list of values to delete as
+ the value. If no value is supplied, all attribute
+ name/values for the item will be deleted.
+
:type expected_value: list
:param expected_value: If supplied, this is a list or tuple consisting
- of a single attribute name and expected value. The list can be of
+ of a single attribute name and expected value. The list can be of
the form:
* ['name', 'value']
In which case the call will first verify that the attribute "name"
of this item has a value of "value". If it does, the delete
- will proceed, otherwise a ConditionalCheckFailed error will be
+ will proceed, otherwise a ConditionalCheckFailed error will be
returned. The list can also be of the form:
* ['name', True|False]
- which will simply check for the existence (True) or
+ which will simply check for the existence (True) or
non-existence (False) of the attribute.
:rtype: bool
@@ -173,50 +177,53 @@ def delete_attributes(self, item_name, attributes=None,
def batch_delete_attributes(self, items):
"""
Delete multiple items in this domain.
-
+
:type items: dict or dict-like object
- :param items: A dictionary-like object. The keys of the dictionary are
- the item names and the values are either:
+ :param items: A dictionary-like object. The keys of the dictionary
+ are the item names and the values are either:
* dictionaries of attribute names/values, exactly the
same as the attribute_names parameter of the scalar
put_attributes call. The attribute name/value pairs
will only be deleted if they match the name/value
pairs passed in.
* None which means that all attributes associated
- with the item should be deleted.
+ with the item should be deleted.
:rtype: bool
:return: True if successful
"""
return self.connection.batch_delete_attributes(self, items)
- def select(self, query='', next_token=None, consistent_read=False, max_items=None):
+ def select(self, query='', next_token=None, consistent_read=False,
+ max_items=None):
"""
- Returns a set of Attributes for item names within domain_name that match the query.
- The query must be expressed in using the SELECT style syntax rather than the
- original SimpleDB query language.
+ Returns a set of Attributes for item names within domain_name
+ that match the query. The query must be expressed in using
+ the SELECT style syntax rather than the original SimpleDB
+ query language.
:type query: string
:param query: The SimpleDB query to be performed.
:rtype: iter
- :return: An iterator containing the results. This is actually a generator
- function that will iterate across all search results, not just the
- first page.
+ :return: An iterator containing the results. This is actually
+ a generator function that will iterate across all search
+ results, not just the first page.
"""
- return SelectResultSet(self, query, max_items=max_items, next_token=next_token,
+ return SelectResultSet(self, query, max_items=max_items,
+ next_token=next_token,
consistent_read=consistent_read)
def get_item(self, item_name, consistent_read=False):
"""
Retrieves an item from the domain, along with all of its attributes.
-
+
:param string item_name: The name of the item to retrieve.
:rtype: :class:`boto.sdb.item.Item` or ``None``
- :keyword bool consistent_read: When set to true, ensures that the most
+ :keyword bool consistent_read: When set to true, ensures that the most
recent data is returned.
- :return: The requested item, or ``None`` if there was no match found
+ :return: The requested item, or ``None`` if there was no match found
"""
item = self.get_attributes(item_name, consistent_read=consistent_read)
if item:
@@ -266,7 +273,6 @@ def delete_item(self, item):
# f.seek(0)
# return f
-
def from_xml(self, doc):
"""Load this domain based on an XML document"""
import xml.sax
@@ -315,6 +321,8 @@ def endElement(self, name, value, connection):
import sys
from xml.sax.handler import ContentHandler
+
+
class DomainDumpParser(ContentHandler):
"""
SAX parser for a domain that has been dumped
@@ -360,6 +368,8 @@ def endElement(self, name):
self.uploader.start()
from threading import Thread
+
+
class UploaderThread(Thread):
"""Uploader Thread"""
View
43 boto/sdb/item.py
@@ -14,34 +14,37 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import base64
+
class Item(dict):
"""
A ``dict`` sub-class that serves as an object representation of a
SimpleDB item. An item in SDB is similar to a row in a relational
database. Items belong to a :py:class:`Domain <boto.sdb.domain.Domain>`,
which is similar to a table in a relational database.
-
+
The keys on instances of this object correspond to attributes that are
- stored on the SDB item.
-
- .. tip:: While it is possible to instantiate this class directly, you may
- want to use the convenience methods on :py:class:`boto.sdb.domain.Domain`
- for that purpose. For example, :py:meth:`boto.sdb.domain.Domain.get_item`.
+ stored on the SDB item.
+
+ .. tip:: While it is possible to instantiate this class directly,
+ you may want to use the convenience methods on
+ :py:class:`boto.sdb.domain.Domain`
+ for that purpose. For example,
+ :py:meth:`boto.sdb.domain.Domain.get_item`.
"""
def __init__(self, domain, name='', active=False):
"""
:type domain: :py:class:`boto.sdb.domain.Domain`
:param domain: The domain that this item belongs to.
-
+
:param str name: The name of this item. This name will be used when
- querying for items using methods like
+ querying for items using methods like
:py:meth:`boto.sdb.domain.Domain.get_item`
"""
dict.__init__(self)
@@ -102,8 +105,8 @@ def endElement(self, name, value, connection):
def load(self):
"""
Loads or re-loads this item's attributes from SDB.
-
- .. warning::
+
+ .. warning::
If you have changed attribute values on an Item instance,
this method will over-write the values if they are different in
SDB. For any local attributes that don't yet exist in SDB,
@@ -114,7 +117,7 @@ def load(self):
def save(self, replace=True):
"""
Saves this item to SDB.
-
+
:param bool replace: If ``True``, delete any attributes on the remote
SDB item that have a ``None`` value on this object.
"""
@@ -134,11 +137,11 @@ def add_value(self, key, value):
attribute that has yet to be set, it will simply create an attribute
named ``key`` with your given ``value`` as its value. If you are
adding a value to an existing attribute, this method will convert the
- attribute to a list (if it isn't already) and append your new value
+ attribute to a list (if it isn't already) and append your new value
to said list.
-
+
For clarification, consider the following interactive session:
-
+
.. code-block:: python
>>> item = some_domain.get_item('some_item')
@@ -150,9 +153,9 @@ def add_value(self, key, value):
>>> item.add_value('some_attr', 2)
>>> item['some_attr']
[1, 2]
-
+
:param str key: The attribute to add a value to.
- :param object value: The value to set or append to the attribute.
+ :param object value: The value to set or append to the attribute.
"""
if key in self:
# We already have this key on the item.
@@ -170,12 +173,8 @@ def add_value(self, key, value):
def delete(self):
"""
Deletes this item in SDB.
-
+
.. note:: This local Python object remains in its current state
after deletion, this only deletes the remote item in SDB.
"""
self.domain.delete_item(self)
-
-
-
-
View
13 boto/sdb/queryresultset.py
@@ -14,11 +14,12 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+
def query_lister(domain, query='', max_items=None, attr_names=None):
more_results = True
num_results = 0
@@ -34,7 +35,8 @@ def query_lister(domain, query='', max_items=None, attr_names=None):
num_results += 1
next_token = rs.next_token
more_results = next_token != None
-
+
+
class QueryResultSet:
def __init__(self, domain=None, query='', max_items=None, attr_names=None):
@@ -44,7 +46,9 @@ def __init__(self, domain=None, query='', max_items=None, attr_names=None):
self.attr_names = attr_names
def __iter__(self):
- return query_lister(self.domain, self.query, self.max_items, self.attr_names)
+ return query_lister(self.domain, self.query, self.max_items,
+ self.attr_names)
+
def select_lister(domain, query='', max_items=None):
more_results = True
@@ -60,7 +64,8 @@ def select_lister(domain, query='', max_items=None):
num_results += 1
next_token = rs.next_token
more_results = next_token != None
-
+
+
class SelectResultSet(object):
def __init__(self, domain=None, query='', max_items=None,
View
3 boto/sdb/regioninfo.py
@@ -16,14 +16,15 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
from boto.regioninfo import RegionInfo
+
class SDBRegionInfo(RegionInfo):
def __init__(self, connection=None, name=None, endpoint=None):
View
9 boto/ses/__init__.py
@@ -15,14 +15,15 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from .connection import SESConnection
from boto.regioninfo import RegionInfo
+
def regions():
"""
Get all available regions for the SES service.
@@ -34,14 +35,15 @@ def regions():
endpoint='email.us-east-1.amazonaws.com',
connection_cls=SESConnection)]
+
def connect_to_region(region_name, **kw_params):
"""
- Given a valid region name, return a
+ Given a valid region name, return a
:class:`boto.sns.connection.SESConnection`.
:type: str
:param region_name: The name of the region to connect to.
-
+
:rtype: :class:`boto.sns.connection.SESConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
@@ -51,6 +53,7 @@ def connect_to_region(region_name, **kw_params):
return region.connect(**kw_params)
return None
+
def get_region(region_name, **kw_params):
"""
Find and return a :class:`boto.regioninfo.RegionInfo` object
View
16 boto/ses/connection.py
@@ -89,7 +89,7 @@ def _make_request(self, action, params=None):
params['Action'] = action
for k, v in params.items():
- if isinstance(v, compat.text_types): # UTF-8 encode only if it's Unicode
+ if isinstance(v, compat.text_types): # encode only if it's Unicode
params[k] = v.encode('utf-8')
response = super(SESConnection, self).make_request(
@@ -152,7 +152,8 @@ def _handle_error(self, response, body):
raise ExceptionToRaise(response.status, exc_reason, body)
- def send_email(self, source, subject, body, to_addresses, cc_addresses=None,
+ def send_email(self, source, subject, body,
+ to_addresses, cc_addresses=None,
bcc_addresses=None, format='text', reply_addresses=None,
return_path=None, text_body=None, html_body=None):
"""Composes an email message based on input data, and then immediately
@@ -191,9 +192,9 @@ def send_email(self, source, subject, body, to_addresses, cc_addresses=None,
:param return_path: The email address to which bounce notifications are
to be forwarded. If the message cannot be delivered
to the recipient, then an error message will be
- returned from the recipient's ISP; this message will
- then be forwarded to the email address specified by
- the ReturnPath parameter.
+ returned from the recipient's ISP; this message
+ will then be forwarded to the email address
+ specified by the ReturnPath parameter.
:type text_body: string
:param text_body: The text body to send with this email.
@@ -226,7 +227,7 @@ def send_email(self, source, subject, body, to_addresses, cc_addresses=None,
if text_body is not None:
params['Message.Body.Text.Data'] = text_body
- if(format not in ("text","html")):
+ if(format not in ("text", "html")):
raise ValueError("'format' argument must be 'text' or 'html'")
if(not (html_body or text_body)):
@@ -267,7 +268,8 @@ def send_raw_email(self, raw_message, source=None, destinations=None):
:param raw_message: The raw text of the message. The client is
responsible for ensuring the following:
- - Message must contain a header and a body, separated by a blank line.
+ - Message must contain a header and a body, separated by
+ a blank line.
- All required header fields must be present.
- Each part of a multipart MIME message must be formatted properly.
- MIME content types must be among those supported by Amazon SES.
View
3 boto/ses/exceptions.py
@@ -3,6 +3,7 @@
"""
from boto.exception import BotoServerError
+
class SESAddressNotVerifiedError(BotoServerError):
"""
Raised when a "Reply-To" address has not been validated in SES yet.
@@ -39,4 +40,4 @@ class SESDomainEndsWithDotError(BotoServerError):
"""
Recipient's email address' domain ends with a period/dot.
"""
- pass
+ pass
View
9 boto/sns/__init__.py
@@ -15,7 +15,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -25,6 +25,7 @@
from .connection import SNSConnection
from boto.regioninfo import RegionInfo
+
def regions():
"""
Get all available regions for the SNS service.
@@ -55,14 +56,15 @@ def regions():
connection_cls=SNSConnection),
]
+
def connect_to_region(region_name, **kw_params):
"""
- Given a valid region name, return a
+ Given a valid region name, return a
:class:`boto.sns.connection.SNSConnection`.
:type: str
:param region_name: The name of the region to connect to.
-
+
:rtype: :class:`boto.sns.connection.SNSConnection` or ``None``
:return: A connection to the given region, or None if an invalid region
name is given
@@ -72,6 +74,7 @@ def connect_to_region(region_name, **kw_params):
return region.connect(**kw_params)
return None
+
def get_region(region_name, **kw_params):
"""
Find and return a :class:`boto.regioninfo.RegionInfo` object
View
105 boto/sns/connection.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -60,7 +60,7 @@ def get_all_topics(self, next_token=None):
this method.
"""
- params = {'ContentType' : 'JSON'}
+ params = {'ContentType': 'JSON'}
if next_token:
params['NextToken'] = next_token
response = self.make_request('ListTopics', params, '/', 'GET')
@@ -71,7 +71,7 @@ def get_all_topics(self, next_token=None):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def get_topic_attributes(self, topic):
"""
Get attributes of a Topic
@@ -80,8 +80,8 @@ def get_topic_attributes(self, topic):
:param topic: The ARN of the topic.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic}
response = self.make_request('GetTopicAttributes', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -90,7 +90,7 @@ def get_topic_attributes(self, topic):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def set_topic_attributes(self, topic, attr_name, attr_value):
"""
Get attributes of a Topic
@@ -107,10 +107,10 @@ def set_topic_attributes(self, topic, attr_name, attr_value):
:param attr_value: The new value for the attribute.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'AttributeName' : attr_name,
- 'AttributeValue' : attr_value}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'AttributeName': attr_name,
+ 'AttributeValue': attr_value}
response = self.make_request('SetTopicAttributes', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -119,7 +119,7 @@ def set_topic_attributes(self, topic, attr_name, attr_value):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def add_permission(self, topic, label, account_ids, actions):
"""
Adds a statement to a topic's access control policy, granting
@@ -140,9 +140,9 @@ def add_permission(self, topic, label, account_ids, actions):
specified principal(s).
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'Label' : label}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'Label': label}
self.build_list_params(params, account_ids, 'AWSAccountId')
self.build_list_params(params, actions, 'ActionName')
response = self.make_request('AddPermission', params, '/', 'GET')
@@ -153,7 +153,7 @@ def add_permission(self, topic, label, account_ids, actions):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def remove_permission(self, topic, label):
"""
Removes a statement from a topic's access control policy.
@@ -166,9 +166,9 @@ def remove_permission(self, topic, label):
to be removed.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'Label' : label}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'Label': label}
response = self.make_request('RemovePermission', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -177,7 +177,7 @@ def remove_permission(self, topic, label):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def create_topic(self, topic):
"""
Create a new Topic.
@@ -186,8 +186,8 @@ def create_topic(self, topic):
:param topic: The name of the new topic.
"""
- params = {'ContentType' : 'JSON',
- 'Name' : topic}
+ params = {'ContentType': 'JSON',
+ 'Name': topic}
response = self.make_request('CreateTopic', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -205,8 +205,8 @@ def delete_topic(self, topic):
:param topic: The ARN of the topic
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic}
response = self.make_request('DeleteTopic', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -216,8 +216,6 @@ def delete_topic(self, topic):
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
-
def publish(self, topic, message, subject=None):
"""
Get properties of a Topic
@@ -235,9 +233,9 @@ def publish(self, topic, message, subject=None):
line of the email notifications.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'Message' : message}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'Message': message}
if subject:
params['Subject'] = subject
response = self.make_request('Publish', params, '/', 'GET')
@@ -248,7 +246,7 @@ def publish(self, topic, message, subject=None):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def subscribe(self, topic, protocol, endpoint):
"""
Subscribe to a Topic.
@@ -271,10 +269,10 @@ def subscribe(self, topic, protocol, endpoint):
* For sqs, this would be the ARN of an SQS Queue
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'Protocol' : protocol,
- 'Endpoint' : endpoint}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'Protocol': protocol,
+ 'Endpoint': endpoint}
response = self.make_request('Subscribe', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -289,9 +287,9 @@ def subscribe_sqs_queue(self, topic, queue):
Subscribe an SQS queue to a topic.
This is convenience method that handles most of the complexity involved
- in using ans SQS queue as an endpoint for an SNS topic. To achieve this
- the following operations are performed:
-
+ in using ans SQS queue as an endpoint for an SNS topic. To achieve
+ this the following operations are performed:
+
* The correct ARN is constructed for the SQS queue and that ARN is
then subscribed to the topic.
* A JSON policy document is contructed that grants permission to
@@ -300,7 +298,7 @@ def subscribe_sqs_queue(self, topic, queue):
the queue's set_attribute method. If the queue already has
a policy associated with it, this process will add a Statement to
that policy. If no policy exists, a new policy will be created.
-
+
:type topic: string
:param topic: The name of the new topic.
@@ -316,12 +314,12 @@ def subscribe_sqs_queue(self, topic, queue):
policy['Version'] = '2008-10-17'
if 'Statement' not in policy:
policy['Statement'] = []
- statement = {'Action' : 'SQS:SendMessage',
- 'Effect' : 'Allow',
+ statement = {'Action': 'SQS:SendMessage',
+ 'Effect': 'Allow',
'Principal' : {'AWS' : '*'},
- 'Resource' : q_arn,
- 'Sid' : str(uuid.uuid4()),
- 'Condition' : {'StringLike' : {'aws:SourceArn' : topic}}}
+ 'Resource': q_arn,
+ 'Sid': str(uuid.uuid4()),
+ 'Condition': {'StringLike' : {'aws:SourceArn' : topic}}}
policy['Statement'].append(statement)
queue.set_attribute('Policy', compat.json.dumps(policy))
return resp
@@ -345,9 +343,9 @@ def confirm_subscription(self, topic, token,
of the subscription.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic,
- 'Token' : token}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic,
+ 'Token': token}
if authenticate_on_unsubscribe:
params['AuthenticateOnUnsubscribe'] = 'true'
response = self.make_request('ConfirmSubscription', params, '/', 'GET')
@@ -358,7 +356,7 @@ def confirm_subscription(self, topic, token,
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def unsubscribe(self, subscription):
"""
Allows endpoint owner to delete subscription.
@@ -368,8 +366,8 @@ def unsubscribe(self, subscription):
:param subscription: The ARN of the subscription to be deleted.
"""
- params = {'ContentType' : 'JSON',
- 'SubscriptionArn' : subscription}
+ params = {'ContentType': 'JSON',
+ 'SubscriptionArn': subscription}
response = self.make_request('Unsubscribe', params, '/', 'GET')
body = response.read()
if response.status == 200:
@@ -378,7 +376,7 @@ def unsubscribe(self, subscription):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def get_all_subscriptions(self, next_token=None):
"""
Get list of all subscriptions.
@@ -388,7 +386,7 @@ def get_all_subscriptions(self, next_token=None):
this method.
"""
- params = {'ContentType' : 'JSON'}
+ params = {'ContentType': 'JSON'}
if next_token:
params['NextToken'] = next_token
response = self.make_request('ListSubscriptions', params, '/', 'GET')
@@ -399,7 +397,7 @@ def get_all_subscriptions(self, next_token=None):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
+
def get_all_subscriptions_by_topic(self, topic, next_token=None):
"""
Get list of all subscriptions to a specific topic.
@@ -413,8 +411,8 @@ def get_all_subscriptions_by_topic(self, topic, next_token=None):
this method.
"""
- params = {'ContentType' : 'JSON',
- 'TopicArn' : topic}
+ params = {'ContentType': 'JSON',
+ 'TopicArn': topic}
if next_token:
params['NextToken'] = next_token
response = self.make_request('ListSubscriptionsByTopic', params,
@@ -426,4 +424,3 @@ def get_all_subscriptions_by_topic(self, topic, next_token=None):
boto.log.error('%s %s' % (response.status, response.reason))
boto.log.error('%s' % body)
raise self.ResponseError(response.status, response.reason, body)
-
View
6 boto/sqs/__init__.py
@@ -14,18 +14,19 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
from .regioninfo import SQSRegionInfo
+
def regions():
"""
Get all available regions for the SQS service.
-
+
:rtype: list
:return: A list of :class:`boto.ec2.regioninfo.RegionInfo`
"""
@@ -45,6 +46,7 @@ def regions():
endpoint='sqs.ap-southeast-1.amazonaws.com')
]
+
def connect_to_region(region_name, **kw_params):
for region in regions():
if region.name == region_name:
View
7 boto/sqs/attributes.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -23,8 +23,9 @@
Represents an SQS Attribute Name/Value set
"""
+
class Attributes(dict):
-
+
def __init__(self, parent):
self.parent = parent
self.current_key = None
@@ -42,5 +43,3 @@ def endElement(self, name, value, connection):
self.current_value = value
else:
setattr(self, name, value)
-
-
View
10 boto/sqs/batchresults.py
@@ -15,7 +15,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -24,6 +24,7 @@
A set of results returned by SendMessageBatch.
"""
+
class ResultEntry(dict):
"""
The result (successful or unsuccessful) of a single
@@ -61,7 +62,8 @@ def endElement(self, name, value, connection):
self['error_code'] = value
elif name == 'Message':
self['error_message'] = value
-
+
+
class BatchResults(object):
"""
A container for the results of a send_message_batch request.
@@ -72,7 +74,7 @@ class BatchResults(object):
:ivar errors: A list of unsuccessful results. Each item in the
list will be an instance of :class:`ResultEntry`.
"""
-
+
def __init__(self, parent):
self.parent = parent
self.results = []
@@ -91,5 +93,3 @@ def startElement(self, name, attrs, connection):
def endElement(self, name, value, connection):
setattr(self, name, value)
-
-
View
69 boto/sqs/connection.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -73,7 +73,8 @@ def create_queue(self, queue_name, visibility_timeout=None):
of that name. This is still an expensive operation,
though, and not the preferred way to check for
the existence of a queue. See the
- :func:`boto.sqs.connection.SQSConnection.lookup` method.
+ :func:`boto.sqs.connection.SQSConnection.lookup`
+ method.
:type visibility_timeout: int
:param visibility_timeout: The default visibility timeout for all
@@ -96,7 +97,7 @@ def delete_queue(self, queue, force_deletion=False):
:type queue: A Queue object
:param queue: The SQS queue to be deleted
-
+
:type force_deletion: Boolean
:param force_deletion: Normally, SQS will not delete a queue that
contains messages. However, if the
@@ -105,7 +106,7 @@ def delete_queue(self, queue, force_deletion=False):
there are messages in the queue or not.
USE WITH CAUTION. This will delete all
messages in the queue as well.
-
+
:rtype: bool
:return: True if the command succeeded, False otherwise
"""
@@ -114,31 +115,31 @@ def delete_queue(self, queue, force_deletion=False):
def get_queue_attributes(self, queue, attribute='All'):
"""
Gets one or all attributes of a Queue
-
+
:type queue: A Queue object
:param queue: The SQS queue to be deleted
:type attribute: str
:type attribute: The specific attribute requested. If not supplied,
the default is to return all attributes.
Valid attributes are:
-
+
ApproximateNumberOfMessages|
ApproximateNumberOfMessagesNotVisible|
VisibilityTimeout|
CreatedTimestamp|
LastModifiedTimestamp|
Policy
-
+
:rtype: :class:`boto.sqs.attributes.Attributes`
:return: An Attributes object containing request value(s).
"""
- params = {'AttributeName' : attribute}
+ params = {'AttributeName': attribute}
return self.get_object('GetQueueAttributes', params,
Attributes, queue.id)
def set_queue_attribute(self, queue, attribute, value):
- params = {'Attribute.Name' : attribute, 'Attribute.Value' : value}
+ params = {'Attribute.Name': attribute, 'Attribute.Value': value}
return self.get_status('SetQueueAttributes', params, queue.id)
def receive_message(self, queue, number_messages=1,
@@ -148,11 +149,11 @@ def receive_message(self, queue, number_messages=1,
: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
@@ -163,15 +164,15 @@ def receive_message(self, queue, number_messages=1,
with response or All if you want all attributes.
The default is to return no additional attributes.
Valid values:
-
+
All|SenderId|SentTimestamp|
ApproximateReceiveCount|
ApproximateFirstReceiveTimestamp
-
+
:rtype: list
:return: A list of :class:`boto.sqs.message.Message` objects.
"""
- params = {'MaxNumberOfMessages' : number_messages}
+ params = {'MaxNumberOfMessages': number_messages}
if visibility_timeout:
params['VisibilityTimeout'] = visibility_timeout
if attributes:
@@ -186,14 +187,14 @@ def delete_message(self, queue, message):
: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