From 27145f418b9a860186c2a38bb1257bceb7aa7dfd Mon Sep 17 00:00:00 2001 From: Joshua Date: Sat, 30 Jan 2010 12:56:05 -0600 Subject: [PATCH] Update to Parser API. Parser.parse() now takes a APIMethod instance. --- tweepy/binder.py | 2 +- tweepy/parsers.py | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tweepy/binder.py b/tweepy/binder.py index 1d0ba66..979b82b 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -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() diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 7b9fc13..de6ce1b 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -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 -- 2.25.1