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


Python types.ClassType方法代码示例

本文整理汇总了Python中types.ClassType方法的典型用法代码示例。如果您正苦于以下问题:Python types.ClassType方法的具体用法?Python types.ClassType怎么用?Python types.ClassType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types的用法示例。


在下文中一共展示了types.ClassType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handler_for_name

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def handler_for_name(fq_name):
  """Resolves and instantiates handler by fully qualified name.

  First resolves the name using for_name call. Then if it resolves to a class,
  instantiates a class, if it resolves to a method - instantiates the class and
  binds method to the instance.

  Args:
    fq_name: fully qualified name of something to find.

  Returns:
    handler instance which is ready to be called.
  """
  resolved_name = for_name(fq_name)
  if isinstance(resolved_name, (type, types.ClassType)):
    # create new instance if this is type
    return resolved_name()
  elif isinstance(resolved_name, types.MethodType):
    # bind the method
    return getattr(resolved_name.im_class(), resolved_name.__name__)
  else:
    return resolved_name 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:util.py

示例2: async_raise

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def async_raise(tid, exctype):
    """raises the exception, performs cleanup if needed.

    tid is the value given by thread.get_ident() (an integer).
    Raise SystemExit to kill a thread."""
    if not isinstance(exctype, (types.ClassType, type)):
        raise TypeError("Only types can be raised (not instances)")
    if not isinstance(tid, int):
        raise TypeError("tid must be an integer")
    res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))
    if res == 0:
        raise ValueError("invalid thread id")
    elif res != 1:
        # """if it returns a number greater than one, you're in trouble, 
        # and you should call it again with exc=NULL to revert the effect"""
        ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
        raise SystemError("PyThreadState_SetAsyncExc failed") 
开发者ID:linuxscout,项目名称:mishkal,代码行数:19,代码来源:killthread.py

示例3: runTests

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def runTests(self):
        if self.catchbreak:
            installHandler()
        if self.testRunner is None:
            self.testRunner = runner.TextTestRunner
        if isinstance(self.testRunner, (type, types.ClassType)):
            try:
                testRunner = self.testRunner(verbosity=self.verbosity,
                                             failfast=self.failfast,
                                             buffer=self.buffer)
            except TypeError:
                # didn't accept the verbosity, buffer or failfast arguments
                testRunner = self.testRunner()
        else:
            # it is assumed to be a TestRunner instance
            testRunner = self.testRunner
        self.result = testRunner.run(self.test)
        if self.exit:
            sys.exit(not self.result.wasSuccessful()) 
开发者ID:glmcdona,项目名称:meddle,代码行数:21,代码来源:main.py

示例4: __get_result

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def __get_result(self):
        if self._exception:
            if isinstance(self._exception, types.InstanceType):
                # The exception is an instance of an old-style class, which
                # means type(self._exception) returns types.ClassType instead
                # of the exception's actual class type.
                exception_type = self._exception.__class__
            else:
                exception_type = type(self._exception)
            raise exception_type, self._exception, self._traceback
        else:
            return self._result 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:_base.py

示例5: __new__

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def __new__(cls, name, bases, dct):
        if '__slots__' in dct:
            dct['__getstate__'] = cls._create_getstate(dct['__slots__'])
            dct['__setstate__'] = cls._create_setstate(dct['__slots__'])
        if _use_slots:
            return type.__new__(cls, name, bases + (object,), dct)
        else:
            if '__slots__' in dct:
                del dct['__slots__']
            return types.ClassType.__new__(types.ClassType, name, bases, dct) 
开发者ID:ladybug-tools,项目名称:honeybee,代码行数:12,代码来源:euclid.py

示例6: register

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def register(cls, subclass):
        """Register a virtual subclass of an ABC."""
        if not isinstance(subclass, (type, types.ClassType)):
            raise TypeError("Can only register classes")
        if issubclass(subclass, cls):
            return  # Already a subclass
        # Subtle: test for cycles *after* testing for "already a subclass";
        # this means we allow X.register(X) and interpret it as a no-op.
        if issubclass(cls, subclass):
            # This would create a cycle, which is bad for the algorithm below
            raise RuntimeError("Refusing to create an inheritance cycle")
        cls._abc_registry.add(subclass)
        ABCMeta._abc_invalidation_counter += 1  # Invalidate negative cache 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:15,代码来源:_abc.py

示例7: configure_custom

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def configure_custom(self, config):
        """Configure an object with a user-supplied factory."""
        c = config.pop('()')
        if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType:
            c = self.resolve(c)
        props = config.pop('.', None)
        # Check for valid identifiers
        kwargs = dict((k, config[k]) for k in config if valid_ident(k))
        result = c(**kwargs)
        if props:
            for name, value in props.items():
                setattr(result, name, value)
        return result 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,代码来源:dictconfig.py

示例8: configure_custom

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def configure_custom(self, config):
        """Configure an object with a user-supplied factory."""
        c = config.pop('()')
        if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType:
            c = self.resolve(c)
        props = config.pop('.', None)
        # Check for valid identifiers
        kwargs = {k: config[k] for k in config if valid_ident(k)}
        result = c(**kwargs)
        if props:
            for name, value in props.items():
                setattr(result, name, value)
        return result 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:15,代码来源:dictconfig.py

示例9: isclass

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def isclass(klass):
        return isinstance(klass, (type, types.ClassType))

    # TYPE is used in exceptions, repr(int) is different on Python 2 and 3. 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:6,代码来源:_compat.py

示例10: configure_custom

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def configure_custom(self, config):
        """Configure an object with a user-supplied factory."""
        c = config.pop('()')
        if not hasattr(c, '__call__') and hasattr(types, 'ClassType') and type(c) != types.ClassType:
            c = self.resolve(c)
        props = config.pop('.', None)
        # Check for valid identifiers
        kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
        result = c(**kwargs)
        if props:
            for name, value in props.items():
                setattr(result, name, value)
        return result 
开发者ID:glmcdona,项目名称:meddle,代码行数:15,代码来源:config.py

示例11: build_opener

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def build_opener(*handlers):
    """Create an opener object from a list of handlers.

    The opener will use several default handlers, including support
    for HTTP, FTP and when applicable, HTTPS.

    If any of the handlers passed as arguments are subclasses of the
    default handlers, the default handlers will not be used.
    """
    import types
    def isclass(obj):
        return isinstance(obj, (types.ClassType, type))

    opener = OpenerDirector()
    default_classes = [ProxyHandler, UnknownHandler, HTTPHandler,
                       HTTPDefaultErrorHandler, HTTPRedirectHandler,
                       FTPHandler, FileHandler, HTTPErrorProcessor]
    if hasattr(httplib, 'HTTPS'):
        default_classes.append(HTTPSHandler)
    skip = set()
    for klass in default_classes:
        for check in handlers:
            if isclass(check):
                if issubclass(check, klass):
                    skip.add(klass)
            elif isinstance(check, klass):
                skip.add(klass)
    for klass in skip:
        default_classes.remove(klass)

    for klass in default_classes:
        opener.add_handler(klass())

    for h in handlers:
        if isclass(h):
            h = h()
        opener.add_handler(h)
    return opener 
开发者ID:glmcdona,项目名称:meddle,代码行数:40,代码来源:urllib2.py

示例12: __str__

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def __str__(self):
        exc = self.exc
        if type(exc) is types.ClassType:
            exc = exc.__name__
        return 'problem in %s - %s: %s' % (self.filename, exc, self.value) 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:pydoc.py

示例13: isclass

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def isclass(object):
    """Return true if the object is a class.

    Class objects provide these attributes:
        __doc__         documentation string
        __module__      name of module in which this class was defined"""
    return isinstance(object, (type, types.ClassType)) 
开发者ID:glmcdona,项目名称:meddle,代码行数:9,代码来源:inspect.py

示例14: skip

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def skip(reason):
    """
    Unconditionally skip a test.
    """
    def decorator(test_item):
        if not isinstance(test_item, (type, types.ClassType)):
            @functools.wraps(test_item)
            def skip_wrapper(*args, **kwargs):
                raise SkipTest(reason)
            test_item = skip_wrapper

        test_item.__unittest_skip__ = True
        test_item.__unittest_skip_why__ = reason
        return test_item
    return decorator 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:case.py

示例15: MakeControlClass

# 需要导入模块: import types [as 别名]
# 或者: from types import ClassType [as 别名]
def MakeControlClass( controlClass, name = None ):
	"""Given a CoClass in a generated .py file, this function will return a Class
	object which can be used as an OCX control.

	This function is used when you do not want to handle any events from the OCX
	control.  If you need events, then you should derive a class from both the
	activex.Control class and the CoClass
	"""
	if name is None:
		name = controlClass.__name__
	return new_type("OCX" + name, (Control, controlClass), {}) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:activex.py


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