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


Python abc.MutableSequence方法代码示例

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


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

示例1: update_config_pwd

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def update_config_pwd(msg, cfg):
    """
    Updates the profile's auth entry with values set by the user.
    This will overwrite existing values.

    Args:
        :msg: (Message class) an instance of a message class.
        :cfg: (jsonconfig.Config) config instance.
    """
    msg_type = msg.__class__.__name__.lower()
    key_fmt = msg.profile + "_" + msg_type
    if isinstance(msg._auth, (MutableSequence, tuple)):
        cfg.pwd[key_fmt] = " :: ".join(msg._auth)
    else:
        cfg.pwd[key_fmt] = msg._auth


##############################################################################
#  Config functions used by the CLI to create profile entries
############################################################################## 
开发者ID:trp07,项目名称:messages,代码行数:22,代码来源:_config.py

示例2: update

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def update(self, serializers):
        # Serializers is a list
        if isinstance(serializers, abc.MutableSequence):
            self.serializers = dict(
                ((str(k), v) for k, v in enumerate(serializers))
            )
        # Serializers is a string
        elif isinstance(serializers, abc.Sequence):
            self.serializers = {
                '0': serializers
            }
        # Serializers is a dictionary
        elif isinstance(serializers, abc.Mapping):
            self.serializers.update(serializers)
        else:
            raise(TypeError(
                ("serializers must be either a MutableSequence, "
                 "a Sequence, or a Mapping.")
            )) 
开发者ID:lgiordani,项目名称:punch,代码行数:21,代码来源:replacer.py

示例3: insert

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def insert(self, index: int, item: object) -> None:
        """
        The Abstract class `MutableSequence` leverages this insert method to
        perform the `BlueprintGroup.append` operation.

        :param index: Index to use for removing a new Blueprint item
        :param item: New `Blueprint` object.
        :return: None
        """
        self._blueprints.insert(index, item) 
开发者ID:huge-success,项目名称:sanic,代码行数:12,代码来源:blueprint_group.py

示例4: check_valid

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def check_valid(msg_type, attr, value, func, exec_info):
    """
    Checker function all validate_* functions below will call.
    Raises InvalidMessageInputError if input is not valid as per
    given func.
    """
    if value is not None:
        if isinstance(value, MutableSequence):
            for v in value:
                if not func(v):
                    raise InvalidMessageInputError(msg_type, attr, value, exec_info)
        else:
            if not func(value):
                raise InvalidMessageInputError(msg_type, attr, value, exec_info) 
开发者ID:trp07,项目名称:messages,代码行数:16,代码来源:_utils.py

示例5: list_to_string

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def list_to_string(recipient):
        """
        Format the recipient for the MIMEMultipart() email type.
        If the recipient is a list, then it returns the list as a
        comma separated string.
        example: input=['you@here.com', 'her@there.com']
                 output='you@there.com, her@there.com'
        """
        if recipient:
            if isinstance(recipient, MutableSequence):
                return ", ".join(recipient)
            return recipient 
开发者ID:trp07,项目名称:messages,代码行数:14,代码来源:email_.py

示例6: _deserialize

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def _deserialize(self, value, attr, obj, recurse_lvl=0):
        """
        Check deeply to see if there is a {'bytes': [...]} dict and if so
        convert it to a bytes object
        """
        if recurse_lvl == 0:
            valued = super(EntriesField, self)._deserialize(value, attr, obj)
        else:
            valued = value
        if isinstance(valued, MutableMapping):
            for key in six.iterkeys(valued):
                if key == self._BYTES_KEY:
                    return self._hex_list_to_binary(valued[key])
                valued[key] = self._deserialize(
                    value=valued[key],
                    attr=attr,
                    obj=obj,
                    recurse_lvl=(recurse_lvl + 1),
                )
            return valued
        if isinstance(valued, MutableSequence):
            for i in range(len(valued)):
                valued[i] = self._deserialize(
                    value=valued[i],
                    attr=attr,
                    obj=obj,
                    recurse_lvl=(recurse_lvl + 1),
                )
            return valued
        return valued 
开发者ID:Morgan-Stanley,项目名称:testplan,代码行数:32,代码来源:schemas.py

示例7: test_MutableSequence

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def test_MutableSequence(self):
        for sample in [tuple, str, bytes]:
            self.assertNotIsInstance(sample(), MutableSequence)
            self.assertFalse(issubclass(sample, MutableSequence))
        for sample in [list, bytearray, deque]:
            self.assertIsInstance(sample(), MutableSequence)
            self.assertTrue(issubclass(sample, MutableSequence))
        self.assertFalse(issubclass(str, MutableSequence))
        self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
            '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:12,代码来源:test_collections.py

示例8: test_abc

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def test_abc(self):
        from collections import abc
        for element_type_1d in [jboolean, jbyte, jshort, jint, jlong, jfloat, jdouble, jchar,
                                String]:
            for element_type in [element_type_1d, jarray(element_type_1d)]:
                with self.subTest(element_type=element_type):
                    cls = jarray(element_type)
                    self.assertTrue(issubclass(cls, abc.MutableSequence))
                    self.assertTrue(isinstance(cls([]), abc.MutableSequence)) 
开发者ID:chaquo,项目名称:chaquopy,代码行数:11,代码来源:test_array.py

示例9: test_MutableSequence

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def test_MutableSequence(self):
        for sample in [tuple, str, bytes]:
            self.assertNotIsInstance(sample(), MutableSequence)
            self.assertFalse(issubclass(sample, MutableSequence))
        for sample in [list, bytearray]:
            self.assertIsInstance(sample(), MutableSequence)
            self.assertTrue(issubclass(sample, MutableSequence))
        self.assertFalse(issubclass(str, MutableSequence))
        self.validate_abstract_methods(MutableSequence, '__contains__', '__iter__',
            '__len__', '__getitem__', '__setitem__', '__delitem__', 'insert') 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:12,代码来源:test_collections.py

示例10: __new__

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def __new__(cls, arg):  # <1>
        if isinstance(arg, abc.Mapping):
            return super().__new__(cls)  # <2>
        elif isinstance(arg, abc.MutableSequence):  # <3>
            return [cls(item) for item in arg]
        else:
            return arg 
开发者ID:fluentpython,项目名称:notebooks,代码行数:9,代码来源:explore2.py

示例11: build

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def build(cls, obj):  # <5>
        if isinstance(obj, abc.Mapping):  # <6>
            return cls(obj)
        elif isinstance(obj, abc.MutableSequence):  # <7>
            return [cls.build(item) for item in obj]
        else:  # <8>
            return obj
# END EXPLORE0 
开发者ID:fluentpython,项目名称:notebooks,代码行数:10,代码来源:explore0.py

示例12: build

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def build(cls, obj):
        if isinstance(obj, abc.Mapping):
            return cls(obj)
        elif isinstance(obj, abc.MutableSequence):
            return [cls.build(item) for item in obj]
        else:  # <8>
            return obj 
开发者ID:fluentpython,项目名称:notebooks,代码行数:9,代码来源:explore1.py

示例13: hashable

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def hashable(x):
    if isinstance(x, MutableSequence):
        return tuple(x)
    elif isinstance(x, MutableMapping):
        return tuple([(k,v) for k,v in x.items()])
    else:
        return x 
开发者ID:holoviz,项目名称:panel,代码行数:9,代码来源:util.py

示例14: __getitem__

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def __getitem__(self, s: slice) -> MutableSequence:
        ... 
开发者ID:asyml,项目名称:forte,代码行数:4,代码来源:core.py

示例15: send

# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def send(self):
        """
        Send the message.
        First, a message is constructed, then a session with the email
        servers is created, finally the message is sent and the session
        is stopped.
        """
        self._generate_email()

        if self.verbose:
            print(
                "Debugging info"
                "\n--------------"
                "\n{} Message created.".format(timestamp())
            )

        recipients = []
        for i in (self.to, self.cc, self.bcc):
            if i:
                if isinstance(i, MutableSequence):
                    recipients += i
                else:
                    recipients.append(i)

        session = self._get_session()
        if self.verbose:
            print(timestamp(), "Login successful.")

        session.sendmail(self.from_, recipients, self.message.as_string())
        session.quit()

        if self.verbose:
            print(timestamp(), "Logged out.")

        if self.verbose:
            print(
                timestamp(),
                type(self).__name__ + " info:",
                self.__str__(indentation="\n * "),
            )

        print("Message sent.") 
开发者ID:trp07,项目名称:messages,代码行数:44,代码来源:email_.py


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