canoser
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: canoser | ||
| Version: 0.7.10 | ||
| Version: 0.7.11 | ||
| Summary: A python implementation of the LCS(Libra Canonical Serialization) for the Libra network. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/yuan-xy/canoser-python.git |
@@ -5,3 +5,3 @@ from canoser.types import type_mapping | ||
| class DelegateT: | ||
| class DelegateT(Base): | ||
| delegate_type = 'delegate' | ||
@@ -8,0 +8,0 @@ |
| import struct | ||
| from random import randint | ||
| from canoser.base import Base | ||
@@ -64,2 +65,4 @@ from struct import pack, unpack | ||
| def check_value(cls, value): | ||
| if isinstance(value, bool): | ||
| raise TypeError(f"{s} is not a integer") | ||
| if not isinstance(value, int): | ||
@@ -83,2 +86,5 @@ raise TypeError(f"{value} is not instance of <int>.") | ||
| @classmethod | ||
| def random(cls): | ||
| return randint(cls.min_value, cls.max_value) | ||
@@ -85,0 +91,0 @@ class Int8(IntType): |
+12
-0
@@ -6,2 +6,3 @@ from canoser.base import Base | ||
| from canoser.struct import TypedProperty | ||
| import json | ||
@@ -106,1 +107,12 @@ #TODO: how to support discontinuous index in enum | ||
| return {self.enum_name : jj} | ||
| def __str__(self): | ||
| return self.to_json(indent=2) | ||
| def __repr__(self): | ||
| return self.__class__.__qualname__ + self.to_json(indent=2) | ||
| def to_json(self, sort_keys=False, indent=4): | ||
| amap = self.to_json_serializable() | ||
| return json.dumps(amap, sort_keys=sort_keys, indent=indent) | ||
@@ -1,1 +0,1 @@ | ||
| version = "0.7.10" | ||
| version = "0.7.11" |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: canoser | ||
| Version: 0.7.10 | ||
| Version: 0.7.11 | ||
| Summary: A python implementation of the LCS(Libra Canonical Serialization) for the Libra network. | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/yuan-xy/canoser-python.git |
@@ -32,1 +32,11 @@ from canoser import * | ||
| class Bools(DelegateT): | ||
| delegate_type = [bool] | ||
| def test_delegate(): | ||
| x = [True, False, True] | ||
| bs = Bools.encode(x) | ||
| assert bs == b'\x03\x00\x00\x00\x01\x00\x01' | ||
| x2 = Bools.deserialize(bs) | ||
| assert x == x2 |
@@ -136,1 +136,8 @@ import pytest | ||
| assert x3.value == [['ab', 'c'], ['d'], []] | ||
| assert x2.__repr__() == """MyEnumWrap{ | ||
| "opt3": [ | ||
| [ | ||
| "abc" | ||
| ] | ||
| ] | ||
| }""" |
@@ -6,2 +6,7 @@ from canoser import * | ||
| def test_random(): | ||
| for _x in range(10000): | ||
| rand = Uint8.random() | ||
| assert rand >=0 and rand <256 | ||
| def test_checked_add(): | ||
@@ -24,3 +29,6 @@ assert 255 == Uint8.checked_add(254, 1) | ||
| Uint8.int_unsafe("256") | ||
| with pytest.raises(Exception): | ||
| Uint8.check_value(True) | ||
| def test_str_to_int_strict(): | ||
@@ -27,0 +35,0 @@ assert 0 == Uint8.int_safe(0) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
109217
1%1636
2.19%