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