本文整理汇总了Python中bidict.bidict方法的典型用法代码示例。如果您正苦于以下问题:Python bidict.bidict方法的具体用法?Python bidict.bidict怎么用?Python bidict.bidict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bidict
的用法示例。
在下文中一共展示了bidict.bidict方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_validators_with_defaults
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def get_validators_with_defaults(schema_props):
validators = {}
defaults = {}
display_map = bidict()
for name, props in schema_props.items():
ValidatorType, is_array, default = get_validator_details(schema_props, name)
attr_name = props.get("x-calm-dsl-display-name", name)
validators[attr_name] = (ValidatorType, is_array)
defaults[attr_name] = default
display_map[attr_name] = name
return validators, defaults, display_map
示例2: __init__
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def __init__(self,proto_def):
# Calculate intersection between keys of outgoing messages and incoming
# messages:
if not \
dicts_agree(proto_def.incoming_msgs,proto_def.outgoing_msgs):
raise SerializerError('Incompatible definitions of '
'incoming and outgoing msgs: {}')
self._in_keys = proto_def.incoming_msgs.keys()
self._out_keys = proto_def.outgoing_msgs.keys()
# Collect a dictionary of all the messages:
all_msgs = {}
all_msgs.update(proto_def.incoming_msgs)
all_msgs.update(proto_def.outgoing_msgs)
# Dict between msg_type and MsgDef instance:
self._proto_def = dict()
# Bidirectional dict between msg type and msg name:
self._b_msg_type_name = bidict.bidict()
for msg_type, msg_def in all_msgs.items():
# Initialize msg_def with serializer=self
msg_def_inst = msg_def(self)
self._proto_def[msg_type] = msg_def_inst
# Assign the msg_def's instance name:
self._b_msg_type_name[msg_type] = type(msg_def_inst).__name__
示例3: test_issubclass_bimap
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_issubclass_bimap(bi_cls):
"""All bidict types should subclass :class:`BidirectionalMapping`,
and any class conforming to the interface (e.g. VirtualBimapSubclass)
should be considered a (virtual) subclass too.
"""
assert issubclass(bi_cls, BidirectionalMapping)
示例4: test_issubclass_mapping
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_issubclass_mapping(bi_cls):
"""All bidict types should be :class:`collections.abc.Mapping`s."""
assert issubclass(bi_cls, Mapping)
示例5: test_issubclass_mutablemapping
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_issubclass_mutablemapping(bi_cls):
"""All mutable bidict types should be :class:`collections.abc.MutableMapping`s."""
assert issubclass(bi_cls, MutableMapping)
示例6: test_issubclass_hashable
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_issubclass_hashable(bi_cls):
"""All hashable bidict types should implement :class:`collections.abc.Hashable`."""
assert issubclass(bi_cls, Hashable)
示例7: test_ordered_reversible
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_ordered_reversible(bi_cls):
"""All ordered bidict types should be reversible."""
assert callable(bi_cls.__reversed__)
示例8: test_bimap_inverse_notimplemented
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def test_bimap_inverse_notimplemented():
"""Calling .inverse on a BidirectionalMapping should raise :class:`NotImplementedError`."""
with pytest.raises(NotImplementedError):
# Can't instantiate a BidirectionalMapping that hasn't overridden the abstract methods of
# the interface, so only way to call this implementation is on the class.
BidirectionalMapping.inverse.fget(bidict()) # pylint: disable=no-member
示例9: __init__
# 需要导入模块: import bidict [as 别名]
# 或者: from bidict import bidict [as 别名]
def __init__(self, salt, length, salter=_generate_bit_from_hash):
self.salt = salt
self.cache = bidict({'': ''})
self.length = length
self.fmt = '{{:0{length}b}}'.format(length=length)
self.salter = salter