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

Unified Diff: third_party/oauth2client/locked_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/keyring_storage.py ('k') | third_party/oauth2client/multistore_file.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/oauth2client/locked_file.py
diff --git a/third_party/oauth2client/locked_file.py b/third_party/oauth2client/locked_file.py
index fa2c6c1c761245abdb7c32f71e37a74772c8215e..858b702819e0c998be576d83e0ff5e8fd6718936 100644
--- a/third_party/oauth2client/locked_file.py
+++ b/third_party/oauth2client/locked_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.
@@ -17,20 +17,16 @@
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('Acquired filename with rb mode')
+ print 'Aquired filename with rb mode'
f.unlock_and_close()
-
"""
-
-from __future__ import print_function
__author__ = 'cache@google.com (David T McWherter)'
@@ -74,7 +70,6 @@
self._mode = mode
self._fallback_mode = fallback_mode
self._fh = None
- self._lock_fd = None
def is_locked(self):
"""Was the file locked."""
@@ -127,7 +122,7 @@
validate_file(self._filename)
try:
self._fh = open(self._filename, self._mode)
- except IOError as e:
+ except IOError, 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)
@@ -142,12 +137,12 @@
self._locked = True
break
- except OSError as e:
+ except OSError, 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()
@@ -197,9 +192,9 @@
validate_file(self._filename)
try:
self._fh = open(self._filename, self._mode)
- except IOError as e:
+ except IOError, e:
# If we can't access with _mode, try _fallback_mode and don't lock.
- if e.errno in (errno.EPERM, errno.EACCES):
+ if e.errno == errno.EACCES:
self._fh = open(self._filename, self._fallback_mode)
return
@@ -209,16 +204,16 @@
fcntl.lockf(self._fh.fileno(), fcntl.LOCK_EX)
self._locked = True
return
- except IOError as e:
+ except IOError, e:
# If not retrying, then just pass on the error.
if timeout == 0:
- raise
+ raise e
if e.errno != errno.EACCES:
- raise
+ raise e
# 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)
@@ -272,7 +267,7 @@
validate_file(self._filename)
try:
self._fh = open(self._filename, self._mode)
- except IOError as e:
+ except IOError, 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)
@@ -289,9 +284,9 @@
pywintypes.OVERLAPPED())
self._locked = True
return
- except pywintypes.error as e:
+ except pywintypes.error, e:
if timeout == 0:
- raise
+ raise e
# If the error is not that the file is already in use, raise.
if e[0] != _Win32Opener.FILE_IN_USE_ERROR:
@@ -313,7 +308,7 @@
try:
hfile = win32file._get_osfhandle(self._fh.fileno())
win32file.UnlockFileEx(hfile, 0, -0x10000, pywintypes.OVERLAPPED())
- except pywintypes.error as e:
+ except pywintypes.error, e:
if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR:
raise
self._locked = False
@@ -375,4 +370,4 @@
def unlock_and_close(self):
"""Unlock and close a file."""
- self._opener.unlock_and_close()
+ self._opener.unlock_and_close()
« no previous file with comments | « third_party/oauth2client/keyring_storage.py ('k') | third_party/oauth2client/multistore_file.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698