Fixed bug with refreshing tokens in file Storage
diff --git a/oauth2client/appengine.py b/oauth2client/appengine.py
index 2811069..68d5066 100644
--- a/oauth2client/appengine.py
+++ b/oauth2client/appengine.py
@@ -229,7 +229,7 @@
self._property_name = property_name
self._cache = cache
- def get(self):
+ def locked_get(self):
"""Retrieve Credential from datastore.
Returns:
@@ -248,7 +248,7 @@
return credential
- def put(self, credentials):
+ def locked_put(self, credentials):
"""Write a Credentials to the datastore.
Args:
diff --git a/oauth2client/django_orm.py b/oauth2client/django_orm.py
index 581fe8e..5e511db 100644
--- a/oauth2client/django_orm.py
+++ b/oauth2client/django_orm.py
@@ -86,7 +86,7 @@
self.key_value = key_value
self.property_name = property_name
- def get(self):
+ def locked_get(self):
"""Retrieve Credential from datastore.
Returns:
@@ -102,7 +102,7 @@
credential.set_store(self)
return credential
- def put(self, credentials):
+ def locked_put(self, credentials):
"""Write a Credentials to the datastore.
Args:
diff --git a/oauth2client/file.py b/oauth2client/file.py
index 89140b8..60a6385 100644
--- a/oauth2client/file.py
+++ b/oauth2client/file.py
@@ -46,20 +46,32 @@
self._filename = filename
self._lock = threading.Lock()
- def get(self):
+ def acquire_lock(self):
+ """Acquires any lock necessary to access this Storage.
+
+ This lock is not reentrant."""
+ self._lock.acquire()
+
+ def release_lock(self):
+ """Release the Storage lock.
+
+ Trying to release a lock that isn't held will result in a
+ RuntimeError.
+ """
+ self._lock.release()
+
+ def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
- self._lock.acquire()
credentials = None
try:
f = open(self._filename, 'r')
content = f.read()
f.close()
except IOError:
- self._lock.release()
return credentials
# First try reading as JSON, and if that fails fall back to pickle.
@@ -74,19 +86,15 @@
credentials.set_store(self)
except:
pass
- finally:
- self._lock.release()
return credentials
- def put(self, credentials):
+ def locked_put(self, credentials):
"""Write Credentials to file.
Args:
credentials: Credentials, the credentials to store.
"""
- self._lock.acquire()
f = open(self._filename, 'w')
f.write(credentials.to_json())
f.close()
- self._lock.release()