本文整理匯總了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)