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
e1ad0af2
Commit
e1ad0af2
authored
5 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[fix]
#59
fix pylint warnings
fix format with black
parent
954f49af
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
Makefile
+3
-3
3 additions, 3 deletions
Makefile
duniterpy/api/client.py
+52
-26
52 additions, 26 deletions
duniterpy/api/client.py
with
55 additions
and
29 deletions
Makefile
+
3
−
3
View file @
e1ad0af2
...
...
@@ -20,9 +20,9 @@ mypy:
# check code errors
pylint
:
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 duniterpy/
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 tests/
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 examples/
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,
W1202,
W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 duniterpy/
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,
W1202,
W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 tests/
pylint
--disable
=
C,R0902,R0903,R0904,R0912,R0913,R0914,R0915,
W1202,
W0613
--enable
=
C0121,C0202,C0321
--jobs
=
0 examples/
# check format
check-format
:
...
...
This diff is collapsed.
Click to expand it.
duniterpy/api/client.py
+
52
−
26
View file @
e1ad0af2
...
...
@@ -274,12 +274,20 @@ class API:
error_data
=
parse_error
(
await
response
.
text
())
raise
DuniterError
(
error_data
)
except
(
TypeError
,
jsonschema
.
ValidationError
):
raise
ValueError
(
'
status code != 200 => %d (%s)
'
%
(
response
.
status
,
(
await
response
.
text
())))
raise
ValueError
(
"
status code != 200 => %d (%s)
"
%
(
response
.
status
,
(
await
response
.
text
()))
)
return
response
async
def
requests
(
self
,
method
:
str
=
'
GET
'
,
path
:
str
=
''
,
data
:
Optional
[
dict
]
=
None
,
_json
:
Optional
[
dict
]
=
None
)
->
ClientResponse
:
async
def
requests
(
self
,
method
:
str
=
"
GET
"
,
path
:
str
=
""
,
data
:
Optional
[
dict
]
=
None
,
_json
:
Optional
[
dict
]
=
None
,
)
->
ClientResponse
:
"""
Generic requests wrapper on aiohttp
...
...
@@ -292,13 +300,13 @@ class API:
url
=
self
.
reverse_url
(
self
.
connection_handler
.
http_scheme
,
path
)
if
data
is
not
None
:
logging
.
debug
(
"
{0} : {1}, data={2}
"
.
format
(
method
,
url
,
data
)
)
logging
.
debug
(
"
%s : %s, data=%s
"
,
method
,
url
,
data
)
elif
_json
is
not
None
:
logging
.
debug
(
"
{0} : {1}, json={2}
"
.
format
(
method
,
url
,
_json
)
)
logging
.
debug
(
"
%s : %s, json=%s
"
,
method
,
url
,
_json
)
# http header to send json body
self
.
headers
[
'
Content-Type
'
]
=
'
application/json; charset=utf-8
'
self
.
headers
[
"
Content-Type
"
]
=
"
application/json; charset=utf-8
"
else
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
method
,
url
)
)
logging
.
debug
(
"
%s : %s
"
,
method
,
url
)
response
=
await
self
.
connection_handler
.
session
.
request
(
method
,
...
...
@@ -307,7 +315,7 @@ class API:
json
=
_json
,
headers
=
self
.
headers
,
proxy
=
self
.
connection_handler
.
proxy
,
timeout
=
15
timeout
=
15
,
)
return
response
...
...
@@ -342,8 +350,12 @@ class Client:
Main class to create an API client
"""
def
__init__
(
self
,
_endpoint
:
Union
[
str
,
endpoint
.
Endpoint
],
session
:
Optional
[
ClientSession
]
=
None
,
proxy
:
Optional
[
str
]
=
None
)
->
None
:
def
__init__
(
self
,
_endpoint
:
Union
[
str
,
endpoint
.
Endpoint
],
session
:
Optional
[
ClientSession
]
=
None
,
proxy
:
Optional
[
str
]
=
None
,
)
->
None
:
"""
Init Client instance
...
...
@@ -370,8 +382,13 @@ class Client:
self
.
session
=
session
self
.
proxy
=
proxy
async
def
get
(
self
,
url_path
:
str
,
params
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
)
->
Any
:
async
def
get
(
self
,
url_path
:
str
,
params
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
,
)
->
Any
:
"""
GET request on endpoint host + url_path
...
...
@@ -403,8 +420,13 @@ class Client:
return
result
async
def
post
(
self
,
url_path
:
str
,
params
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
)
->
Any
:
async
def
post
(
self
,
url_path
:
str
,
params
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
,
)
->
Any
:
"""
POST request on endpoint host + url_path
...
...
@@ -428,15 +450,21 @@ class Client:
await
parse_response
(
response
,
schema
)
# return the chosen type
if
rtype
==
RESPONSE_AIOHTTP
:
return
response
elif
rtype
==
RESPONSE_TEXT
:
return
await
response
.
text
()
result
=
response
# type: Any
if
rtype
==
RESPONSE_TEXT
:
result
=
await
response
.
text
()
elif
rtype
==
RESPONSE_JSON
:
return
await
response
.
json
()
result
=
await
response
.
json
()
return
result
async
def
query
(
self
,
query
:
str
,
variables
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
)
->
Any
:
async
def
query
(
self
,
query
:
str
,
variables
:
Optional
[
dict
]
=
None
,
rtype
:
str
=
RESPONSE_JSON
,
schema
:
Optional
[
dict
]
=
None
,
)
->
Any
:
"""
GraphQL query or mutation request on endpoint
...
...
@@ -446,17 +474,15 @@ class Client:
:param schema: Json Schema to validate response (optional, default None)
:return:
"""
payload
=
{
'
query
'
:
query
}
# type: Dict[str, Union[str, dict]]
payload
=
{
"
query
"
:
query
}
# type: Dict[str, Union[str, dict]]
if
variables
is
not
None
:
payload
[
'
variables
'
]
=
variables
payload
[
"
variables
"
]
=
variables
client
=
API
(
self
.
endpoint
.
conn_handler
(
self
.
session
,
self
.
proxy
))
# get aiohttp response
response
=
await
client
.
requests
(
'
POST
'
,
_json
=
payload
)
response
=
await
client
.
requests
(
"
POST
"
,
_json
=
payload
)
# if schema supplied...
if
schema
is
not
None
:
...
...
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