Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

generators for abstracting MWS continuation calls #1045

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 1 deletion.
  1. +35 −0 boto/mws/connection.py
  2. +1 −1  boto/mws/response.py
View
35 boto/mws/connection.py
@@ -21,6 +21,7 @@
import xml.sax
import hashlib
import base64
+import string
from boto.connection import AWSQueryConnection
from boto.mws.exception import ResponseErrorFactory
from boto.mws.response import ResponseFactory, ResponseElement
@@ -219,6 +220,7 @@ def decorator(func, quota=int(quota), restore=float(restore)):
response = getattr(boto.mws.response, action + 'Response')
else:
response = ResponseFactory(action)
+ response._action = action
def wrapper(self, *args, **kw):
kw.setdefault(accesskey, getattr(self, accesskey, None))
@@ -278,6 +280,39 @@ def post_request(self, path, params, cls, body='', headers={}, isXML=True):
xml.sax.parseString(body, h)
return obj
+ def method_for(self, name):
+ """Return the MWS API method referred to in the argument.
+ The named method can be in CamelCase or underlined_lower_case.
+ This is the complement to MWSConnection.any_call.action
+ """
+ # this looks ridiculous but it should be better than regex
+ action = '_' in name and string.capwords(name, '_') or name
+ attribs = [getattr(self, m) for m in dir(self)]
+ ismethod = lambda m: type(m) is type(self.method_for)
+ ismatch = lambda m: getattr(m, 'action', None) == action
+ method = filter(ismatch, filter(ismethod, attribs))
+ return method and method[0] or None
+
+ def iter_call(self, call, *args, **kw):
+ """Pass a call name as the first argument and a generator
+ is returned for the initial response and any continuation
+ call responses made using the NextToken.
+ """
+ method = self.method_for(call)
+ assert method, 'No call named "{0}"'.format(call)
+ return self.iter_response(method(*args, **kw))
+
+ def iter_response(self, response):
+ """Pass a call's response as the initial argument and a
+ generator is returned for the initial response and any
+ continuation call responses made using the NextToken.
+ """
+ yield response
+ more = self.method_for(response._action + 'ByNextToken')
+ while more and response._result.HasNext == 'true':
+ response = more(NextToken=response._result.NextToken)
+ yield response
+
@boolean_arguments('PurgeAndReplace')
@http_body('FeedContent')
@structured_lists('MarketplaceIdList.Id')
View
2  boto/mws/response.py
@@ -287,7 +287,7 @@ class CancelReportRequestsResult(RequestReportResult):
class GetReportListResult(ResponseElement):
- ReportInfo = Element()
+ ReportInfo = ElementList()
class GetReportListByNextTokenResult(GetReportListResult):
Something went wrong with that request. Please try again.