mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
Implement data persistence
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user