blob: e0e3997bd8018eb0770c94b0a3343c7b8f40c449 [file] [log] [blame]
Joe Gregorio695fdc12011-01-16 16:46:55 -05001# Copyright 2010 Google Inc. All Rights Reserved.
2
3"""Utilities for OAuth.
4
5Utilities for making it easier to work with OAuth 2.0
6credentials.
7"""
8
9__author__ = 'jcgregorio@google.com (Joe Gregorio)'
10
11import pickle
12
13
14class Storage(object):
15 """Store and retrieve a single credential to and from a file."""
16
17 def __init__(self, filename):
18 self.filename = filename
19
20 def get(self):
21 """Retrieve Credential from file.
22
23 Returns:
24 apiclient.oauth.Credentials
25 """
26 f = open(self.filename, 'r')
27 credentials = pickle.loads(f.read())
28 f.close()
29 credentials.set_store(self.put)
30 return credentials
31
32 def put(self, credentials):
33 """Write a pickled Credentials to file.
34
35 Args:
36 credentials: Credentials, the credentials to store.
37 """
38 f = open(self.filename, 'w')
39 f.write(pickle.dumps(credentials))
40 f.close()
41
42