本文整理匯總了Python中__builtin__.isinstance方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.isinstance方法的具體用法?Python __builtin__.isinstance怎麽用?Python __builtin__.isinstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.isinstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: isinstance
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def isinstance(obj, clsinfo):
import __builtin__
if type(clsinfo) in (tuple, list):
for cls in clsinfo:
if cls is type: cls = types.ClassType
if __builtin__.isinstance(obj, cls):
return 1
return 0
else: return __builtin__.isinstance(obj, clsinfo)
##############################################################################
# Test framework core
##############################################################################
# All classes defined herein are 'new-style' classes, allowing use of 'super()'
示例2: _get_callable_argspec_py2
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def _get_callable_argspec_py2(func):
argspec = inspect.getargspec(func)
varpos = argspec.varargs
varkw = argspec.keywords
args = argspec.args
tuplearg = False
for elem in args:
tuplearg = tuplearg or isinstance(elem, list)
if tuplearg:
msg = 'tuple argument(s) found'
raise FyppFatalError(msg)
defaults = {}
if argspec.defaults is not None:
for ind, default in enumerate(argspec.defaults):
iarg = len(args) - len(argspec.defaults) + ind
defaults[args[iarg]] = default
return args, defaults, varpos, varkw
示例3: _formatted_exception
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def _formatted_exception(exc):
error_header_formstr = '{file}:{line}: '
error_body_formstr = 'error: {errormsg} [{errorclass}]'
if not isinstance(exc, FyppError):
return error_body_formstr.format(
errormsg=str(exc), errorclass=exc.__class__.__name__)
out = []
if exc.fname is not None:
if exc.span[1] > exc.span[0] + 1:
line = '{0}-{1}'.format(exc.span[0] + 1, exc.span[1])
else:
line = '{0}'.format(exc.span[0] + 1)
out.append(error_header_formstr.format(file=exc.fname, line=line))
out.append(error_body_formstr.format(errormsg=exc.msg,
errorclass=exc.__class__.__name__))
if exc.cause is not None:
out.append('\n' + _formatted_exception(exc.cause))
out.append('\n')
return ''.join(out)
示例4: pow
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def pow(x, y, z=_SENTINEL):
"""
pow(x, y[, z]) -> number
With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
"""
# Handle newints
if isinstance(x, newint):
x = long(x)
if isinstance(y, newint):
y = long(y)
if isinstance(z, newint):
z = long(z)
try:
if z == _SENTINEL:
return _builtin_pow(x, y)
else:
return _builtin_pow(x, y, z)
except ValueError:
if z == _SENTINEL:
return _builtin_pow(x+0j, y)
else:
return _builtin_pow(x+0j, y, z)
# ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
# callable = __builtin__.callable
示例5: isinstance
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def isinstance(obj, t):
if not __builtin__.isinstance(t, type(())):
# t is not a tuple
return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
else:
# t is a tuple
for typ in t:
if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
return True
return False
# vim:set ts=4 sw=4 sts=4 expandtab:
示例6: isinstance20
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def isinstance20(a, typea):
if type(typea) != type(type):
raise TypeError("TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types")
return type(typea) != typea
示例7: reversed
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def reversed(data):
if not isinstance(data, list):
data = list(data)
return data[::-1]
示例8: pow
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def pow(x, y, z=_SENTINEL):
"""
pow(x, y[, z]) -> number
With two arguments, equivalent to x**y. With three arguments,
equivalent to (x**y) % z, but may be more efficient (e.g. for ints).
"""
# Handle newints
if isinstance(x, newint):
x = long(x)
if isinstance(y, newint):
y = long(y)
if isinstance(z, newint):
z = long(z)
try:
if z == _SENTINEL:
return _builtin_pow(x, y)
else:
return _builtin_pow(x, y, z)
except ValueError:
if z == _SENTINEL:
return _builtin_pow(x+0j, y)
else:
return _builtin_pow(x+0j, y, z)
# ``future`` doesn't support Py3.0/3.1. If we ever did, we'd add this:
# callable = __builtin__.callable
示例9: __getitem__
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def __getitem__(self, k):
if isinstance(k, int):
try:
return self.modifiers[k]
except:
return None
for m in self.modifiers:
if (str(m.type) == k or m.type.value == k):
return m
return None
示例10: getResultSetId
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def getResultSetId(self, top=None):
if (
fullResultSetNameCheck == 0 or
self.boolean.value in ['not', 'prox']
):
return ""
if top is None:
topLevel = 1
top = self
else:
topLevel = 0
# Iterate over operands and build a list
rsList = []
if isinstance(self.leftOperand, Triple):
rsList.extend(self.leftOperand.getResultSetId(top))
else:
rsList.append(self.leftOperand.getResultSetId(top))
if isinstance(self.rightOperand, Triple):
rsList.extend(self.rightOperand.getResultSetId(top))
else:
rsList.append(self.rightOperand.getResultSetId(top))
if topLevel == 1:
# Check all elements are the same
# if so we're a fubar form of present
if (len(rsList) == rsList.count(rsList[0])):
return rsList[0]
else:
return ""
else:
return rsList
示例11: addTest
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def addTest(self, test):
# sanity checks
if not callable(test):
raise TypeError("the test to add must be callable")
if (isinstance(test, (type, types.ClassType)) and
issubclass(test, (TestCase, TestSuite))):
raise TypeError("TestCases and TestSuites must be instantiated "
"before passing them to addTest()")
self._tests.append(test)
示例12: addTests
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def addTests(self, tests):
if isinstance(tests, basestring):
raise TypeError("tests must be an iterable of tests, not a string")
for test in tests:
self.addTest(test)
示例13: loadTestsFromModule
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def loadTestsFromModule(self, module):
"""Return a suite of all tests cases contained in the given module"""
tests = []
for name in dir(module):
obj = getattr(module, name)
if (isinstance(obj, (type, types.ClassType)) and
issubclass(obj, TestCase)):
tests.append(self.loadTestsFromTestCase(obj))
return self.suiteClass(tests)
示例14: loadTestsFromName
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def loadTestsFromName(self, name, module=None):
"""Return a suite of all tests cases given a string specifier.
The name may resolve either to a module, a test case class, a
test method within a test case class, or a callable object which
returns a TestCase or TestSuite instance.
The method optionally resolves the names relative to a given module.
"""
parts = name.split('.')
if module is None:
parts_copy = parts[:]
while parts_copy:
try:
module = __import__('.'.join(parts_copy))
break
except ImportError:
del parts_copy[-1]
if not parts_copy: raise
parts = parts[1:]
obj = module
for part in parts:
parent, obj = obj, getattr(obj, part)
if type(obj) == types.ModuleType:
return self.loadTestsFromModule(obj)
elif (isinstance(obj, (type, types.ClassType)) and
issubclass(obj, TestCase)):
return self.loadTestsFromTestCase(obj)
elif type(obj) == types.UnboundMethodType:
return parent(obj.__name__)
elif isinstance(obj, TestSuite):
return obj
elif callable(obj):
test = obj()
if not isinstance(test, (TestCase, TestSuite)):
raise ValueError, \
"calling %s returned %s, not a test" % (obj,test)
return test
else:
raise ValueError, "don't know how to make test from: %s" % obj
示例15: parsefile
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import isinstance [as 別名]
def parsefile(self, fobj):
'''Parses file or a file like object.
Args:
fobj (str or file): Name of a file or a file like object.
'''
if isinstance(fobj, str):
if fobj == STDIN:
self._includefile(None, sys.stdin, STDIN, os.getcwd())
else:
inpfp = _open_input_file(fobj, self._encoding)
self._includefile(None, inpfp, fobj, os.path.dirname(fobj))
inpfp.close()
else:
self._includefile(None, fobj, FILEOBJ, os.getcwd())