Restore api reference in cached entries.
authorJosh Roesslein <jroesslein@gmail.com>
Thu, 30 Jul 2009 19:26:10 +0000 (14:26 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Thu, 30 Jul 2009 19:26:10 +0000 (14:26 -0500)
tweepy/binder.py
tweepy/models.py

index 02c35d4c37b7de9746024fae7f367cbba9073282..43a43b9830568f8139b5f53008856176ffcafc5a 100644 (file)
@@ -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
index 83fb28f6f802b0d63e6ffbfe0f4c0293916644ff..d3e90ef71301abedfff4b06777ebc120a8accf95 100644 (file)
@@ -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