OLD | NEW |
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 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 # |
11 # The above copyright notice and this permission notice shall be included | 11 # The above copyright notice and this permission notice shall be included |
12 # in all copies or substantial portions of the Software. | 12 # in all copies or substantial portions of the Software. |
13 # | 13 # |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
20 # IN THE SOFTWARE. | 20 # IN THE SOFTWARE. |
21 | 21 |
22 import xml.sax | 22 import xml.sax |
23 import threading | 23 import threading |
| 24 import boto |
24 from boto import handler | 25 from boto import handler |
25 from boto.connection import AWSQueryConnection | 26 from boto.connection import AWSQueryConnection |
26 from boto.sdb.domain import Domain, DomainMetaData | 27 from boto.sdb.domain import Domain, DomainMetaData |
27 from boto.sdb.item import Item | 28 from boto.sdb.item import Item |
28 from boto.sdb.regioninfo import SDBRegionInfo | 29 from boto.sdb.regioninfo import SDBRegionInfo |
29 from boto.exception import SDBResponseError | 30 from boto.exception import SDBResponseError |
30 | 31 |
31 class ItemThread(threading.Thread): | 32 class ItemThread(threading.Thread): |
32 """ | 33 """ |
33 A threaded :class:`Item <boto.sdb.item.Item>` retriever utility class. | 34 A threaded :class:`Item <boto.sdb.item.Item>` retriever utility class. |
34 Retrieved :class:`Item <boto.sdb.item.Item>` objects are stored in the | 35 Retrieved :class:`Item <boto.sdb.item.Item>` objects are stored in the |
35 ``items`` instance variable after | 36 ``items`` instance variable after :py:meth:`run() <run>` is called. |
36 :py:meth:`run() <run>` is called. | |
37 | 37 |
38 .. tip:: | 38 .. tip:: The item retrieval will not start until |
39 The item retrieval will not start until the | 39 the :func:`run() <boto.sdb.connection.ItemThread.run>` method is called. |
40 :func:`run() <boto.sdb.connection.ItemThread.run>` method is called. | |
41 """ | 40 """ |
42 def __init__(self, name, domain_name, item_names): | 41 def __init__(self, name, domain_name, item_names): |
43 """ | 42 """ |
44 :param str name: A thread name. Used for identification. | 43 :param str name: A thread name. Used for identification. |
45 :param str domain_name: The name of a SimpleDB | 44 :param str domain_name: The name of a SimpleDB |
46 :class:`Domain <boto.sdb.domain.Domain>` | 45 :class:`Domain <boto.sdb.domain.Domain>` |
47 :type item_names: string or list of strings | 46 :type item_names: string or list of strings |
48 :param item_names: The name(s) of the items to retrieve from the specifi
ed | 47 :param item_names: The name(s) of the items to retrieve from the specifi
ed |
49 :class:`Domain <boto.sdb.domain.Domain>`. | 48 :class:`Domain <boto.sdb.domain.Domain>`. |
50 :ivar list items: A list of items retrieved. Starts as empty list. | 49 :ivar list items: A list of items retrieved. Starts as empty list. |
(...skipping 29 matching lines...) Expand all Loading... |
80 """ | 79 """ |
81 DefaultRegionName = 'us-east-1' | 80 DefaultRegionName = 'us-east-1' |
82 DefaultRegionEndpoint = 'sdb.amazonaws.com' | 81 DefaultRegionEndpoint = 'sdb.amazonaws.com' |
83 APIVersion = '2009-04-15' | 82 APIVersion = '2009-04-15' |
84 ResponseError = SDBResponseError | 83 ResponseError = SDBResponseError |
85 | 84 |
86 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, | 85 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, |
87 is_secure=True, port=None, proxy=None, proxy_port=None, | 86 is_secure=True, port=None, proxy=None, proxy_port=None, |
88 proxy_user=None, proxy_pass=None, debug=0, | 87 proxy_user=None, proxy_pass=None, debug=0, |
89 https_connection_factory=None, region=None, path='/', | 88 https_connection_factory=None, region=None, path='/', |
90 converter=None): | 89 converter=None, security_token=None): |
91 """ | 90 """ |
92 For any keywords that aren't documented, refer to the parent class, | 91 For any keywords that aren't documented, refer to the parent class, |
93 :py:class:`boto.connection.AWSAuthConnection`. You can avoid having | 92 :py:class:`boto.connection.AWSAuthConnection`. You can avoid having |
94 to worry about these keyword arguments by instantiating these objects | 93 to worry about these keyword arguments by instantiating these objects |
95 via :py:func:`boto.connect_sdb`. | 94 via :py:func:`boto.connect_sdb`. |
96 | 95 |
97 :type region: :class:`boto.sdb.regioninfo.SDBRegionInfo` | 96 :type region: :class:`boto.sdb.regioninfo.SDBRegionInfo` |
98 :keyword region: Explicitly specify a region. Defaults to ``us-east-1`` | 97 :keyword region: Explicitly specify a region. Defaults to ``us-east-1`` |
99 if not specified. | 98 if not specified. You may also specify the region in your ``boto.cfg
``: |
| 99 |
| 100 .. code-block:: cfg |
| 101 |
| 102 [SDB] |
| 103 region = eu-west-1 |
| 104 |
100 """ | 105 """ |
101 if not region: | 106 if not region: |
102 region = SDBRegionInfo(self, self.DefaultRegionName, | 107 region_name = boto.config.get('SDB', 'region', self.DefaultRegionNam
e) |
103 self.DefaultRegionEndpoint) | 108 for reg in boto.sdb.regions(): |
| 109 if reg.name == region_name: |
| 110 region = reg |
| 111 break |
| 112 |
104 self.region = region | 113 self.region = region |
105 AWSQueryConnection.__init__(self, aws_access_key_id, | 114 AWSQueryConnection.__init__(self, aws_access_key_id, |
106 aws_secret_access_key, | 115 aws_secret_access_key, |
107 is_secure, port, proxy, | 116 is_secure, port, proxy, |
108 proxy_port, proxy_user, proxy_pass, | 117 proxy_port, proxy_user, proxy_pass, |
109 self.region.endpoint, debug, | 118 self.region.endpoint, debug, |
110 https_connection_factory, path) | 119 https_connection_factory, path, |
| 120 security_token=security_token) |
111 self.box_usage = 0.0 | 121 self.box_usage = 0.0 |
112 self.converter = converter | 122 self.converter = converter |
113 self.item_cls = Item | 123 self.item_cls = Item |
114 | 124 |
115 def _required_auth_capability(self): | 125 def _required_auth_capability(self): |
116 return ['sdb'] | 126 return ['sdb'] |
117 | 127 |
118 def set_item_cls(self, cls): | 128 def set_item_cls(self, cls): |
119 """ | 129 """ |
120 While the default item class is :py:class:`boto.sdb.item.Item`, this | 130 While the default item class is :py:class:`boto.sdb.item.Item`, this |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 if consistent_read: | 608 if consistent_read: |
599 params['ConsistentRead'] = 'true' | 609 params['ConsistentRead'] = 'true' |
600 if next_token: | 610 if next_token: |
601 params['NextToken'] = next_token | 611 params['NextToken'] = next_token |
602 try: | 612 try: |
603 return self.get_list('Select', params, [('Item', self.item_cls)], | 613 return self.get_list('Select', params, [('Item', self.item_cls)], |
604 parent=domain) | 614 parent=domain) |
605 except SDBResponseError, e: | 615 except SDBResponseError, e: |
606 e.body = "Query: %s\n%s" % (query, e.body) | 616 e.body = "Query: %s\n%s" % (query, e.body) |
607 raise e | 617 raise e |
OLD | NEW |