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
be1199be
Commit
be1199be
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Parse errors
parent
23a08a2a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
_ucoinpy_test/api/test_bma.py
+9
-0
9 additions, 0 deletions
_ucoinpy_test/api/test_bma.py
ucoinpy/__init__.py
+1
-1
1 addition, 1 deletion
ucoinpy/__init__.py
ucoinpy/api/bma/__init__.py
+27
-0
27 additions, 0 deletions
ucoinpy/api/bma/__init__.py
with
37 additions
and
1 deletion
_ucoinpy_test/api/test_bma.py
+
9
−
0
View file @
be1199be
...
...
@@ -19,3 +19,12 @@ class Test_BMA_API(unittest.TestCase):
endpoint
=
BMAEndpoint
(
None
,
None
,
"
2001:0db8:0000:85a3:0000:0000:ac1f:8001
"
,
9092
)
api
=
API
(
endpoint
.
conn_handler
(),
"
any
"
)
self
.
assertEqual
(
api
.
reverse_url
(
"
http
"
,
"
/test/url
"
),
"
http://2001:0db8:0000:85a3:0000:0000:ac1f:8001:9092/any/test/url
"
)
def
test_parse_error
(
self
):
api
=
API
(
None
,
"
any
"
)
error
=
api
.
parse_error
(
"""
{
"
ucode
"
: 1005,
"
message
"
:
"
Document has unkown fields or wrong line ending format
"
}
"""
)
self
.
assertEqual
(
error
[
"
ucode
"
],
1005
)
self
.
assertEqual
(
error
[
"
message
"
],
"
Document has unkown fields or wrong line ending format
"
)
This diff is collapsed.
Click to expand it.
ucoinpy/__init__.py
+
1
−
1
View file @
be1199be
...
...
@@ -21,7 +21,7 @@ PROTOCOL_VERSION="1"
MANAGED_API
=
[
"
BASIC_MERKLED_API
"
]
__author__
=
'
Caner Candan & inso
'
__version__
=
'
0.14.
0
'
__version__
=
'
0.14.
1
'
__nonsense__
=
'
uCoin
'
from
.
import
api
,
documents
,
key
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ucoinpy/api/bma/__init__.py
+
27
−
0
View file @
be1199be
...
...
@@ -46,6 +46,19 @@ class ConnectionHandler(object):
class
API
(
object
):
"""
APIRequest is a class used as an interface. The intermediate derivated classes are the modules and the leaf classes are the API requests.
"""
error_schema
=
{
"
type
"
:
"
object
"
,
"
properties
"
:
{
"
ucode
"
:
{
"
type
"
:
"
number
"
},
"
message
"
:
{
"
type
"
:
"
string
"
}
},
"
required
"
:
[
"
ucode
"
,
"
message
"
]
}
def
__init__
(
self
,
connection_handler
,
module
):
"""
Asks a module in order to create the url used then by derivated classes.
...
...
@@ -113,6 +126,20 @@ class API(object):
except
TypeError
:
raise
jsonschema
.
ValidationError
(
"
Could not parse json
"
)
def
parse_error
(
self
,
text
):
"""
Validate and parse the BMA answer from websocket
:param str text: the bma error
:return: the json data
"""
try
:
data
=
json
.
loads
(
text
)
jsonschema
.
validate
(
data
,
self
.
error_schema
)
return
data
except
TypeError
:
raise
jsonschema
.
ValidationError
(
"
Could not parse json
"
)
async
def
parse_response
(
self
,
response
):
"""
Validate and parse the BMA answer
...
...
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