py3k: Use isinstance for numbers and sequences

operator.isNumberType() and .isSequenceType() go away in py3k.
This commit is contained in:
Brian Crowell 2012-10-15 21:13:49 -05:00 committed by Brian Crowell
parent eed042fae5
commit da1d715b8e

View File

@ -72,6 +72,7 @@ import os, sys
# type stuff # type stuff
from types import IntType, StringType, TupleType from types import IntType, StringType, TupleType
import collections import collections
import numbers
try: try:
UnicodeStringType = type(unicode("")) UnicodeStringType = type(unicode(""))
@ -104,8 +105,6 @@ def isImageType(t):
def isDirectory(f): def isDirectory(f):
return isStringType(f) and os.path.isdir(f) return isStringType(f) and os.path.isdir(f)
from operator import isNumberType, isSequenceType
# #
# Debug level # Debug level
@ -414,15 +413,15 @@ def _getscaleoffset(expr):
data = expr(_E(stub)).data data = expr(_E(stub)).data
try: try:
(a, b, c) = data # simplified syntax (a, b, c) = data # simplified syntax
if (a is stub and b == "__mul__" and isNumberType(c)): if (a is stub and b == "__mul__" and isinstance(c, numbers.Number)):
return c, 0.0 return c, 0.0
if (a is stub and b == "__add__" and isNumberType(c)): if (a is stub and b == "__add__" and isinstance(c, numbers.Number)):
return 1.0, c return 1.0, c
except TypeError: pass except TypeError: pass
try: try:
((a, b, c), d, e) = data # full syntax ((a, b, c), d, e) = data # full syntax
if (a is stub and b == "__mul__" and isNumberType(c) and if (a is stub and b == "__mul__" and isinstance(c, numbers.Number) and
d == "__add__" and isNumberType(e)): d == "__add__" and isinstance(e, numbers.Number)):
return c, e return c, e
except TypeError: pass except TypeError: pass
raise ValueError("illegal expression") raise ValueError("illegal expression")
@ -1122,7 +1121,7 @@ class Image:
if isinstance(lut, ImagePointHandler): if isinstance(lut, ImagePointHandler):
return lut.point(self) return lut.point(self)
if not isSequenceType(lut): if not isinstance(lut, collections.Sequence):
# if it isn't a list, it should be a function # if it isn't a list, it should be a function
if self.mode in ("I", "I;16", "F"): if self.mode in ("I", "I;16", "F"):
# check if the function can be used with point_transform # check if the function can be used with point_transform