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


Python inspect.ismethod方法代码示例

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


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

示例1: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def __init__(self, docstring, class_name, class_object):
        super(NumpyClassDocString, self).__init__(docstring)
        self.class_name = class_name
        methods = dict((name, func) for name, func
                       in inspect.getmembers(class_object))

        self.has_parameters = False
        if '__init__' in methods:
            # verify if __init__ is a Python function. If it isn't
            # (e.g. the function is implemented in C), getargspec will fail
            if not inspect.ismethod(methods['__init__']):
                return
            args, varargs, keywords, defaults = inspect.getargspec(
                methods['__init__'])
            if (args and args != ['self']) or varargs or keywords or defaults:
                self.has_parameters = True 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:18,代码来源:docscrape.py

示例2: __getattr__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def __getattr__(self, name: str) -> Any:
        """
        Delegate method calls to the class wrapped by Not().
        Re-wrap methods on child classes of Term (e.g. isin, eg...) to retain 'NOT <term>' output.
        """
        item_func = getattr(self.term, name)

        if not inspect.ismethod(item_func):
            return item_func

        def inner(inner_self, *args, **kwargs):
            result = item_func(inner_self, *args, **kwargs)
            if isinstance(result, (Term,)):
                return Not(result)
            return result

        return inner 
开发者ID:kayak,项目名称:pypika,代码行数:19,代码来源:terms.py

示例3: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def __init__(self, log=True):
        global isLog
        isLog = log

        self._name = self.__class__.__name__

        self._routes = {
            n: v
            for n, v in inspect.getmembers(self, inspect.ismethod)
            if not v.__func__.__qualname__.startswith(("Base.", "Window.", "Server."))
        }
        self._routes.update(
            dict(set=self.set, get=self.get)
        )  # add get/set config methods
        if "init" in self._routes:
            del self._routes[
                "init"
            ]  # ensure that a server-side init() is not exposed on client-side
        self._clients = [] 
开发者ID:manatlan,项目名称:wuy,代码行数:21,代码来源:wuy.py

示例4: collect_options

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def collect_options(mcs, bases, attrs):
        """
        Collects options from the current class and its parent classes.

        :returns: a dictionary of options
        """
        options = {}
        # options from parent classes:
        for base in reversed(bases):
            if hasattr(base, '_options'):
                for key, value in inspect.getmembers(base._options):
                    if not key.startswith('_') and value is not None:
                        options[key] = value

        # options from the current class:
        if 'Options' in attrs:
            for key, value in inspect.getmembers(attrs['Options']):
                if not key.startswith('_') and value is not None:
                    # HACK HACK HACK
                    if inspect.ismethod(value) and value.im_self is None:
                        value = value.im_func
                    options[key] = value
        return options 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:document.py

示例5: _get_name_of_callable

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def _get_name_of_callable(cls, c):
    if inspect.ismethod(c):
      return c.im_class.__name__+'.'+c.__name__
    if inspect.isfunction(c):
      if c.__name__ == (lambda: None).__name__:
        filename = c.func_code.co_filename
        cls._ensure_file_in_cache(filename, c)
        definitions = cls._LAMBDA_CACHE[filename][c.func_code.co_firstlineno]
        assert definitions
        # If there's multiple definitions at the same line, there's not enough
        # information to distinguish which lambda c refers to, so just let
        # python's generic lambda name be used
        if len(definitions) == 1:
          return astunparse.unparse(definitions[0]).strip()
      return c.__name__
    if hasattr(c, '__call__'):
      return c.__class__.__name__+'.__call__'
    return repr(c) 
开发者ID:luci,项目名称:recipes-py,代码行数:20,代码来源:magic_check_fn.py

示例6: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def __init__(self):
    """Validates required attributes for Action subclasses."""
    if not isinstance(getattr(self, 'ACTION_NAME', None), basestring):
      raise AttributeError(_NO_ACTION_NAME_MSG % self.__class__.__name__)
    if not isinstance(getattr(self, 'FRIENDLY_NAME', None), basestring):
      raise AttributeError(_NO_FRIENDLY_NAME_MSG % self.__class__.__name__)
    try:
      if not inspect.ismethod(super(BaseAction, self).__getattribute__('run')):
        raise AttributeError()
    except AttributeError:
      raise AttributeError(_NO_RUN_METHOD_MSG % self.__class__.__name__)
    self.action_type = getattr(self, 'ACTION_TYPE', ActionType.ASYNC)
    if self.action_type not in (ActionType.SYNC, ActionType.ASYNC):
      raise AttributeError(
          _BAD_ACTION_TYPE_MSG %
          (self.__class__.__name__, str(self.action_type))) 
开发者ID:google,项目名称:loaner,代码行数:18,代码来源:base_action.py

示例7: test_all_endpoints_have_scope_attributes

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def test_all_endpoints_have_scope_attributes(self, client):
        # Skip paging calls and options
        skips = {
            'next',
            'previous',
            'all_pages',
            'all_items',
            'chunked',
            'max_limits',
            'token_as',
        }
        for name, method in getmembers(client, predicate=ismethod):
            if name.startswith('_') or name in skips:
                continue
            assert isinstance(method.scope, Scope)
            assert isinstance(method.required_scope, Scope)
            assert isinstance(method.optional_scope, Scope)
            assert method.scope == method.required_scope + method.optional_scope 
开发者ID:felix-hilden,项目名称:tekore,代码行数:20,代码来源:full.py

示例8: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def __init__(self, *args, **kwargs):
            self.pan_device = kwargs.pop('pan_device', None)
            pan.xapi.PanXapi.__init__(self, *args, **kwargs)
            pred = lambda x: inspect.ismethod(x) or inspect.isfunction(x) # inspect.ismethod needed for Python2, inspect.isfunction needed for Python3
            for name, method in inspect.getmembers(
                    pan.xapi.PanXapi,
                    pred):
                # Ignore hidden methods
                if name[0] == "_":
                    continue
                # Ignore non-api methods
                if name in ('xml_result', 'xml_root', 'cmd_xml'):
                    continue

                # Wrapper method.  This is used to create
                # methods in this class that match the methods in the
                # super class, and call the super class methods inside
                # a try/except block, which allows us to check and
                # analyze the exceptions and convert them to more
                # useful exceptions than generic PanXapiErrors.
                wrapper_method = PanDevice.XapiWrapper.make_method(name, method)

                # Create method matching each public method of the base class
                setattr(PanDevice.XapiWrapper, name, wrapper_method) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:26,代码来源:base.py

示例9: convert

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def convert(self, ctx, argument):
        arg = argument.replace('0x', '').lower()

        if arg[0] == '#':
            arg = arg[1:]
        try:
            value = int(arg, base=16)
            if not (0 <= value <= 0xFFFFFF):
                raise BadArgument('Colour "{}" is invalid.'.format(arg))
            return discord.Colour(value=value)
        except ValueError:
            arg = arg.replace(' ', '_')
            method = getattr(discord.Colour, arg, None)
            if arg.startswith('from_') or method is None or not inspect.ismethod(method):
                raise BadArgument('Colour "{}" is invalid.'.format(arg))
            return method() 
开发者ID:Rapptz,项目名称:discord.py,代码行数:18,代码来源:converter.py

示例10: try_serialize_handler

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [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 
开发者ID:elsigh,项目名称:browserscope,代码行数:20,代码来源:util.py

示例11: is_generator

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def is_generator(obj):
  """Return true if the object is generator or generator function.

  Generator function objects provides same attributes as functions.
  See isfunction.__doc__ for attributes listing.

  Adapted from Python 2.6.

  Args:
    obj: an object to test.

  Returns:
    true if the object is generator function.
  """
  if isinstance(obj, types.GeneratorType):
    return True

  CO_GENERATOR = 0x20
  return bool(((inspect.isfunction(obj) or inspect.ismethod(obj)) and
               obj.func_code.co_flags & CO_GENERATOR)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:util.py

示例12: is_generator_function

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def is_generator_function(obj):
  """Return true if the object is a user-defined generator function.

  Generator function objects provides same attributes as functions.
  See isfunction.__doc__ for attributes listing.

  Adapted from Python 2.6.

  Args:
    obj: an object to test.

  Returns:
    true if the object is generator function.
  """
  CO_GENERATOR = 0x20
  return bool(((inspect.isfunction(obj) or inspect.ismethod(obj)) and
               obj.func_code.co_flags & CO_GENERATOR)) 
开发者ID:elsigh,项目名称:browserscope,代码行数:19,代码来源:util.py

示例13: mirror_sync_methods

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def mirror_sync_methods(obj):
    """Populate sync and async methods for obj

    For each method will create a sync version if the name refers to an async method
    (coroutine) and there is no override in the child class; will create an async
    method for the corresponding sync method if there is no implementation.

    Uses the methods specified in
    - async_methods: the set that an implementation is expected to provide
    - default_async_methods: that can be derived from their sync version in
      AbstractFileSystem
    - AsyncFileSystem: async-specific default implementations
    """
    from fsspec import AbstractFileSystem

    for method in async_methods + default_async_methods + dir(AsyncFileSystem):
        smethod = method[1:]
        if private.match(method):
            if inspect.iscoroutinefunction(getattr(obj, method, None)) and getattr(
                obj, smethod, False
            ).__func__ is getattr(AbstractFileSystem, smethod):
                setattr(obj, smethod, sync_wrapper(getattr(obj, method), obj=obj))
            elif hasattr(obj, smethod) and inspect.ismethod(getattr(obj, smethod)):
                setattr(obj, method, async_wrapper(getattr(obj, smethod))) 
开发者ID:intake,项目名称:filesystem_spec,代码行数:26,代码来源:asyn.py

示例14: addWidget

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def addWidget(self, w, name=None, scale=None):
        if not self.acceptsType(w):
            raise Exception("Widget type %s not supported by WidgetGroup" % type(w))
        if name is None:
            name = str(w.objectName())
        if name == '':
            raise Exception("Cannot add widget '%s' without a name." % str(w))
        self.widgetList[w] = name
        self.scales[w] = scale
        self.readWidget(w)
            
        if type(w) in WidgetGroup.classes:
            signal = WidgetGroup.classes[type(w)][0]
        else:
            signal = w.widgetGroupInterface()[0]
            
        if signal is not None:
            if inspect.isfunction(signal) or inspect.ismethod(signal):
                signal = signal(w)
            signal.connect(self.mkChangeCallback(w))
        else:
            self.uncachedWidgets[w] = None 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:24,代码来源:WidgetGroup.py

示例15: readWidget

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import ismethod [as 别名]
def readWidget(self, w):
        if type(w) in WidgetGroup.classes:
            getFunc = WidgetGroup.classes[type(w)][1]
        else:
            getFunc = w.widgetGroupInterface()[1]
        
        if getFunc is None:
            return None
            
        ## if the getter function provided in the interface is a bound method,
        ## then just call the method directly. Otherwise, pass in the widget as the first arg
        ## to the function.
        if inspect.ismethod(getFunc) and getFunc.__self__ is not None:  
            val = getFunc()
        else:
            val = getFunc(w)
            
        if self.scales[w] is not None:
            val /= self.scales[w]
        #if isinstance(val, QtCore.QString):
            #val = str(val)
        n = self.widgetList[w]
        self.cache[n] = val
        return val 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:26,代码来源:WidgetGroup.py


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