For compatibility with python-3.0, use isinstance() instead of type().
authorZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 05:29:48 +0000 (05:29 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 19 Feb 2009 05:29:48 +0000 (05:29 -0000)
svn path=/main/trunk/; revision=12633

bin/dohtml
pym/_emerge/__init__.py
pym/portage/dep.py
pym/portage/locks.py

index 56f95bbfa0e4e0ebf251cddc50c5a722ccafe893..1c707bdfd0fcea14eed0f2907226ff8712a54050 100755 (executable)
@@ -31,7 +31,6 @@
 
 import os
 import sys
-import types
 
 def dodir(path):
        os.spawnlp(os.P_WAIT, "install", "install", "-d", path)
@@ -160,9 +159,6 @@ def main():
 
        (options, args) = parse_args()
 
-       if type(options.allowed_exts) == types.StringType:
-               options.allowed_exts = options.allowed_exts.split(",")
-
        if options.verbose:
                print "Allowed extensions:", options.allowed_exts
                print "Document prefix : '" + options.doc_prefix         + "'"
index 00ef6f705ae145e69d5a8e57c929d31c2335e762..0200ce30c9124a38101b4c7a1f855961a92e09d1 100644 (file)
@@ -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.
index 831a8a324a267414f6e63982a0193c0af1bb2dcc..04817068c0b587aa12c754f3323214a43445bc9e 100644 (file)
@@ -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)
index 50fe317bfe72c5b94e97499be481db5eb1c1e261..36bc085bf227b0efe4e00f2782b9b1c8e514ca90 100644 (file)
@@ -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