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


Python rlp.Serializable方法代码示例

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


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

示例1: gen_header

# 需要导入模块: import rlp [as 别名]
# 或者: from rlp import Serializable [as 别名]
def gen_header(testcases):
    header = f'''"""DO NOT MODIFY: Tests generated from `tests/` with {sys.argv[0]}"""
import unittest
from binascii import unhexlify
from manticore import ManticoreEVM, Plugin
from manticore.utils import config
'''

    if any("logs" in testcase for testcase in testcases.values()):
        body += """
import sha3
import rlp
from rlp.sedes import (
    CountableList,
    BigEndianInt,
    Binary,
)
class Log(rlp.Serializable):
    fields = [
        ('address', Binary.fixed_length(20, allow_empty=True)),
        ('topics', CountableList(BigEndianInt(32))),
        ('data', Binary())
    ]
"""

    header += """consts = config.get_group('core')
consts.mprocessing = consts.mprocessing.single
consts = config.get_group('evm')
consts.oog = 'pedantic'

class EVMTest(unittest.TestCase):
    # https://nose.readthedocs.io/en/latest/doc_tests/test_multiprocess/multiprocess.html#controlling-distribution
    _multiprocess_can_split_ = True
    # https://docs.python.org/3.7/library/unittest.html#unittest.TestCase.maxDiff
    maxDiff = None

"""
    return header 
开发者ID:trailofbits,项目名称:manticore,代码行数:40,代码来源:make_VMTests.py

示例2: diff_rlp_object

# 需要导入模块: import rlp [as 别名]
# 或者: from rlp import Serializable [as 别名]
def diff_rlp_object(left: BaseBlock,
                    right: BaseBlock) -> Optional[Iterable[Tuple[str, str, str]]]:
    if left != right:
        rlp_type = type(left)

        for field_name, field_type in rlp_type._meta.fields:
            left_value = getattr(left, field_name)
            right_value = getattr(right, field_name)
            if isinstance(field_type, type) and issubclass(field_type, rlp.Serializable):
                sub_diff = diff_rlp_object(left_value, right_value)
                for sub_field_name, sub_left_value, sub_right_value in sub_diff:
                    yield (
                        f"{field_name}.{sub_field_name}",
                        sub_left_value,
                        sub_right_value,
                    )
            elif isinstance(field_type, (rlp.sedes.List, rlp.sedes.CountableList)):
                if tuple(left_value) != tuple(right_value):
                    yield (
                        field_name,
                        left_value,
                        right_value,
                    )
            elif left_value != right_value:
                yield (
                    field_name,
                    left_value,
                    right_value,
                )
            else:
                continue 
开发者ID:ethereum,项目名称:py-evm,代码行数:33,代码来源:rlp.py

示例3: decode_all

# 需要导入模块: import rlp [as 别名]
# 或者: from rlp import Serializable [as 别名]
def decode_all(rlp: bytes,
               sedes: rlp.Serializable = None,
               recursive_cache: bool = False,
               **kwargs: Any) -> Iterable[Any]:
    """Decode multiple RLP encoded object.

    If the deserialized result `obj` has an attribute :attr:`_cached_rlp` (e.g. if `sedes` is a
    subclass of :class:`rlp.Serializable`) it will be set to `rlp`, which will improve performance
    on subsequent :func:`rlp.encode` calls. Bear in mind however that `obj` needs to make sure that
    this value is updated whenever one of its fields changes or prevent such changes entirely
    (:class:`rlp.sedes.Serializable` does the latter).

    :param sedes: an object implementing a function ``deserialize(code)`` which will be applied
                  after decoding, or ``None`` if no deserialization should be performed
    :param **kwargs: additional keyword arguments that will be passed to the deserializer
    :param strict: if false inputs that are longer than necessary don't cause an exception
    :returns: the decoded and maybe deserialized Python object
    :raises: :exc:`rlp.DecodingError` if the input string does not end after the root item and
             `strict` is true
    :raises: :exc:`rlp.DeserializationError` if the deserialization fails
    """
    if not is_bytes(rlp):
        raise DecodingError('Can only decode RLP bytes, got type %s' % type(rlp).__name__, rlp)

    end = 0
    rlp_length = len(rlp)

    while rlp_length - end > 0:
        try:
            item, per_item_rlp, end = consume_item(rlp, end)
        except IndexError:
            raise DecodingError('RLP string too short', rlp)
        if sedes:
            obj = sedes.deserialize(item, **kwargs)
            if is_sequence(obj) or hasattr(obj, '_cached_rlp'):
                _apply_rlp_cache(obj, per_item_rlp, recursive_cache)
            yield obj
        else:
            yield item 
开发者ID:ethereum,项目名称:trinity,代码行数:41,代码来源:rlp_decode.py


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