| OLD | NEW |
| 1 # Copyright 2014 Google Inc. All rights reserved. | 1 # Copyright 2014 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 114 |
| 115 def loads(s): | 115 def loads(s): |
| 116 obj = json.loads(s) | 116 obj = json.loads(s) |
| 117 return _validate_clientsecrets(obj) | 117 return _validate_clientsecrets(obj) |
| 118 | 118 |
| 119 | 119 |
| 120 def _loadfile(filename): | 120 def _loadfile(filename): |
| 121 try: | 121 try: |
| 122 with open(filename, 'r') as fp: | 122 with open(filename, 'r') as fp: |
| 123 obj = json.load(fp) | 123 obj = json.load(fp) |
| 124 except IOError: | 124 except IOError as exc: |
| 125 raise InvalidClientSecretsError('File not found: "%s"' % filename) | 125 raise InvalidClientSecretsError('Error opening file', exc.filename, |
| 126 exc.strerror, exc.errno) |
| 126 return _validate_clientsecrets(obj) | 127 return _validate_clientsecrets(obj) |
| 127 | 128 |
| 128 | 129 |
| 129 def loadfile(filename, cache=None): | 130 def loadfile(filename, cache=None): |
| 130 """Loading of client_secrets JSON file, optionally backed by a cache. | 131 """Loading of client_secrets JSON file, optionally backed by a cache. |
| 131 | 132 |
| 132 Typical cache storage would be App Engine memcache service, | 133 Typical cache storage would be App Engine memcache service, |
| 133 but you can pass in any other cache client that implements | 134 but you can pass in any other cache client that implements |
| 134 these methods: | 135 these methods: |
| 135 | 136 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 164 if not cache: | 165 if not cache: |
| 165 return _loadfile(filename) | 166 return _loadfile(filename) |
| 166 | 167 |
| 167 obj = cache.get(filename, namespace=_SECRET_NAMESPACE) | 168 obj = cache.get(filename, namespace=_SECRET_NAMESPACE) |
| 168 if obj is None: | 169 if obj is None: |
| 169 client_type, client_info = _loadfile(filename) | 170 client_type, client_info = _loadfile(filename) |
| 170 obj = {client_type: client_info} | 171 obj = {client_type: client_info} |
| 171 cache.set(filename, obj, namespace=_SECRET_NAMESPACE) | 172 cache.set(filename, obj, namespace=_SECRET_NAMESPACE) |
| 172 | 173 |
| 173 return next(six.iteritems(obj)) | 174 return next(six.iteritems(obj)) |
| OLD | NEW |