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


Python collections.ChainMap方法代码示例

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


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

示例1: substitute

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def substitute(self, *args, **kws):
        if len(args) > 1:
            raise TypeError('Too many positional arguments')
        if not args:
            mapping = kws
        elif kws:
            mapping = ChainMap(kws, args[0])
        else:
            mapping = args[0]
        # Helper function for .sub()
        def convert(mo):
            # Check the most common path first.
            named = mo.group('named') or mo.group('braced')
            if named is not None:
                val = mapping[named]
                # We use this idiom instead of str() because the latter will
                # fail if val is a Unicode containing non-ASCII characters.
                return '%s' % (val,)
            if mo.group('escaped') is not None:
                return self.delimiter
            if mo.group('invalid') is not None:
                self._invalid(mo)
            raise ValueError('Unrecognized named group in pattern',
                             self.pattern)
        return self.pattern.sub(convert, self.template) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:27,代码来源:string.py

示例2: _unify_values

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def _unify_values(self, section, vars):
        """Create a sequence of lookups with 'vars' taking priority over
        the 'section' which takes priority over the DEFAULTSECT.

        """
        sectiondict = {}
        try:
            sectiondict = self._sections[section]
        except KeyError:
            if section != self.default_section:
                raise NoSectionError(section)
        # Update with the entry specific variables
        vardict = {}
        if vars:
            for key, value in vars.items():
                if value is not None:
                    value = str(value)
                vardict[self.optionxform(key)] = value
        return _ChainMap(vardict, sectiondict, self._defaults) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:21,代码来源:configparser.py

示例3: count

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def count(start=0, step=1):
    """
    ``itertools.count`` in Py 2.6 doesn't accept a step
    parameter. This is an enhanced version of ``itertools.count``
    for Py2.6 equivalent to ``itertools.count`` in Python 2.7+.
    """
    while True:
        yield start
        start += step


########################################################################
###  ChainMap (helper for configparser and string.Template)
###  From the Py3.4 source code. See also:
###    https://github.com/kkxue/Py2ChainMap/blob/master/py2chainmap.py
######################################################################## 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:18,代码来源:misc.py

示例4: __init__

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def __init__(self, **kwargs) -> None:
        default_kwargs = {
            'id': next(self.discord_id),
            'name': 'role',
            'position': 1,
            'colour': discord.Colour(0xdeadbf),
            'permissions': discord.Permissions(),
        }
        super().__init__(**collections.ChainMap(kwargs, default_kwargs))

        if isinstance(self.colour, int):
            self.colour = discord.Colour(self.colour)

        if isinstance(self.permissions, int):
            self.permissions = discord.Permissions(self.permissions)

        if 'mention' not in kwargs:
            self.mention = f'&{self.name}' 
开发者ID:python-discord,项目名称:bot,代码行数:20,代码来源:helpers.py

示例5: unwatch_command

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: str) -> None:
        """
        Ends the active nomination of the specified user with the given reason.

        Providing a `reason` is required.
        """
        active_nomination = await self.bot.api_client.get(
            self.api_endpoint,
            params=ChainMap(
                self.api_default_params,
                {"user__id": str(user.id)}
            )
        )

        if not active_nomination:
            await ctx.send(":x: The specified user does not have an active nomination")
            return

        [nomination] = active_nomination
        await self.bot.api_client.patch(
            f"{self.api_endpoint}/{nomination['id']}",
            json={'end_reason': reason, 'active': False}
        )
        await ctx.send(f":white_check_mark: Messages sent by {user} will no longer be relayed")
        self._remove_user(user.id) 
开发者ID:python-discord,项目名称:bot,代码行数:27,代码来源:talentpool.py

示例6: safe_substitute

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def safe_substitute(self, *args, **kws):
        if len(args) > 1:
            raise TypeError('Too many positional arguments')
        if not args:
            mapping = kws
        elif kws:
            mapping = ChainMap(kws, args[0])
        else:
            mapping = args[0]
        # Helper function for .sub()
        def convert(mo):
            named = mo.group('named') or mo.group('braced')
            if named is not None:
                try:
                    # We use this idiom instead of str() because the latter
                    # will fail if val is a Unicode containing non-ASCII
                    return '%s' % (mapping[named],)
                except KeyError:
                    return mo.group()
            if mo.group('escaped') is not None:
                return self.delimiter
            if mo.group('invalid') is not None:
                return mo.group()
            raise ValueError('Unrecognized named group in pattern',
                             self.pattern)
        return self.pattern.sub(convert, self.template)



########################################################################
# the Formatter class
# see PEP 3101 for details and purpose of this class

# The hard parts are reused from the C implementation.  They're exposed as "_"
# prefixed methods of str.

# The overall parser is implemented in _string.formatter_parser.
# The field name parser is implemented in _string.formatter_field_name_split 
开发者ID:war-and-code,项目名称:jawfish,代码行数:40,代码来源:string.py

示例7: __init__

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def __init__(self, *maps):
        '''Initialize a ChainMap by setting *maps* to the given mappings.
        If no mappings are provided, a single empty dictionary is used.

        '''
        self.maps = list(maps) or [{}]          # always at least one map 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:8,代码来源:misc.py

示例8: fromkeys

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def fromkeys(cls, iterable, *args):
        'Create a ChainMap with a single dict created from the iterable.'
        return cls(dict.fromkeys(iterable, *args)) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:misc.py

示例9: copy

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def copy(self):
        'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
        return self.__class__(self.maps[0].copy(), *self.maps[1:]) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:5,代码来源:misc.py

示例10: new_child

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def new_child(self, m=None):                # like Django's Context.push()
        '''
        New ChainMap with a new map followed by all previous maps. If no
        map is provided, an empty dict is used.
        '''
        if m is None:
            m = {}
        return self.__class__(m, *self.maps) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:10,代码来源:misc.py

示例11: __init__

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def __init__(self, *maps):
            '''Initialize a ChainMap by setting *maps* to the given mappings.
            If no mappings are provided, a single empty dictionary is used.
            '''
            self.maps = list(maps) or [{}]          # always at least one map 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:datastructures.py

示例12: fromkeys

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def fromkeys(cls, iterable, *args):
            'Create a ChainMap with a single dict created from the iterable.'
            return cls(dict.fromkeys(iterable, *args)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:datastructures.py

示例13: copy

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def copy(self):
            'New ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]'
            return self.__class__(self.maps[0].copy(), *self.maps[1:]) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:datastructures.py

示例14: new_child

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def new_child(self, m=None):                # like Django's Context.push()
            '''New ChainMap with a new map followed by all previous maps.
            If no map is provided, an empty dict is used.
            '''
            if m is None:
                m = {}
            return self.__class__(m, *self.maps) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:datastructures.py

示例15: parents

# 需要导入模块: import collections [as 别名]
# 或者: from collections import ChainMap [as 别名]
def parents(self):                          # like Django's Context.pop()
            'New ChainMap from maps[1:].'
            return self.__class__(*self.maps[1:]) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:5,代码来源:datastructures.py


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