~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/sns/__init__.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2012-04-15 20:21:21 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120415202121-3fpf6q355s0xqpyu
Tags: 2.3.0-1
* New upstream release (Closes: #664478)
* Update debian/watch for Boto's move to Github.  Thanks Scott
  Moser. (Closes: #650480)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# this is here for backward compatibility
24
24
# originally, the SNSConnection class was defined here
25
25
from connection import SNSConnection
 
26
from boto.regioninfo import RegionInfo
 
27
 
 
28
def regions():
 
29
    """
 
30
    Get all available regions for the SNS service.
 
31
 
 
32
    :rtype: list
 
33
    :return: A list of :class:`boto.regioninfo.RegionInfo` instances
 
34
    """
 
35
    return [RegionInfo(name='us-east-1',
 
36
                       endpoint='sns.us-east-1.amazonaws.com',
 
37
                       connection_cls=SNSConnection),
 
38
            RegionInfo(name='eu-west-1',
 
39
                       endpoint='sns.eu-west-1.amazonaws.com',
 
40
                       connection_cls=SNSConnection),
 
41
            RegionInfo(name='us-west-1',
 
42
                       endpoint='sns.us-west-1.amazonaws.com',
 
43
                       connection_cls=SNSConnection),
 
44
            RegionInfo(name='sa-east-1',
 
45
                       endpoint='sns.sa-east-1.amazonaws.com',
 
46
                       connection_cls=SNSConnection),
 
47
            RegionInfo(name='us-west-2',
 
48
                       endpoint='sns.us-west-2.amazonaws.com',
 
49
                       connection_cls=SNSConnection),
 
50
            RegionInfo(name='ap-northeast-1',
 
51
                       endpoint='sns.ap-northeast-1.amazonaws.com',
 
52
                       connection_cls=SNSConnection),
 
53
            RegionInfo(name='ap-southeast-1',
 
54
                       endpoint='sns.ap-southeast-1.amazonaws.com',
 
55
                       connection_cls=SNSConnection),
 
56
            ]
 
57
 
 
58
def connect_to_region(region_name, **kw_params):
 
59
    """
 
60
    Given a valid region name, return a 
 
61
    :class:`boto.sns.connection.SNSConnection`.
 
62
 
 
63
    :type: str
 
64
    :param region_name: The name of the region to connect to.
 
65
    
 
66
    :rtype: :class:`boto.sns.connection.SNSConnection` or ``None``
 
67
    :return: A connection to the given region, or None if an invalid region
 
68
             name is given
 
69
    """
 
70
    for region in regions():
 
71
        if region.name == region_name:
 
72
            return region.connect(**kw_params)
 
73
    return None
 
74
 
 
75
def get_region(region_name, **kw_params):
 
76
    """
 
77
    Find and return a :class:`boto.regioninfo.RegionInfo` object
 
78
    given a region name.
 
79
 
 
80
    :type: str
 
81
    :param: The name of the region.
 
82
 
 
83
    :rtype: :class:`boto.regioninfo.RegionInfo`
 
84
    :return: The RegionInfo object for the given region or None if
 
85
             an invalid region name is provided.
 
86
    """
 
87
    for region in regions(**kw_params):
 
88
        if region.name == region_name:
 
89
            return region
 
90
    return None