blob: 052a91bac20520c887b55b93b90ab3d08125514a [file] [log] [blame]
Joe Gregorio9b57dd32011-02-17 15:53:50 -05001# Copyright 2010 Google Inc. All Rights Reserved.
2
3"""Utilities for OAuth.
4
5Utilities for making it easier to work with OAuth 1.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 try:
27 f = open(self._filename, 'r')
28 credentials = pickle.loads(f.read())
29 f.close()
30 except:
31 credentials = None
32
33 return credentials
34
35 def put(self, credentials):
36 """Write a pickled Credentials to file.
37
38 Args:
39 credentials: Credentials, the credentials to store.
40 """
41 f = open(self._filename, 'w')
42 f.write(pickle.dumps(credentials))
43 f.close()