Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
0059bd9a
Commit
0059bd9a
authored
6 years ago
by
inso
Committed by
inso
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix WS2P parsing
parent
619f1f3e
No related branches found
No related tags found
1 merge request
!45
Add README.rst for PyPI
Pipeline
#2726
passed
6 years ago
Stage: github-sync
Stage: build
Stage: test
Stage: release
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/documents/ws2p/heads.py
+43
-29
43 additions, 29 deletions
duniterpy/documents/ws2p/heads.py
with
43 additions
and
29 deletions
duniterpy/documents/ws2p/heads.py
+
43
−
29
View file @
0059bd9a
import
attr
import
re
from
..document
import
MalformedDocumentError
from
..block
import
BlockUID
from
..constants
import
ws2p_public_prefix_regex
,
ws2p_private_prefix_regex
,
\
pubkey_regex
,
signature_regex
,
ws2pid_regex
,
block_uid_regex
,
ws2p_head_regex
...
...
@@ -43,6 +44,7 @@ class Head:
@classmethod
def
from_inline
(
cls
,
inline
):
try
:
data
=
Head
.
re_inline
.
match
(
inline
)
head
=
data
.
group
(
0
).
split
(
'
:
'
)
if
len
(
head
)
==
2
:
...
...
@@ -50,6 +52,8 @@ class Head:
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,6 +83,7 @@ class HeadV0:
@classmethod
def
from_inline
(
cls
,
inline
,
signature
):
try
:
data
=
HeadV0
.
re_inline
.
match
(
inline
)
api
=
API
.
from_inline
(
data
.
group
(
1
))
head
=
Head
.
from_inline
(
data
.
group
(
2
))
...
...
@@ -87,6 +92,8 @@ class HeadV0:
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
,
...
...
@@ -101,7 +108,7 @@ class HeadV1:
.
format
(
ws2pid
=
ws2pid_regex
,
software
=
"
[A-Za-z-_]+
"
,
software_version
=
"
[0-9]+[.][0-9]+[.][0-9]+
"
,
software_version
=
"
[0-9]+[.][0-9]+[.][0-9]+
-?[A-Za-z0-9\.]+
"
,
pow_prefix
=
"
[0-9]+
"
))
v0
=
attr
.
ib
(
type
=
HeadV0
)
...
...
@@ -112,7 +119,9 @@ class HeadV1:
@classmethod
def
from_inline
(
cls
,
inline
,
signature
):
try
:
v0
,
offload
=
HeadV0
.
from_inline
(
inline
,
signature
)
inline
=
HeadV1
.
re_inline
data
=
HeadV1
.
re_inline
.
match
(
offload
)
ws2pid
=
data
.
group
(
1
)
software
=
data
.
group
(
2
)
...
...
@@ -120,6 +129,8 @@ class HeadV1:
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
))]
...
...
@@ -150,11 +161,14 @@ class HeadV2:
@classmethod
def
from_inline
(
cls
,
inline
,
signature
):
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
)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment