PageRenderTime 20ms CodeModel.GetById 8ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/boto-2.5.2/boto/ecs/__init__.py

#
Python | 90 lines | 40 code | 10 blank | 40 comment | 3 complexity | 28e7befdf10c7d0f154e0577b094863f MD5 | raw file
 1# Copyright (c) 2010 Chris Moyer http://coredumped.org/
 2#
 3# Permission is hereby granted, free of charge, to any person obtaining a
 4# copy of this software and associated documentation files (the
 5# "Software"), to deal in the Software without restriction, including
 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
 8# persons to whom the Software is furnished to do so, subject to the fol-
 9# lowing conditions:
10#
11# The above copyright notice and this permission notice shall be included
12# in all copies or substantial portions of the Software.
13#
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-
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, 
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
20# IN THE SOFTWARE.
21
22import boto
23from boto.connection import AWSQueryConnection, AWSAuthConnection
24import time
25import urllib
26import xml.sax
27from boto.ecs.item import ItemSet
28from boto import handler
29
30class ECSConnection(AWSQueryConnection):
31    """
32    ECommerce Connection
33
34    For more information on how to use this module see:
35
36    http://blog.coredumped.org/2010/09/search-for-books-on-amazon-using-boto.html
37    """
38
39    APIVersion = '2010-11-01'
40
41    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
42                 is_secure=True, port=None, proxy=None, proxy_port=None,
43                 proxy_user=None, proxy_pass=None, host='ecs.amazonaws.com',
44                 debug=0, https_connection_factory=None, path='/'):
45        AWSQueryConnection.__init__(self, aws_access_key_id, aws_secret_access_key,
46                                    is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
47                                    host, debug, https_connection_factory, path)
48
49    def _required_auth_capability(self):
50        return ['ecs']
51
52    def get_response(self, action, params, page=0, itemSet=None):
53        """
54        Utility method to handle calls to ECS and parsing of responses.
55        """
56        params['Service'] = "AWSECommerceService"
57        params['Operation'] = action
58        if page:
59            params['ItemPage'] = page
60        response = self.make_request(None, params, "/onca/xml")
61        body = response.read()
62        boto.log.debug(body)
63
64        if response.status != 200:
65            boto.log.error('%s %s' % (response.status, response.reason))
66            boto.log.error('%s' % body)
67            raise self.ResponseError(response.status, response.reason, body)
68
69        if itemSet == None:
70            rs = ItemSet(self, action, params, page)
71        else:
72            rs = itemSet
73        h = handler.XmlHandler(rs, self)
74        xml.sax.parseString(body, h)
75        return rs
76
77    #
78    # Group methods
79    #
80    
81    def item_search(self, search_index, **params):
82        """
83        Returns items that satisfy the search criteria, including one or more search 
84        indices.
85
86        For a full list of search terms, 
87        :see: http://docs.amazonwebservices.com/AWSECommerceService/2010-09-01/DG/index.html?ItemSearch.html
88        """
89        params['SearchIndex'] = search_index
90        return self.get_response('ItemSearch', params)