Commit 27145f41 authored by Joshua's avatar Joshua
Browse files

Update to Parser API. Parser.parse() now takes a APIMethod instance.

parent c48d352a
......@@ -163,7 +163,7 @@ def bind_api(**config):
raise TweepError(error_msg)
# Parse the response payload
result = self.api.parser.parse(self.api, self.payload_type, self.payload_list, resp.read())
result = self.api.parser.parse(self, resp.read())
conn.close()
......
......@@ -8,7 +8,7 @@ from tweepy.utils import import_simplejson
class Parser(object):
def parse(self, api, payload_type, payload_list, payload):
def parse(self, method, payload):
"""
Parse the response payload and return the result.
Returns a tuple that contains the result data and the cursors
......@@ -24,7 +24,7 @@ class JSONParser(Parser):
def __init__(self):
self.json_lib = import_simplejson()
def parse(self, api, payload_type, payload_list, payload):
def parse(self, method, payload):
try:
json = self.json_lib.loads(payload)
except Exception, e:
......@@ -43,23 +43,23 @@ class ModelParser(JSONParser):
JSONParser.__init__(self)
self.model_factory = model_factory or ModelFactory
def parse(self, api, payload_type, payload_list, payload):
def parse(self, method, payload):
try:
if payload_type is None: return
model = getattr(self.model_factory, payload_type)
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)
json = JSONParser.parse(self, api, payload_type, payload_list, payload)
json = JSONParser.parse(self, method, payload)
if isinstance(json, tuple):
json, cursors = json
else:
cursors = None
if payload_list:
result = model.parse_list(api, json)
if method.payload_list:
result = model.parse_list(method.api, json)
else:
result = model.parse(api, json)
result = model.parse(method.api, json)
if cursors:
return result, cursors
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment