From 602cdd04fa0262e8718db6bbef9d3aca346c60d4 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Thu, 30 Jul 2009 14:26:10 -0500 Subject: [PATCH] Restore api reference in cached entries. --- tweepy/binder.py | 1 + tweepy/models.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tweepy/binder.py b/tweepy/binder.py index 02c35d4..43a43b9 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -33,6 +33,7 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False, cache_result = api.cache.get(url, timeout) if cache_result: # if cache result found and not expired, return it + cache_result._api = api # restore api reference to this api instance return cache_result # Open connection diff --git a/tweepy/models.py b/tweepy/models.py index 83fb28f..d3e90ef 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -2,12 +2,22 @@ # Copyright 2009 Joshua Roesslein # See LICENSE -class Status(object): +class Model(object): + + def __getstate__(self): + # pickle + pickle = {} + for k,v in self.__dict__.items(): + if k == '_api': continue # do not pickle the api reference + pickle[k] = v + return pickle + +class Status(Model): def destroy(self): return self._api.destroy_status(id=self.id) -class User(object): +class User(Model): def timeline(self, **kargs): return self._api.user_timeline(**kargs) @@ -18,19 +28,19 @@ class User(object): def followers(self, **kargs): return self._api.followers(id=self.id, **kargs) -class DirectMessage(object): +class DirectMessage(Model): def destroy(self): return self._api.destroy_direct_message(id=self.id) -class Friendship(object): +class Friendship(Model): pass -class SavedSearch(object): +class SavedSearch(Model): pass -class SearchResult(object): +class SearchResult(Model): pass -- 2.25.1