Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: third_party/oauth2client/multistore_file.py

Issue 1094533003: Revert of Upgrade 3rd packages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/oauth2client/locked_file.py ('k') | third_party/oauth2client/old_run.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/oauth2client/multistore_file.py
diff --git a/third_party/oauth2client/multistore_file.py b/third_party/oauth2client/multistore_file.py
index 5008c00ee0324e83ec4025640825454c23126d89..ea89027f236d047851f0183464e73b1ea68de4c0 100644
--- a/third_party/oauth2client/multistore_file.py
+++ b/third_party/oauth2client/multistore_file.py
@@ -1,4 +1,4 @@
-# Copyright 2014 Google Inc. All rights reserved.
+# Copyright 2011 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,41 +19,39 @@
both in a single process and across processes.
The credential themselves are keyed off of:
-
* client_id
* user_agent
* scope
-The format of the stored data is like so::
-
- {
- 'file_version': 1,
- 'data': [
- {
- 'key': {
- 'clientId': '<client id>',
- 'userAgent': '<user agent>',
- 'scope': '<scope>'
- },
- 'credential': {
- # JSON serialized Credentials.
- }
+The format of the stored data is like so:
+{
+ 'file_version': 1,
+ 'data': [
+ {
+ 'key': {
+ 'clientId': '<client id>',
+ 'userAgent': '<user agent>',
+ 'scope': '<scope>'
+ },
+ 'credential': {
+ # JSON serialized Credentials.
}
- ]
- }
-
+ }
+ ]
+}
"""
__author__ = 'jbeda@google.com (Joe Beda)'
+import base64
import errno
-import json
import logging
import os
import threading
+from anyjson import simplejson
+from .client import Storage as BaseStorage
from .client import Credentials
-from .client import Storage as BaseStorage
from . import util
from locked_file import LockedFile
@@ -66,10 +64,12 @@
class Error(Exception):
"""Base error for this module."""
+ pass
class NewerCredentialStoreError(Error):
- """The credential store is a newer version than supported."""
+ """The credential store is a newer version that supported."""
+ pass
@util.positional(4)
@@ -193,7 +193,7 @@
This will create the file if necessary.
"""
- self._file = LockedFile(filename, 'r+', 'r')
+ self._file = LockedFile(filename, 'r+b', 'rb')
self._thread_lock = threading.Lock()
self._read_only = False
self._warn_on_readonly = warn_on_readonly
@@ -271,7 +271,7 @@
simple version of "touch" to ensure the file has been created.
"""
if not os.path.exists(self._file.filename()):
- old_umask = os.umask(0o177)
+ old_umask = os.umask(0177)
try:
open(self._file.filename(), 'a+b').close()
finally:
@@ -280,23 +280,13 @@
def _lock(self):
"""Lock the entire multistore."""
self._thread_lock.acquire()
- try:
- self._file.open_and_lock()
- except IOError as e:
- if e.errno == errno.ENOSYS:
- logger.warn('File system does not support locking the credentials '
- 'file.')
- elif e.errno == errno.ENOLCK:
- logger.warn('File system is out of resources for writing the '
- 'credentials file (is your disk full?).')
- else:
- raise
+ self._file.open_and_lock()
if not self._file.is_locked():
self._read_only = True
if self._warn_on_readonly:
logger.warn('The credentials file (%s) is not writable. Opening in '
'read-only mode. Any refreshed credentials will only be '
- 'valid for this run.', self._file.filename())
+ 'valid for this run.' % self._file.filename())
if os.path.getsize(self._file.filename()) == 0:
logger.debug('Initializing empty multistore file')
# The multistore is empty so write out an empty file.
@@ -325,7 +315,7 @@
"""
assert self._thread_lock.locked()
self._file.file_handle().seek(0)
- return json.load(self._file.file_handle())
+ return simplejson.load(self._file.file_handle())
def _locked_json_write(self, data):
"""Write a JSON serializable data structure to the multistore.
@@ -339,7 +329,7 @@
if self._read_only:
return
self._file.file_handle().seek(0)
- json.dump(data, self._file.file_handle(), sort_keys=True, indent=2, separators=(',', ': '))
+ simplejson.dump(data, self._file.file_handle(), sort_keys=True, indent=2)
self._file.file_handle().truncate()
def _refresh_data_cache(self):
@@ -397,7 +387,7 @@
raw_key = cred_entry['key']
key = util.dict_to_tuple_key(raw_key)
credential = None
- credential = Credentials.new_from_json(json.dumps(cred_entry['credential']))
+ credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
return (key, credential)
def _write(self):
@@ -410,7 +400,7 @@
raw_data['data'] = raw_creds
for (cred_key, cred) in self._data.items():
raw_key = dict(cred_key)
- raw_cred = json.loads(cred.to_json())
+ raw_cred = simplejson.loads(cred.to_json())
raw_creds.append({'key': raw_key, 'credential': raw_cred})
self._locked_json_write(raw_data)
@@ -472,4 +462,4 @@
Returns:
A Storage object that can be used to get/set this cred
"""
- return self._Storage(self, key)
+ return self._Storage(self, key)
« no previous file with comments | « third_party/oauth2client/locked_file.py ('k') | third_party/oauth2client/old_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698