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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
66917a8f
Commit
66917a8f
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
New token class method to build Conditions
parent
ae3f800f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/grammars/test_output.py
+17
-0
17 additions, 0 deletions
tests/grammars/test_output.py
ucoinpy/grammars/output.py
+27
-0
27 additions, 0 deletions
ucoinpy/grammars/output.py
with
44 additions
and
0 deletions
tests/grammars/test_output.py
+
17
−
0
View file @
66917a8f
...
@@ -58,3 +58,20 @@ class Test_OutputGrammar(unittest.TestCase):
...
@@ -58,3 +58,20 @@ class Test_OutputGrammar(unittest.TestCase):
self
.
assertEqual
(
result
.
left
.
right
.
op
.
name
,
"
AND
"
)
self
.
assertEqual
(
result
.
left
.
right
.
op
.
name
,
"
AND
"
)
self
.
assertEqual
(
result
.
left
.
right
.
right
.
sha_hash
,
"
309BC5E644F797F53E5A2065EAF38A173437F2E6
"
)
self
.
assertEqual
(
result
.
left
.
right
.
right
.
sha_hash
,
"
309BC5E644F797F53E5A2065EAF38A173437F2E6
"
)
self
.
assertEqual
(
pypeg2
.
compose
(
result
,
output
.
Condition
),
condition
)
self
.
assertEqual
(
pypeg2
.
compose
(
result
,
output
.
Condition
),
condition
)
def
test_instanciate_condition
(
self
):
inst
=
output
.
Condition
.
token
(
output
.
SIG
.
token
(
"
HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd
"
),
output
.
Operator
.
token
(
"
OR
"
),
output
.
Condition
.
token
(
output
.
SIG
.
token
(
"
DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV
"
),
output
.
Operator
.
token
(
"
AND
"
),
output
.
XHX
.
token
(
"
309BC5E644F797F53E5A2065EAF38A173437F2E6
"
)
))
condition
=
"
(SIG(HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd) OR (SIG(DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV) AND XHX(309BC5E644F797F53E5A2065EAF38A173437F2E6)))
"
inst
=
pypeg2
.
parse
(
condition
,
output
.
Condition
)
self
.
assertEqual
(
inst
.
left
.
left
.
pubkey
,
"
HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd
"
)
self
.
assertEqual
(
inst
.
left
.
op
.
name
,
"
OR
"
)
self
.
assertEqual
(
inst
.
left
.
right
.
left
.
pubkey
,
"
DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV
"
)
self
.
assertEqual
(
inst
.
left
.
right
.
op
.
name
,
"
AND
"
)
self
.
assertEqual
(
inst
.
left
.
right
.
right
.
sha_hash
,
"
309BC5E644F797F53E5A2065EAF38A173437F2E6
"
)
self
.
assertEqual
(
pypeg2
.
compose
(
inst
,
output
.
Condition
),
condition
)
This diff is collapsed.
Click to expand it.
ucoinpy/grammars/output.py
+
27
−
0
View file @
66917a8f
...
@@ -14,6 +14,12 @@ class Hash(Symbol):
...
@@ -14,6 +14,12 @@ class Hash(Symbol):
class
SIG
(
str
):
class
SIG
(
str
):
grammar
=
"
SIG(
"
,
attr
(
'
pubkey
'
,
Pubkey
),
"
)
"
grammar
=
"
SIG(
"
,
attr
(
'
pubkey
'
,
Pubkey
),
"
)
"
@classmethod
def
token
(
cls
,
pubkey
):
sig
=
cls
()
sig
.
pubkey
=
pubkey
return
sig
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
return
"
SIG({0})
"
.
format
(
self
.
pubkey
)
return
"
SIG({0})
"
.
format
(
self
.
pubkey
)
...
@@ -21,6 +27,12 @@ class SIG(str):
...
@@ -21,6 +27,12 @@ class SIG(str):
class
XHX
(
str
):
class
XHX
(
str
):
grammar
=
"
XHX(
"
,
attr
(
'
sha_hash
'
,
Hash
),
"
)
"
grammar
=
"
XHX(
"
,
attr
(
'
sha_hash
'
,
Hash
),
"
)
"
@classmethod
def
token
(
cls
,
sha_hash
):
xhx
=
cls
()
xhx
.
sha_hash
=
sha_hash
return
xhx
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
return
"
XHX({0})
"
.
format
(
self
.
sha_hash
)
return
"
XHX({0})
"
.
format
(
self
.
sha_hash
)
...
@@ -28,11 +40,26 @@ class XHX(str):
...
@@ -28,11 +40,26 @@ class XHX(str):
class
Operator
(
Keyword
):
class
Operator
(
Keyword
):
grammar
=
Enum
(
K
(
"
AND
"
),
K
(
"
OR
"
))
grammar
=
Enum
(
K
(
"
AND
"
),
K
(
"
OR
"
))
@classmethod
def
token
(
cls
,
keyword
):
op
=
cls
(
keyword
)
return
op
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
return
"
{0}
"
.
format
(
self
.
name
)
return
"
{0}
"
.
format
(
self
.
name
)
class
Condition
(
str
):
class
Condition
(
str
):
@classmethod
def
token
(
cls
,
left
,
op
=
None
,
right
=
None
):
condition
=
cls
()
condition
.
left
=
left
if
op
:
condition
.
op
=
op
if
right
:
condition
.
right
=
right
return
condition
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
def
compose
(
self
,
parser
,
grammar
=
None
,
attr_of
=
None
):
if
type
(
self
.
left
)
is
Condition
:
if
type
(
self
.
left
)
is
Condition
:
left
=
"
({0})
"
.
format
(
parser
.
compose
(
self
.
left
,
grammar
=
grammar
,
attr_of
=
attr_of
))
left
=
"
({0})
"
.
format
(
parser
.
compose
(
self
.
left
,
grammar
=
grammar
,
attr_of
=
attr_of
))
...
...
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