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/_emerge/__init__.py | 6 +++--- pym/portage/dep.py | 4 ++-- pym/portage/locks.py | 23 ++++++++++++----------- 3 files changed, 17 insertions(+), 16 deletions(-) (limited to 'pym') diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 00ef6f705..0200ce30c 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -32,7 +32,7 @@ from portage import digraph from portage.const import NEWS_LIB_PATH import _emerge.help -import portage.xpak, commands, errno, re, socket, time, types +import portage.xpak, commands, errno, re, socket, time from portage.output import blue, bold, colorize, darkblue, darkgreen, darkred, green, \ nc_len, red, teal, turquoise, xtermTitle, \ xtermTitleReset, yellow @@ -277,8 +277,8 @@ def countdown(secs=5, doing="Starting"): # formats a size given in bytes nicely def format_size(mysize): - if type(mysize) not in [types.IntType,types.LongType]: - return str(mysize) + if isinstance(mysize, basestring): + return mysize if 0 != mysize % 1024: # Always round up to the next kB so that it doesn't show 0 kB when # some small file still needs to be fetched. diff --git a/pym/portage/dep.py b/pym/portage/dep.py index 831a8a324..04817068c 100644 --- a/pym/portage/dep.py +++ b/pym/portage/dep.py @@ -18,7 +18,7 @@ # "a? ( b? ( z ) ) -- Valid # -import re, sys, types +import re, sys import weakref from itertools import chain import portage.exception @@ -230,7 +230,7 @@ def use_reduce(deparray, uselist=[], masklist=[], matchall=0, excludeall=[]): while mydeparray: head = mydeparray.pop(0) - if type(head) == types.ListType: + if not isinstance(head, basestring): additions = use_reduce(head, uselist, masklist, matchall, excludeall) if additions: rlist.append(additions) 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