Implement data persistence

This commit is contained in:
AKFish
2013-08-21 22:25:20 +08:00
parent aa3025271c
commit b71329e560
+24
View File
@@ -24,10 +24,13 @@
# #
################################################################################
from __future__ import with_statement
import datetime
import GithubException
import pickle
class _NotSetType:
def __repr__(self):
@@ -96,6 +99,27 @@ class GithubObject(object):
else:
return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ")
def save(self, file_name):
'''
Save instance to a file
:param file_name: the full path of target file
'''
with open(file_name, 'wb') as f:
pickle.dump(self, f)
@classmethod
def load(cls, file_name):
'''
Load saved instance from file
:param file_name: the full path to saved file
:rtype: saved instance. The type of loaded instance remains its orginal one and will not be affected by from which derived class the method is called.
'''
with open(file_name, 'rb') as f:
return pickle.load(f)
class NonCompletableGithubObject(GithubObject):
def _completeIfNeeded(self):