本文整理匯總了Python中six.class_types方法的典型用法代碼示例。如果您正苦於以下問題:Python six.class_types方法的具體用法?Python six.class_types怎麽用?Python six.class_types使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類six
的用法示例。
在下文中一共展示了six.class_types方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_class_name
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def get_class_name(obj, fully_qualified=True):
"""Get class name for object.
If object is a type, fully qualified name of the type is returned.
Else, fully qualified name of the type of the object is returned.
For builtin types, just name is returned.
"""
if not isinstance(obj, six.class_types):
obj = type(obj)
try:
built_in = obj.__module__ in _BUILTIN_MODULES
except AttributeError:
pass
else:
if built_in:
return obj.__name__
if fully_qualified and hasattr(obj, '__module__'):
return '%s.%s' % (obj.__module__, obj.__name__)
else:
return obj.__name__
示例2: __init__
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def __init__(self, query_class):
"""
:param query_class: 要查詢的 class 名稱或者對象
:type query_class: string_types or leancloud.ObjectMeta
"""
if isinstance(query_class, six.string_types):
if query_class in ("File", "_File"):
query_class = File
else:
query_class = Object.extend(query_class)
if not isinstance(query_class, (type, six.class_types)) or not issubclass(
query_class, (File, Object)
):
raise ValueError("Query takes string or LeanCloud Object")
self._query_class = query_class
self._where = {}
self._include = []
self._include_acl = None
self._limit = -1
self._skip = 0
self._extra = {}
self._order = []
self._select = []
示例3: get_unpatched
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def get_unpatched(item):
lookup = (
get_unpatched_class if isinstance(item, six.class_types) else
get_unpatched_function if isinstance(item, types.FunctionType) else
lambda item: None
)
return lookup(item)
示例4: is_matchable_type
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def is_matchable_type(expected_type):
if isinstance(expected_type, type):
return True
if isinstance(expected_type, six.class_types):
return True
if isinstance(expected_type, tuple) and \
expected_type and \
all(map(is_matchable_type, expected_type)):
return True
return False
示例5: can_document_member
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def can_document_member(cls, member, membername, isattr, parent):
return isinstance(member, class_types) and \
issubclass(member, _STIXBase) and \
hasattr(member, '_properties')
示例6: test_class_types
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def test_class_types():
class X:
pass
class Y(object):
pass
assert isinstance(X, six.class_types)
assert isinstance(Y, six.class_types)
assert not isinstance(X(), six.class_types)
示例7: test_from_imports
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def test_from_imports():
from six.moves.queue import Queue
assert isinstance(Queue, six.class_types)
from six.moves.configparser import ConfigParser
assert isinstance(ConfigParser, six.class_types)
示例8: experimental
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def experimental(func):
"""Decorate a function or class to designated it as experimental.
Will raise an `ExperimentalWarning` when used and automatically adds a
Sphinx '.. warning::' directive to the docstring.
Parameters
----------
func
Returns
-------
func
"""
@functools.wraps(func)
def _wrapper(*args, **kwargs):
warning = '%s is experimental and may be modified or removed without warning.' % func.__name__
warnings.warn(warning,
category=ExperimentalWarning, stacklevel=2)
return func(*args, **kwargs)
type_ = 'class' if isinstance(func, six.class_types) else 'method'
directive = '.. warning:: This %s is experimental and may be modified or removed without warning.' % type_
try:
# Insert directive into original docstring
_wrapper.__doc__ = _insert_docstring_text(func, directive)
except AttributeError:
# __doc__ is not writable in Py27
pass
return _wrapper
示例9: testAttributes
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def testAttributes(self):
inner_classes = set([])
for key, value in iam_v1_client.IamV1.__dict__.items():
if isinstance(value, six.class_types):
inner_classes.add(key)
self.assertEquals(set([
'IamPoliciesService',
'ProjectsService',
'ProjectsServiceAccountsKeysService',
'ProjectsServiceAccountsService',
'RolesService']), inner_classes)
示例10: testAttributes
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def testAttributes(self):
inner_classes = set([])
for key, value in dns_v1_client.DnsV1.__dict__.items():
if isinstance(value, six.class_types):
inner_classes.add(key)
self.assertEquals(set([
'ChangesService',
'ProjectsService',
'ManagedZonesService',
'ResourceRecordSetsService']), inner_classes)
示例11: is_classmethod
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def is_classmethod(fn):
"""Returns whether f is a classmethod."""
# This is True for bound methods
if not inspect.ismethod(fn):
return False
if not hasattr(fn, "__self__"):
return False
im_self = fn.__self__
# This is None for instance methods on classes, but True
# for instance methods on instances.
if im_self is None:
return False
# This is True for class methods of new- and old-style classes, respectively
return isinstance(im_self, six.class_types)
示例12: usage
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def usage(obj, selfname='self'):
str(obj) # In case it's lazy, this will load it.
if not isinstance(obj, class_types):
obj = obj.__class__
print('%s supports the following operations:' % obj.__name__)
for (name, method) in sorted(pydoc.allmethods(obj).items()):
if name.startswith('_'):
continue
if getattr(method, '__deprecated__', False):
continue
if sys.version_info[0] >= 3:
getargspec = inspect.getfullargspec
else:
getargspec = inspect.getargspec
args, varargs, varkw, defaults = getargspec(method)[:4]
if (
args
and args[0] == 'self'
and (defaults is None or len(args) > len(defaults))
):
args = args[1:]
name = '%s.%s' % (selfname, name)
argspec = inspect.formatargspec(args, varargs, varkw, defaults)
print(
textwrap.fill(
'%s%s' % (name, argspec),
initial_indent=' - ',
subsequent_indent=' ' * (len(name) + 5),
)
)
##########################################################################
# IDLE
##########################################################################
示例13: get_class_name
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def get_class_name(obj, fully_qualified=True, truncate_builtins=True):
"""Get class name for object.
If object is a type, returns name of the type. If object is a bound
method or a class method, returns its ``self`` object's class name.
If object is an instance of class, returns instance's class name.
Else, name of the type of the object is returned. If fully_qualified
is True, returns fully qualified name of the type. For builtin types,
just name is returned. TypeError is raised if can't get class name from
object.
"""
if inspect.isfunction(obj):
raise TypeError("Can't get class name.")
if inspect.ismethod(obj):
obj = get_method_self(obj)
if not isinstance(obj, six.class_types):
obj = type(obj)
if truncate_builtins:
try:
built_in = obj.__module__ in _BUILTIN_MODULES
except AttributeError: # nosec
pass
else:
if built_in:
return obj.__name__
if fully_qualified and hasattr(obj, '__module__'):
return '%s.%s' % (obj.__module__, obj.__name__)
else:
return obj.__name__
示例14: get_all_class_names
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def get_all_class_names(obj, up_to=object,
fully_qualified=True, truncate_builtins=True):
"""Get class names of object parent classes.
Iterate over all class names object is instance or subclass of,
in order of method resolution (mro). If up_to parameter is provided,
only name of classes that are sublcasses to that class are returned.
"""
if not isinstance(obj, six.class_types):
obj = type(obj)
for cls in obj.mro():
if issubclass(cls, up_to):
yield get_class_name(cls,
fully_qualified=fully_qualified,
truncate_builtins=truncate_builtins)
示例15: get_callable_name
# 需要導入模塊: import six [as 別名]
# 或者: from six import class_types [as 別名]
def get_callable_name(function):
"""Generate a name from callable.
Tries to do the best to guess fully qualified callable name.
"""
method_self = get_method_self(function)
if method_self is not None:
# This is a bound method.
if isinstance(method_self, six.class_types):
# This is a bound class method.
im_class = method_self
else:
im_class = type(method_self)
try:
parts = (im_class.__module__, function.__qualname__)
except AttributeError:
parts = (im_class.__module__, im_class.__name__, function.__name__)
elif inspect.ismethod(function) or inspect.isfunction(function):
# This could be a function, a static method, a unbound method...
try:
parts = (function.__module__, function.__qualname__)
except AttributeError:
if hasattr(function, 'im_class'):
# This is a unbound method, which exists only in python 2.x
im_class = function.im_class
parts = (im_class.__module__,
im_class.__name__, function.__name__)
else:
parts = (function.__module__, function.__name__)
else:
im_class = type(function)
if im_class is _TYPE_TYPE:
im_class = function
try:
parts = (im_class.__module__, im_class.__qualname__)
except AttributeError:
parts = (im_class.__module__, im_class.__name__)
return '.'.join(parts)