本文整理汇总了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
##############################################################################
示例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.")
))
示例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)
示例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)
示例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
示例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
示例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')
示例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))
示例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')
示例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
示例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
示例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
示例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
示例14: __getitem__
# 需要导入模块: from collections import abc [as 别名]
# 或者: from collections.abc import MutableSequence [as 别名]
def __getitem__(self, s: slice) -> MutableSequence:
...
示例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.")