Commit b39fabd7 authored by Vincent Texier's avatar Vincent Texier

merge branch 0.43.5

parents c03343a1 0ccbd5eb
......@@ -18,7 +18,7 @@
__author__ = 'Caner Candan & inso & vit'
__version__ = '0.43.4'
__version__ = '0.43.5'
__nonsense__ = 'duniter'
from . import api, documents, key
\ No newline at end of file
......@@ -2,6 +2,7 @@ import re
import attr
from ..document import MalformedDocumentError
from ..block import BlockUID
from ...constants import WS2P_PUBLIC_PREFIX_REGEX, WS2P_PRIVATE_PREFIX_REGEX, WS2P_HEAD_REGEX, \
PUBKEY_REGEX, SIGNATURE_REGEX, WS2PID_REGEX, BLOCK_UID_REGEX
......@@ -43,13 +44,16 @@ class Head:
@classmethod
def from_inline(cls, inline):
data = Head.re_inline.match(inline)
head = data.group(0).split(':')
if len(head) == 2:
version = int(head[1])
else:
version = 0
return cls(version)
try:
data = Head.re_inline.match(inline)
head = data.group(0).split(':')
if len(head) == 2:
version = int(head[1])
else:
version = 0
return cls(version)
except AttributeError:
raise MalformedDocumentError("Head")
def __str__(self):
return "HEAD" if self.version == 0 else "HEAD:{}".format(str(self.version))
......@@ -79,14 +83,16 @@ class HeadV0:
@classmethod
def from_inline(cls, inline, signature):
data = HeadV0.re_inline.match(inline)
api = API.from_inline(data.group(1))
head = Head.from_inline(data.group(2))
pubkey = data.group(3)
blockstamp = BlockUID.from_str(data.group(4))
offload = data.group(5)
return cls(signature, api, head, pubkey, blockstamp), offload
try:
data = HeadV0.re_inline.match(inline)
api = API.from_inline(data.group(1))
head = Head.from_inline(data.group(2))
pubkey = data.group(3)
blockstamp = BlockUID.from_str(data.group(4))
offload = data.group(5)
return cls(signature, api, head, pubkey, blockstamp), offload
except AttributeError:
raise MalformedDocumentError("HeadV0")
def inline(self):
values = (str(v) for v in attr.astuple(self, recurse=False,
......@@ -110,14 +116,17 @@ class HeadV1:
@classmethod
def from_inline(cls, inline, signature):
v0, offload = HeadV0.from_inline(inline, signature)
data = HeadV1.re_inline.match(offload)
ws2pid = data.group(1)
software = data.group(2)
software_version = data.group(3)
pow_prefix = int(data.group(4))
offload = data.group(5)
return cls(v0, ws2pid, software, software_version, pow_prefix), offload
try:
v0, offload = HeadV0.from_inline(inline, signature)
data = HeadV1.re_inline.match(offload)
ws2pid = data.group(1)
software = data.group(2)
software_version = data.group(3)
pow_prefix = int(data.group(4))
offload = data.group(5)
return cls(v0, ws2pid, software, software_version, pow_prefix), offload
except AttributeError:
raise MalformedDocumentError("HeadV1")
def inline(self):
values = [str(v) for v in attr.astuple(self, True, filter=attr.filters.exclude(attr.fields(HeadV1).v0))]
......@@ -148,11 +157,14 @@ class HeadV2:
@classmethod
def from_inline(cls, inline, signature):
v1, offload = HeadV1.from_inline(inline, signature)
data = HeadV2.re_inline.match(offload)
free_member_room = int(data.group(1))
free_mirror_room = int(data.group(2))
return cls(v1, free_member_room, free_mirror_room), ""
try:
v1, offload = HeadV1.from_inline(inline, signature)
data = HeadV2.re_inline.match(offload)
free_member_room = int(data.group(1))
free_mirror_room = int(data.group(2))
return cls(v1, free_member_room, free_mirror_room), ""
except AttributeError:
raise MalformedDocumentError("HeadV2")
def inline(self):
values = (str(v) for v in attr.astuple(self, True, filter=attr.filters.exclude(attr.fields(HeadV2).v1)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment