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
420259dd
Commit
420259dd
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#52
add type hinting to peer module
parent
7a449c47
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniterpy/documents/peer.py
+35
-7
35 additions, 7 deletions
duniterpy/documents/peer.py
with
35 additions
and
7 deletions
duniterpy/documents/peer.py
+
35
−
7
View file @
420259dd
import
re
import
re
from
typing
import
TypeVar
,
List
,
Type
from
duniterpy.api.endpoint
import
endpoint
from
duniterpy.api.endpoint
import
endpoint
,
Endpoint
from
.document
import
Document
from
.document
import
Document
,
MalformedDocumentError
from
.block_uid
import
BlockUID
from
.block_uid
import
BlockUID
from
..constants
import
BLOCK_HASH_REGEX
,
PUBKEY_REGEX
from
..constants
import
BLOCK_HASH_REGEX
,
PUBKEY_REGEX
# required to type hint cls in classmethod
PeerType
=
TypeVar
(
'
PeerType
'
,
bound
=
'
Peer
'
)
class
Peer
(
Document
):
class
Peer
(
Document
):
"""
"""
...
@@ -35,8 +39,18 @@ class Peer(Document):
...
@@ -35,8 +39,18 @@ class Peer(Document):
"
Endpoints
"
:
re_endpoints
"
Endpoints
"
:
re_endpoints
}}
}}
def
__init__
(
self
,
version
,
currency
,
pubkey
,
block_uid
,
def
__init__
(
self
,
version
:
int
,
currency
:
str
,
pubkey
:
str
,
block_uid
:
BlockUID
,
endpoints
,
signature
):
endpoints
:
List
[
Endpoint
],
signature
:
str
)
->
None
:
"""
Init Peer instance
:param version: Version of the document
:param currency: Name of the currency
:param pubkey: Public key of the issuer
:param block_uid: BlockUID instance timestamp
:param endpoints: List of endpoints string
:param signature: Signature of the document
"""
super
().
__init__
(
version
,
currency
,
[
signature
])
super
().
__init__
(
version
,
currency
,
[
signature
])
self
.
pubkey
=
pubkey
self
.
pubkey
=
pubkey
...
@@ -44,7 +58,13 @@ class Peer(Document):
...
@@ -44,7 +58,13 @@ class Peer(Document):
self
.
endpoints
=
endpoints
self
.
endpoints
=
endpoints
@classmethod
@classmethod
def
from_signed_raw
(
cls
,
raw
):
def
from_signed_raw
(
cls
:
Type
[
PeerType
],
raw
:
str
)
->
PeerType
:
"""
Return a Peer instance from a signed raw format string
:param raw: Signed raw format string
:return:
"""
lines
=
raw
.
splitlines
(
True
)
lines
=
raw
.
splitlines
(
True
)
n
=
0
n
=
0
...
@@ -71,11 +91,19 @@ class Peer(Document):
...
@@ -71,11 +91,19 @@ class Peer(Document):
endpoints
.
append
(
endpoint
(
lines
[
n
]))
endpoints
.
append
(
endpoint
(
lines
[
n
]))
n
+=
1
n
+=
1
signature
=
Peer
.
re_signature
.
match
(
lines
[
n
]).
group
(
1
)
data
=
Peer
.
re_signature
.
match
(
lines
[
n
])
if
data
is
None
:
raise
MalformedDocumentError
(
"
Peer
"
)
signature
=
data
.
group
(
1
)
return
cls
(
version
,
currency
,
pubkey
,
block_uid
,
endpoints
,
signature
)
return
cls
(
version
,
currency
,
pubkey
,
block_uid
,
endpoints
,
signature
)
def
raw
(
self
):
def
raw
(
self
)
->
str
:
"""
Return a raw format string of the Peer document
:return:
"""
doc
=
"""
Version: {0}
doc
=
"""
Version: {0}
Type: Peer
Type: Peer
Currency: {1}
Currency: {1}
...
...
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