當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。