From 8ad412e223f255f7fa473028b49ac7b01cdbe008 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 19 Feb 2009 05:29:48 +0000 Subject: For compatibility with python-3.0, use isinstance() instead of type(). svn path=/main/trunk/; revision=12633 --- pym/portage/locks.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'pym/portage/locks.py') diff --git a/pym/portage/locks.py b/pym/portage/locks.py index 50fe317bf..36bc085bf 100644 --- a/pym/portage/locks.py +++ b/pym/portage/locks.py @@ -7,7 +7,7 @@ __all__ = ["lockdir", "unlockdir", "lockfile", "unlockfile", \ "hardlock_name", "hardlink_is_mine", "hardlink_lockfile", \ "unhardlink_lockfile", "hardlock_cleanup"] -import errno, os, stat, time, types +import errno, os, stat, time from portage.exception import DirectoryNotFound, FileNotFound, \ InvalidData, TryAgain, OperationNotPermitted, PermissionDenied from portage.data import portage_gid @@ -35,12 +35,12 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, if not mypath: raise InvalidData("Empty path given") - if type(mypath) == types.StringType and mypath[-1] == '/': + if isinstance(mypath, basestring) and mypath[-1] == '/': mypath = mypath[:-1] - if type(mypath) == types.FileType: + if hasattr(mypath, 'fileno'): mypath = mypath.fileno() - if type(mypath) == types.IntType: + if isinstance(mypath, int): lockfilename = mypath wantnewlockfile = 0 unlinkfile = 0 @@ -51,8 +51,8 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, unlinkfile = 1 else: lockfilename = mypath - - if type(mypath) == types.StringType: + + if isinstance(mypath, basestring): if not os.path.exists(os.path.dirname(mypath)): raise DirectoryNotFound(os.path.dirname(mypath)) preexisting = os.path.exists(lockfilename) @@ -86,7 +86,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, finally: os.umask(old_mask) - elif type(mypath) == types.IntType: + elif isinstance(mypath, int): myfd = mypath else: @@ -142,7 +142,7 @@ def lockfile(mypath, wantnewlockfile=0, unlinkfile=0, raise - if type(lockfilename) == types.StringType and \ + if isinstance(lockfilename, basestring) and \ myfd != HARDLINK_FD and _fstat_nlink(myfd) == 0: # The file was deleted on us... Keep trying to make one... os.close(myfd) @@ -187,7 +187,8 @@ def unlockfile(mytuple): return True # myfd may be None here due to myfd = mypath in lockfile() - if type(lockfilename) == types.StringType and not os.path.exists(lockfilename): + if isinstance(lockfilename, basestring) and \ + not os.path.exists(lockfilename): writemsg("lockfile does not exist '%s'\n" % lockfilename,1) if myfd is not None: os.close(myfd) @@ -199,7 +200,7 @@ def unlockfile(mytuple): unlinkfile = 1 locking_method(myfd,fcntl.LOCK_UN) except OSError: - if type(lockfilename) == types.StringType: + if isinstance(lockfilename, basestring): os.close(myfd) raise IOError("Failed to unlock file '%s'\n" % lockfilename) @@ -230,7 +231,7 @@ def unlockfile(mytuple): # why test lockfilename? because we may have been handed an # fd originally, and the caller might not like having their # open fd closed automatically on them. - if type(lockfilename) == types.StringType: + if isinstance(lockfilename, basestring): os.close(myfd) return True -- cgit v1.2.3-1-g7c22