# Copyright 2009-2010 Joshua Roesslein
# See LICENSE for details.
+from __future__ import print_function
+
from tweepy.models import ModelFactory
from tweepy.utils import import_simplejson
from tweepy.error import TweepError
except Exception as e:
raise TweepError('Failed to parse JSON payload: %s' % e)
- needsCursors = method.parameters.has_key('cursor')
- if needsCursors and isinstance(json, dict) and 'previous_cursor' in json and 'next_cursor' in json:
- cursors = json['previous_cursor'], json['next_cursor']
- return json, cursors
+ needs_cursors = 'cursor' in method.session.params
+ if needs_cursors and isinstance(json, dict):
+ if 'previous_cursor' in json:
+ if 'next_cursor' in json:
+ cursors = json['previous_cursor'], json['next_cursor']
+ return json, cursors
else:
return json
def parse(self, method, payload):
try:
- if method.payload_type is None: return
+ if method.payload_type is None:
+ return
model = getattr(self.model_factory, method.payload_type)
except AttributeError:
- raise TweepError('No model for this payload type: %s' % method.payload_type)
+ raise TweepError('No model for this payload type: '
+ '%s' % method.payload_type)
json = JSONParser.parse(self, method, payload)
if isinstance(json, tuple):
return result, cursors
else:
return result
-