当前位置: 首页>>代码示例>>Python>>正文


Python __builtin__.isinstance方法代码示例

本文整理汇总了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()' 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:unittest.py

示例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 
开发者ID:aradi,项目名称:fypp,代码行数:19,代码来源:fypp.py

示例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) 
开发者ID:aradi,项目名称:fypp,代码行数:21,代码来源:fypp.py

示例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 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:30,代码来源:misc.py

示例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: 
开发者ID:mortcanty,项目名称:earthengine,代码行数:14,代码来源:py21compat.py

示例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 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:6,代码来源:compatibility.py

示例7: reversed

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import isinstance [as 别名]
def reversed(data):
            if not isinstance(data, list):
                data = list(data)
            return data[::-1] 
开发者ID:Yukinoshita47,项目名称:Yuki-Chan-The-Auto-Pentest,代码行数:6,代码来源:compatibility.py

示例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 
开发者ID:alfa-addon,项目名称:addon,代码行数:31,代码来源:misc.py

示例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 
开发者ID:ip-tools,项目名称:patzilla,代码行数:12,代码来源:parser.py

示例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 
开发者ID:ip-tools,项目名称:patzilla,代码行数:35,代码来源:parser.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:11,代码来源:unittest.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:7,代码来源:unittest.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:11,代码来源:unittest.py

示例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 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:43,代码来源:unittest.py

示例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()) 
开发者ID:aradi,项目名称:fypp,代码行数:17,代码来源:fypp.py


注:本文中的__builtin__.isinstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。