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


Python collections.Callable方法代码示例

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


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

示例1: stream_response_to_file

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def stream_response_to_file(response, path=None):
    pre_opened = False
    fd = None
    if path:
        if isinstance(getattr(path, 'write', None), Callable):
            pre_opened = True
            fd = path
        else:
            fd = open(path, 'wb')
    else:
        header = response.headers['content-disposition']
        i = header.find('filename=') + len('filename=')
        fd = open(header[i:], 'wb')

    for chunk in response.iter_content(chunk_size=512):
        fd.write(chunk)

    if not pre_opened:
        fd.close() 
开发者ID:kislyuk,项目名称:aegea,代码行数:21,代码来源:utils.py

示例2: map

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def map(self, func, *args, **kwargs):
        r"""Call ``func`` with the plugin and \*args and \**kwargs after.

        This yields the return value from ``func`` for each plugin.

        :param collections.Callable func:
            Function to call with each plugin. Signature should at least be:

            .. code-block:: python

                def myfunc(plugin):
                     pass

            Any extra positional or keyword arguments specified with map will
            be passed along to this function after the plugin. The plugin
            passed is a :class:`~flake8.plugins.manager.Plugin`.
        :param args:
            Positional arguments to pass to ``func`` after each plugin.
        :param kwargs:
            Keyword arguments to pass to ``func`` after each plugin.
        """
        for name in self.names:
            yield func(self.plugins[name], *args, **kwargs) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:25,代码来源:manager.py

示例3: field_value

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def field_value(field):
	""" 
	Returns the value for this BoundField, as rendered in widgets. 
	""" 
	if field.form.is_bound: 
		if isinstance(field.field, FileField) and field.data is None: 
			val = field.form.initial.get(field.name, field.field.initial) 
		else: 
			val = field.data 
	else:
		val = field.form.initial.get(field.name, field.field.initial)
		if isinstance(val, collections.Callable):
			val = val()
	if val is None:
		val = ''
	return val 
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:submission_filters.py

示例4: _transaction_func

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def _transaction_func(entering, exiting, using):
    """
    Takes 3 things, an entering function (what to do to start this block of
    transaction management), an exiting function (what to do to end it, on both
    success and failure, and using which can be: None, indiciating using is
    DEFAULT_DB_ALIAS, a callable, indicating that using is DEFAULT_DB_ALIAS and
    to return the function already wrapped.

    Returns either a Transaction objects, which is both a decorator and a
    context manager, or a wrapped function, if using is a callable.
    """
    # Note that although the first argument is *called* `using`, it
    # may actually be a function; @autocommit and @autocommit('foo')
    # are both allowed forms.
    if using is None:
        using = DEFAULT_DB_ALIAS
    if isinstance(using, collections.Callable):
        return Transaction(entering, exiting, DEFAULT_DB_ALIAS)(using)
    return Transaction(entering, exiting, using) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:fake_transaction.py

示例5: register_archive_format

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def register_archive_format(name, function, extra_args=None, description=''):
    """Registers an archive format.

    name is the name of the format. function is the callable that will be
    used to create archives. If provided, extra_args is a sequence of
    (name, value) tuples that will be passed as arguments to the callable.
    description can be provided to describe the format, and will be returned
    by the get_archive_formats() function.
    """
    if extra_args is None:
        extra_args = []
    if not isinstance(function, collections.Callable):
        raise TypeError('The %s object is not callable' % function)
    if not isinstance(extra_args, (tuple, list)):
        raise TypeError('extra_args needs to be a sequence')
    for element in extra_args:
        if not isinstance(element, (tuple, list)) or len(element) !=2:
            raise TypeError('extra_args elements are : (arg_name, value)')

    _ARCHIVE_FORMATS[name] = (function, extra_args, description) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:shutil.py

示例6: _check_unpack_options

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def _check_unpack_options(extensions, function, extra_args):
    """Checks what gets registered as an unpacker."""
    # first make sure no other unpacker is registered for this extension
    existing_extensions = {}
    for name, info in _UNPACK_FORMATS.items():
        for ext in info[0]:
            existing_extensions[ext] = name

    for extension in extensions:
        if extension in existing_extensions:
            msg = '%s is already registered for "%s"'
            raise RegistryError(msg % (extension,
                                       existing_extensions[extension]))

    if not isinstance(function, collections.Callable):
        raise TypeError('The registered function must be a callable') 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:shutil.py

示例7: register_archive_format

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def register_archive_format(name, function, extra_args=None, description=''):
    """Registers an archive format.

    name is the name of the format. function is the callable that will be
    used to create archives. If provided, extra_args is a sequence of
    (name, value) tuples that will be passed as arguments to the callable.
    description can be provided to describe the format, and will be returned
    by the get_archive_formats() function.
    """
    if extra_args is None:
        extra_args = []
    if not isinstance(function, collections.Callable):
        raise TypeError('The %s object is not callable' % function)
    if not isinstance(extra_args, (tuple, list)):
        raise TypeError('extra_args needs to be a sequence')
    for element in extra_args:
        if not isinstance(element, (tuple, list)) or len(element) !=2 :
            raise TypeError('extra_args elements are : (arg_name, value)')

    _ARCHIVE_FORMATS[name] = (function, extra_args, description) 
开发者ID:glmcdona,项目名称:meddle,代码行数:22,代码来源:shutil.py

示例8: test_Callable

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def test_Callable(self):
        non_samples = [None, 42, 3.14, 1j,
                       "", "".encode('ascii'), (), [], {}, set(),
                       (lambda: (yield))(),
                       (x for x in []),
                       ]
        for x in non_samples:
            self.assertNotIsInstance(x, Callable)
            self.assertFalse(issubclass(type(x), Callable), repr(type(x)))
        samples = [lambda: None,
                   type, int, object,
                   len,
                   list.append, [].append,
                   ]
        for x in samples:
            self.assertIsInstance(x, Callable)
            self.assertTrue(issubclass(type(x), Callable), repr(type(x)))
        self.validate_abstract_methods(Callable, '__call__')
        self.validate_isinstance(Callable, '__call__') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_collections.py

示例9: two_factor_auth_callback

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def two_factor_auth_callback(self, callback):
        if not callback:
            return

        if not isinstance(callback, Callable):
            raise ValueError('Your callback should be callable')

        self.two_factor_auth_cb = callback 
开发者ID:kislyuk,项目名称:aegea,代码行数:10,代码来源:session.py

示例10: _monitoring_action

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def _monitoring_action(self):
        now = datetime.now()
        self.__load = psutil.cpu_percent()
        self.__load_stats[now] = self.__load
        if isinstance(self.__temperature_reader, Callable):
            try:
                self.__temperature = self.__temperature_reader()
                self.__temperature_stats[now] = self.__temperature
            except:
                print('Can\'t read CPU temperature') 
开发者ID:it-geeks-club,项目名称:pyspectator,代码行数:12,代码来源:processor.py

示例11: register_hook

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def register_hook(self, event, hook):
        """Properly register a hook."""

        if event not in self.hooks:
            raise ValueError('Unsupported event specified, with event name "%s"' % (event))

        if isinstance(hook, collections.Callable):
            self.hooks[event].append(hook)
        elif hasattr(hook, '__iter__'):
            self.hooks[event].extend(h for h in hook if isinstance(h, collections.Callable)) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:12,代码来源:models.py

示例12: info

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def info(object, spacing=10, collapse=1):
    """Print methods and doc strings.
    Takes module, class, list, dictionary, or string."""
    methodList = [e for e in dir(object) if isinstance(getattr(object, e), collections.Callable)]
    processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
    print( "\n".join(["%s %s" %
                     (method.ljust(spacing),
                      processFunc(str(getattr(object, method).__doc__)))
                     for method in methodList]) ) 
开发者ID:ozan-oktay,项目名称:Attention-Gated-Networks,代码行数:11,代码来源:util.py

示例13: search_tag

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def search_tag(self, markup_name=None, markup_attrs={}):
        found = None
        markup = None
        if isinstance(markup_name, Tag):
            markup = markup_name
            markup_attrs = markup
        call_function_with_tag_data = (
            isinstance(self.name, collections.Callable)
            and not isinstance(markup_name, Tag))

        if ((not self.name)
            or call_function_with_tag_data
            or (markup and self._matches(markup, self.name))
            or (not markup and self._matches(markup_name, self.name))):
            if call_function_with_tag_data:
                match = self.name(markup_name, markup_attrs)
            else:
                match = True
                markup_attr_map = None
                for attr, match_against in list(self.attrs.items()):
                    if not markup_attr_map:
                        if hasattr(markup_attrs, 'get'):
                            markup_attr_map = markup_attrs
                        else:
                            markup_attr_map = {}
                            for k, v in markup_attrs:
                                markup_attr_map[k] = v
                    attr_value = markup_attr_map.get(attr)
                    if not self._matches(attr_value, match_against):
                        match = False
                        break
            if match:
                if markup:
                    found = markup
                else:
                    found = markup_name
        if found and self.text and not self._matches(found.string, self.text):
            found = None
        return found 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:41,代码来源:element.py

示例14: parser_for

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def parser_for(self, encoding):
        # Use the default parser.
        parser = self.default_parser(encoding)

        if isinstance(parser, collections.Callable):
            # Instantiate the parser with default arguments
            parser = parser(target=self, strip_cdata=False, encoding=encoding)
        return parser 
开发者ID:MarcelloLins,项目名称:ServerlessCrawler-VancouverRealState,代码行数:10,代码来源:_lxml.py

示例15: _generate_call_function

# 需要导入模块: import collections [as 别名]
# 或者: from collections import Callable [as 别名]
def _generate_call_function(method_name, optmanager, *args, **kwargs):
        def generated_function(plugin):  # noqa: D105
            method = getattr(plugin, method_name, None)
            if (method is not None and
                    isinstance(method, collections.Callable)):
                return method(optmanager, *args, **kwargs)
        return generated_function 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:9,代码来源:manager.py


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