| Index: appengine/chromium_build_logs/third_party/oauth2client/locked_file.py
|
| diff --git a/appengine/chromium_rietveld/third_party/oauth2client/locked_file.py b/appengine/chromium_build_logs/third_party/oauth2client/locked_file.py
|
| similarity index 88%
|
| copy from appengine/chromium_rietveld/third_party/oauth2client/locked_file.py
|
| copy to appengine/chromium_build_logs/third_party/oauth2client/locked_file.py
|
| index 26f783e3f12b980d888a41b3f52f56502a607439..af92398edd951aa22a858708cc09fa891291ede9 100644
|
| --- a/appengine/chromium_rietveld/third_party/oauth2client/locked_file.py
|
| +++ b/appengine/chromium_build_logs/third_party/oauth2client/locked_file.py
|
| @@ -1,21 +1,37 @@
|
| -# Copyright 2011 Google Inc. All Rights Reserved.
|
| +# Copyright 2014 Google Inc. All rights reserved.
|
| +#
|
| +# Licensed under the Apache License, Version 2.0 (the "License");
|
| +# you may not use this file except in compliance with the License.
|
| +# You may obtain a copy of the License at
|
| +#
|
| +# http://www.apache.org/licenses/LICENSE-2.0
|
| +#
|
| +# Unless required by applicable law or agreed to in writing, software
|
| +# distributed under the License is distributed on an "AS IS" BASIS,
|
| +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| +# See the License for the specific language governing permissions and
|
| +# limitations under the License.
|
|
|
| """Locked file interface that should work on Unix and Windows pythons.
|
|
|
| This module first tries to use fcntl locking to ensure serialized access
|
| to a file, then falls back on a lock file if that is unavialable.
|
|
|
| -Usage:
|
| +Usage::
|
| +
|
| f = LockedFile('filename', 'r+b', 'rb')
|
| f.open_and_lock()
|
| if f.is_locked():
|
| - print 'Acquired filename with r+b mode'
|
| + print('Acquired filename with r+b mode')
|
| f.file_handle().write('locked data')
|
| else:
|
| - print 'Aquired filename with rb mode'
|
| + print('Acquired filename with rb mode')
|
| f.unlock_and_close()
|
| +
|
| """
|
|
|
| +from __future__ import print_function
|
| +
|
| __author__ = 'cache@google.com (David T McWherter)'
|
|
|
| import errno
|
| @@ -58,6 +74,7 @@ class _Opener(object):
|
| self._mode = mode
|
| self._fallback_mode = fallback_mode
|
| self._fh = None
|
| + self._lock_fd = None
|
|
|
| def is_locked(self):
|
| """Was the file locked."""
|
| @@ -110,7 +127,7 @@ class _PosixOpener(_Opener):
|
| validate_file(self._filename)
|
| try:
|
| self._fh = open(self._filename, self._mode)
|
| - except IOError, e:
|
| + except IOError as e:
|
| # If we can't access with _mode, try _fallback_mode and don't lock.
|
| if e.errno == errno.EACCES:
|
| self._fh = open(self._filename, self._fallback_mode)
|
| @@ -125,12 +142,12 @@ class _PosixOpener(_Opener):
|
| self._locked = True
|
| break
|
|
|
| - except OSError, e:
|
| + except OSError as e:
|
| if e.errno != errno.EEXIST:
|
| raise
|
| if (time.time() - start_time) >= timeout:
|
| - logger.warn('Could not acquire lock %s in %s seconds' % (
|
| - lock_filename, timeout))
|
| + logger.warn('Could not acquire lock %s in %s seconds',
|
| + lock_filename, timeout)
|
| # Close the file and open in fallback_mode.
|
| if self._fh:
|
| self._fh.close()
|
| @@ -180,9 +197,9 @@ try:
|
| validate_file(self._filename)
|
| try:
|
| self._fh = open(self._filename, self._mode)
|
| - except IOError, e:
|
| + except IOError as e:
|
| # If we can't access with _mode, try _fallback_mode and don't lock.
|
| - if e.errno == errno.EACCES:
|
| + if e.errno in (errno.EPERM, errno.EACCES):
|
| self._fh = open(self._filename, self._fallback_mode)
|
| return
|
|
|
| @@ -192,16 +209,16 @@ try:
|
| fcntl.lockf(self._fh.fileno(), fcntl.LOCK_EX)
|
| self._locked = True
|
| return
|
| - except IOError, e:
|
| + except IOError as e:
|
| # If not retrying, then just pass on the error.
|
| if timeout == 0:
|
| - raise e
|
| + raise
|
| if e.errno != errno.EACCES:
|
| - raise e
|
| + raise
|
| # We could not acquire the lock. Try again.
|
| if (time.time() - start_time) >= timeout:
|
| - logger.warn('Could not lock %s in %s seconds' % (
|
| - self._filename, timeout))
|
| + logger.warn('Could not lock %s in %s seconds',
|
| + self._filename, timeout)
|
| if self._fh:
|
| self._fh.close()
|
| self._fh = open(self._filename, self._fallback_mode)
|
| @@ -255,7 +272,7 @@ try:
|
| validate_file(self._filename)
|
| try:
|
| self._fh = open(self._filename, self._mode)
|
| - except IOError, e:
|
| + except IOError as e:
|
| # If we can't access with _mode, try _fallback_mode and don't lock.
|
| if e.errno == errno.EACCES:
|
| self._fh = open(self._filename, self._fallback_mode)
|
| @@ -272,9 +289,9 @@ try:
|
| pywintypes.OVERLAPPED())
|
| self._locked = True
|
| return
|
| - except pywintypes.error, e:
|
| + except pywintypes.error as e:
|
| if timeout == 0:
|
| - raise e
|
| + raise
|
|
|
| # If the error is not that the file is already in use, raise.
|
| if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
|
| @@ -296,7 +313,7 @@ try:
|
| try:
|
| hfile = win32file._get_osfhandle(self._fh.fileno())
|
| win32file.UnlockFileEx(hfile, 0, -0x10000, pywintypes.OVERLAPPED())
|
| - except pywintypes.error, e:
|
| + except pywintypes.error as e:
|
| if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
|
| raise
|
| self._locked = False
|
|
|