本文整理汇总了Python中types.InstanceType方法的典型用法代码示例。如果您正苦于以下问题:Python types.InstanceType方法的具体用法?Python types.InstanceType怎么用?Python types.InstanceType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types
的用法示例。
在下文中一共展示了types.InstanceType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: formatDevicesList
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def formatDevicesList(self, devicesCount):
pack_format = '>'
i = 0
for field in self._fields_:
if (i == devicesCount + 2):
break
if type(field[1]) is types.InstanceType:
if BaseStucture in field[1].__class__.__bases__:
pack_format += str(field[1].size()) + 's'
elif 'si' == field[1]:
pack_format += 'c'
elif '<' in field[1]:
pack_format += field[1][1:]
else:
pack_format += field[1]
i += 1
return pack_format
示例2: packDevicesList
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def packDevicesList(self, devicesCount):
values = []
i = 0
for field in self._fields_:
if (i == devicesCount + 2):
break
if type(field[1]) is types.InstanceType:
if BaseStucture in field[1].__class__.__bases__:
values.append(getattr(self, field[0], 0).pack())
else:
if 'si' == field[1]:
values.append(chr(getattr(self, field[0], 0)))
else:
values.append(getattr(self, field[0], 0))
i += 1
return struct.pack(self.formatDevicesList(devicesCount), *values)
示例3: in_idle
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def in_idle():
"""
@rtype: C{boolean}
@return: true if this function is run within idle. Tkinter
programs that are run in idle should never call L{Tk.mainloop}; so
this function should be used to gate all calls to C{Tk.mainloop}.
@warning: This function works by checking C{sys.stdin}. If the
user has modified C{sys.stdin}, then it may return incorrect
results.
"""
import sys, types
return (type(sys.stdin) == types.InstanceType and \
sys.stdin.__class__.__name__ == 'PyShell')
##//////////////////////////////////////////////////////
## Test code.
##//////////////////////////////////////////////////////
示例4: _invoke_callbacks
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def _invoke_callbacks(self):
for callback in self._done_callbacks:
try:
callback(self)
except Exception:
LOGGER.exception('exception calling callback for %r', self)
except BaseException:
# Explicitly let all other new-style exceptions through so
# that we can catch all old-style exceptions with a simple
# "except:" clause below.
#
# All old-style exception objects are instances of
# types.InstanceType, but "except types.InstanceType:" does
# not catch old-style exceptions for some reason. Thus, the
# only way to catch all old-style exceptions without catching
# any new-style exceptions is to filter out the new-style
# exceptions, which all derive from BaseException.
raise
except:
# Because of the BaseException clause above, this handler only
# executes for old-style exception objects.
LOGGER.exception('exception calling callback for %r', self)
示例5: call_internal
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def call_internal(self, func_modifier, args, kw):
""" Common utility class for calling an overloaded method,
either bound on a class or not. func_modifier is a lambda
function which is used to "bind" bound methods to the correct
instance
"""
argtype = type(args[0])
class Old:
pass
if argtype is types.InstanceType: # old-style class
argtype = args[0].__class__
hier = list(inspect.getmro(argtype)) # class hierarchy
hier.reverse() # order w/ superclass first
hier = [ t for t in hier if t in self.registry ]
if len(hier) == 0:
raise TypeError("Function %s has no compatible overloads registered for argument type %s" %
(self.func_name, argtype))
result = None
for t in hier:
if not self.allow_cascade[t] and t != hier[-1]:
continue # don't "cascade" down from superclass on this method
result = func_modifier(self.registry[t])(*args, **kw)
return result
示例6: try_serialize_handler
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def try_serialize_handler(handler):
"""Try to serialize map/reduce handler.
Args:
handler: handler function/instance. Handler can be a function or an
instance of a callable class. In the latter case, the handler will
be serialized across slices to allow users to save states.
Returns:
serialized handler string or None.
"""
if (isinstance(handler, types.InstanceType) or # old style class
(isinstance(handler, object) and # new style class
not inspect.isfunction(handler) and
not inspect.ismethod(handler)) and
hasattr(handler, "__call__")):
return pickle.dumps(handler)
return None
示例7: error
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def error(self, obj, value):
kind = type(value)
if (not py3compat.PY3) and kind is InstanceType:
msg = 'class %s' % value.__class__.__name__
else:
msg = '%s (i.e. %s)' % ( str( kind )[1:-1], repr( value ) )
if obj is not None:
e = "The '%s' trait of %s instance must be %s, but a value of %s was specified." \
% (self.name, class_of(obj),
self.info(), msg)
else:
e = "The '%s' trait must be %s, but a value of %r was specified." \
% (self.name, self.info(), msg)
raise TraitError(e)
示例8: pdef
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def pdef(self, obj, oname=''):
"""Print the call signature for any callable object.
If the object is a class, print the constructor information."""
if not callable(obj):
print('Object is not callable.')
return
header = ''
if inspect.isclass(obj):
header = self.__head('Class constructor information:\n')
obj = obj.__init__
elif (not py3compat.PY3) and type(obj) is types.InstanceType:
obj = obj.__call__
output = self._getdef(obj,oname)
if output is None:
self.noinfo('definition header',oname)
else:
print(header,self.format(output), end=' ', file=io.stdout)
# In Python 3, all classes are new-style, so they all have __init__.
示例9: init_info
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def init_info(self):
scxx_converter.init_info(self)
self.type_name = 'instance'
self.check_func = 'PyInstance_Check'
self.c_type = 'py::object'
self.return_type = 'py::object'
self.to_c_return = 'py::object(py_obj)'
self.matching_types = [types.InstanceType]
# ref counting handled by py::object
self.use_ref_count = 0
#----------------------------------------------------------------------------
# Catchall Converter
#
# catch all now handles callable objects
#----------------------------------------------------------------------------
示例10: __init__
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def __init__(self,data):
self.change = 0
self.maxtype = 0
self.data = data
if type(data) is types.InstanceType and ".dump" in str(data.__class__):
self.which = 0
elif type(data) is types.InstanceType and ".data" in str(data.__class__):
self.which = 0
elif type(data) is types.InstanceType and ".mdump" in str(data.__class__):
self.which = 1
elif type(data) is types.InstanceType and ".cdata" in str(data.__class__):
self.which = 1
else:
raise StandardError,"unrecognized object passed to ensight"
# --------------------------------------------------------------------
示例11: latestVersionOf
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def latestVersionOf(self, anObject):
"""
Get the latest version of an object.
This can handle just about anything callable; instances, functions,
methods, and classes.
"""
t = type(anObject)
if t == types.FunctionType:
return latestFunction(anObject)
elif t == types.MethodType:
if anObject.im_self is None:
return getattr(anObject.im_class, anObject.__name__)
else:
return getattr(anObject.im_self, anObject.__name__)
elif t == types.InstanceType:
# Kick it, if it's out of date.
getattr(anObject, 'nothing', None)
return anObject
elif t == types.ClassType:
return latestClass(anObject)
else:
log.msg('warning returning anObject!')
return anObject
示例12: collect_variables
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def collect_variables(self, vars, objects, names, treated, skip_unknown = False):
for name in names:
if name not in treated:
try:
obj = objects[name]
try:
if sys.version[0] == '2' and type(obj) is types.InstanceType:
type_name = "instance (" + obj.__class__.__name__ + ")"
else:
type_name = type(obj).__name__
except:
type_name = 'unknown'
except:
if skip_unknown:
continue
obj = SynthesizedValue('<undefined>', len_value=0)
type_name = 'unknown'
vars.append((name, type(obj), safe_repr(obj), safe_hex_repr(obj), type_name, get_object_len(obj)))
treated.add(name)
示例13: latestVersionOf
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def latestVersionOf(self, anObject):
"""
Get the latest version of an object.
This can handle just about anything callable; instances, functions,
methods, and classes.
"""
t = type(anObject)
if t == types.FunctionType:
return latestFunction(anObject)
elif t == types.MethodType:
if anObject.__self__ is None:
return getattr(anObject.im_class, anObject.__name__)
else:
return getattr(anObject.__self__, anObject.__name__)
elif not _PY3 and t == InstanceType:
# Kick it, if it's out of date.
getattr(anObject, 'nothing', None)
return anObject
elif _isClassType(t):
return latestClass(anObject)
else:
log.msg('warning returning anObject!')
return anObject
示例14: format
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def format(self):
pack_format = '>'
for field in self._fields_:
if type(field[1]) is types.InstanceType:
if BaseStucture in field[1].__class__.__bases__:
pack_format += str(field[1].size()) + 's'
elif 'si' == field[1]:
pack_format += 'c'
elif '<' in field[1]:
pack_format += field[1][1:]
else:
pack_format += field[1]
return pack_format
示例15: pack
# 需要导入模块: import types [as 别名]
# 或者: from types import InstanceType [as 别名]
def pack(self):
values = []
for field in self._fields_:
if type(field[1]) is types.InstanceType:
if BaseStucture in field[1].__class__.__bases__:
values.append(getattr(self, field[0], 0).pack())
else:
if 'si' == field[1]:
values.append(chr(getattr(self, field[0], 0)))
else:
values.append(getattr(self, field[0], 0))
return struct.pack(self.format(), *values)