Updated packages and code to python3. Won't work with python 2
[twitter-api-cdsw] / tweepy / parsers.py
index 31e002204565e3484e3c959164ff5b16804b0a48..bccb0322c5257b64ad978d4e1fb1cd0584a63fcb 100644 (file)
@@ -2,6 +2,8 @@
 # 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
@@ -51,10 +53,12 @@ class JSONParser(Parser):
         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
 
@@ -74,10 +78,12 @@ class ModelParser(JSONParser):
 
     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):
@@ -94,4 +100,3 @@ class ModelParser(JSONParser):
             return result, cursors
         else:
             return result
-

Benjamin Mako Hill || Want to submit a patch?