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
4eefa835
Commit
4eefa835
authored
6 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
issue
#56
WIP - Client(_endpoint) accept Endpoint instances
parent
0049a93c
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
duniterpy/api/client.py
+15
-7
15 additions, 7 deletions
duniterpy/api/client.py
duniterpy/api/endpoint.py
+17
-8
17 additions, 8 deletions
duniterpy/api/endpoint.py
with
32 additions
and
15 deletions
duniterpy/api/client.py
+
15
−
7
View file @
4eefa835
# Authors:
# Caner Candan <caner@candan.fr>, http://caner.candan.fr
# Inso <insomniak.fr at gmail.com>
from
typing
import
Callable
# vit
import
json
import
logging
from
typing
import
Callable
,
Union
import
aiohttp
import
jsonschema
from
.errors
import
DuniterError
import
duniterpy.api.endpoint
as
endpoint
from
.errors
import
DuniterError
logger
=
logging
.
getLogger
(
"
duniter
"
)
...
...
@@ -177,7 +180,9 @@ class Client:
"""
Main class to create an API client
"""
def
__init__
(
self
,
_endpoint
:
str
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
):
def
__init__
(
self
,
_endpoint
:
Union
[
str
,
endpoint
.
Endpoint
],
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
):
"""
Init Client instance
...
...
@@ -185,8 +190,11 @@ class Client:
:param session: Aiohttp client session (optional, default None)
:param proxy: Proxy server as hostname:port
"""
if
type
(
endpoint
)
is
str
:
# Endpoint Protocol detection
self
.
endpoint
=
endpoint
.
endpoint
(
_endpoint
)
else
:
self
.
endpoint
=
_endpoint
# if no user session...
if
session
is
None
:
...
...
This diff is collapsed.
Click to expand it.
duniterpy/api/endpoint.py
+
17
−
8
View file @
4eefa835
import
re
import
aiohttp
from
.constants
import
*
from
..documents
import
MalformedDocumentError
...
...
@@ -7,7 +9,8 @@ from ..documents import MalformedDocumentError
class
ConnectionHandler
:
"""
Helper class used by other API classes to ease passing server connection information.
"""
def
__init__
(
self
,
http_scheme
:
str
,
ws_scheme
:
str
,
server
:
str
,
port
:
int
,
path
:
str
=
""
,
proxy
:
str
=
None
,
session
:
aiohttp
.
ClientSession
=
None
):
def
__init__
(
self
,
http_scheme
:
str
,
ws_scheme
:
str
,
server
:
str
,
port
:
int
,
path
:
str
=
""
,
proxy
:
str
=
None
,
session
:
aiohttp
.
ClientSession
=
None
):
"""
Init instance of connection handler
...
...
@@ -39,6 +42,9 @@ class Endpoint:
def
inline
(
self
)
->
str
:
raise
NotImplementedError
(
"
inline() is not implemented
"
)
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
raise
NotImplementedError
(
"
conn_handler is not implemented
"
)
def
__str__
(
self
)
->
str
:
raise
NotImplementedError
(
"
__str__ is not implemented
"
)
...
...
@@ -79,6 +85,9 @@ class UnknownEndpoint(Endpoint):
doc
+=
"
{0}
"
.
format
(
p
)
return
doc
def
conn_handler
(
self
,
session
:
aiohttp
.
ClientSession
=
None
,
proxy
:
str
=
None
)
->
ConnectionHandler
:
return
ConnectionHandler
(
""
,
""
,
""
,
0
,
""
)
def
__str__
(
self
)
->
str
:
return
"
{0} {1}
"
.
format
(
self
.
api
,
'
'
.
join
([
"
{0}
"
.
format
(
p
)
for
p
in
self
.
properties
]))
...
...
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