PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Python | 90 lines | 40 code | 10 blank | 40 comment | 4 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. import boto
  22. from boto.connection import AWSQueryConnection, AWSAuthConnection
  23. import time
  24. import urllib
  25. import xml.sax
  26. from boto.ecs.item import ItemSet
  27. from boto import handler
  28. class ECSConnection(AWSQueryConnection):
  29. """
  30. ECommerce Connection
  31. For more information on how to use this module see:
  32. http://blog.coredumped.org/2010/09/search-for-books-on-amazon-using-boto.html
  33. """
  34. APIVersion = '2010-11-01'
  35. def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
  36. is_secure=True, port=None, proxy=None, proxy_port=None,
  37. proxy_user=None, proxy_pass=None, host='ecs.amazonaws.com',
  38. debug=0, https_connection_factory=None, path='/'):
  39. AWSQueryConnection.__init__(self, aws_access_key_id, aws_secret_access_key,
  40. is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
  41. host, debug, https_connection_factory, path)
  42. def _required_auth_capability(self):
  43. return ['ecs']
  44. def get_response(self, action, params, page=0, itemSet=None):
  45. """
  46. Utility method to handle calls to ECS and parsing of responses.
  47. """
  48. params['Service'] = "AWSECommerceService"
  49. params['Operation'] = action
  50. if page:
  51. params['ItemPage'] = page
  52. response = self.make_request(None, params, "/onca/xml")
  53. body = response.read()
  54. boto.log.debug(body)
  55. if response.status != 200:
  56. boto.log.error('%s %s' % (response.status, response.reason))
  57. boto.log.error('%s' % body)
  58. raise self.ResponseError(response.status, response.reason, body)
  59. if itemSet == None:
  60. rs = ItemSet(self, action, params, page)
  61. else:
  62. rs = itemSet
  63. h = handler.XmlHandler(rs, self)
  64. xml.sax.parseString(body, h)
  65. return rs
  66. #
  67. # Group methods
  68. #
  69. def item_search(self, search_index, **params):
  70. """
  71. Returns items that satisfy the search criteria, including one or more search
  72. indices.
  73. For a full list of search terms,
  74. :see: http://docs.amazonwebservices.com/AWSECommerceService/2010-09-01/DG/index.html?ItemSearch.html
  75. """
  76. params['SearchIndex'] = search_index
  77. return self.get_response('ItemSearch', params)