canoser
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: canoser | ||
| Version: 0.7.9 | ||
| Version: 0.7.10 | ||
| 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 |
+22
-11
| import struct | ||
| from canoser.base import Base | ||
| from struct import pack, unpack | ||
| from_bytes = int.from_bytes | ||
@@ -12,7 +14,15 @@ class IntType(Base): | ||
| def encode(cls, value): | ||
| return struct.pack(cls.pack_str, value) | ||
| return pack(cls.pack_str, value) | ||
| @classmethod | ||
| def encode_slow(cls, value): | ||
| return value.to_bytes(cls.byte_lens, byteorder="little", signed=cls.signed) | ||
| @classmethod | ||
| def decode_bytes_slow(cls, bytes): | ||
| return unpack(cls.pack_str, bytes)[0] | ||
| @classmethod | ||
| def decode_bytes(cls, bytes): | ||
| return struct.unpack(cls.pack_str, bytes)[0] | ||
| return from_bytes(bytes, byteorder='little', signed=cls.signed) | ||
@@ -79,2 +89,3 @@ @classmethod | ||
| min_value = -128 | ||
| signed = True | ||
@@ -86,2 +97,3 @@ class Int16(IntType): | ||
| min_value = -32768 | ||
| signed = True | ||
@@ -93,2 +105,3 @@ class Int32(IntType): | ||
| min_value = -2147483648 | ||
| signed = True | ||
@@ -100,2 +113,3 @@ class Int64(IntType): | ||
| min_value = -9223372036854775808 | ||
| signed = True | ||
@@ -108,2 +122,3 @@ | ||
| min_value = 0 | ||
| signed = False | ||
@@ -115,2 +130,3 @@ class Uint16(IntType): | ||
| min_value = 0 | ||
| signed = False | ||
@@ -122,2 +138,3 @@ class Uint32(IntType): | ||
| min_value = 0 | ||
| signed = False | ||
@@ -129,2 +146,3 @@ class Uint64(IntType): | ||
| min_value = 0 | ||
| signed = False | ||
@@ -136,2 +154,3 @@ | ||
| min_value = -170141183460469231731687303715884105728 | ||
| signed = True | ||
@@ -142,8 +161,4 @@ @classmethod | ||
| @classmethod | ||
| def decode_bytes(cls, bytes): | ||
| return int.from_bytes(bytes, byteorder='little', signed=True) | ||
| class Uint128(IntType): | ||
@@ -153,2 +168,3 @@ byte_lens = 16 | ||
| min_value = 0 | ||
| signed = False | ||
@@ -159,6 +175,1 @@ @classmethod | ||
| @classmethod | ||
| def decode_bytes(cls, bytes): | ||
| return int.from_bytes(bytes, byteorder='little', signed=False) | ||
@@ -44,3 +44,8 @@ from canoser.base import Base | ||
| #__getattr__ only gets called for attributes that don't actually exist. | ||
| #If you set an attribute directly, referencing that attribute will retrieve it without calling __getattr__. | ||
| #If you need to catch every attribute regardless whether it exists or not, use __getattribute__ instead. | ||
| def __getattr__(self, name): | ||
| if name == '_index': | ||
| return None | ||
| try: | ||
@@ -47,0 +52,0 @@ return self._index == self.__class__.get_index(name) |
@@ -1,1 +0,1 @@ | ||
| version = "0.7.9" | ||
| version = "0.7.10" |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: canoser | ||
| Version: 0.7.9 | ||
| Version: 0.7.10 | ||
| 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 |
+16
-0
| import pytest | ||
| import pdb | ||
| from copy import copy, deepcopy | ||
| from canoser import * | ||
@@ -112,2 +113,3 @@ | ||
| x = EStruct2(MyEnum('opt3', [['ab', 'c'], ['d'], []])) | ||
| deepcopy(x) | ||
| sx = x.serialize() | ||
@@ -121,1 +123,15 @@ assert sx == b'\x01\x00\x00\x00\x03\x00\x00\x00' +\ | ||
| class MyEnumWrap(MyEnum): | ||
| pass | ||
| def test_enum_wrap(): | ||
| x1 = MyEnumWrap('opt1') | ||
| x2 = MyEnumWrap('opt3', [['ab', 'c'], ['d'], []]) | ||
| assert x2.value == [['ab', 'c'], ['d'], []] | ||
| assert x2.opt3 == True | ||
| assert x2.opt1 == False | ||
| x3 = copy(x2) | ||
| x2.value = [['abc']] | ||
| assert x2.opt3 == True | ||
| assert x2.value == [['abc']] | ||
| assert x3.value == [['ab', 'c'], ['d'], []] |
@@ -16,2 +16,4 @@ import pytest | ||
| s3 = Stock(name='ACME', shares=50) | ||
| s33 = Stock(shares=50, name='ACME') | ||
| assert s3 == s33 | ||
| s6 = Stock(shares=50) | ||
@@ -18,0 +20,0 @@ with pytest.raises(TypeError): |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
108133
1.06%1601
2.17%