Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 2f55e6b3 authored by Moul's avatar Moul
Browse files

[enh] #7, #161: Use a singleton decorator for ClientInstance and EndPoint

- Add a singleton decorator definition
parent a4c3ba74
......@@ -23,6 +23,7 @@ import urllib.request
import logging
from sys import exit, stderr
from commandlines import Command
from duniterpy.api.client import Client
from silkaj.constants import (
......@@ -85,15 +86,19 @@ def parse_endpoints(rep):
return endpoints
class EndPoint(object):
__instance = None
def singleton(class_):
instances = {}
def getinstance(*args, **kwargs):
if class_ not in instances:
instances[class_] = class_(*args, **kwargs)
return instances[class_]
return getinstance
# Try to inheritate this part for all singleton classes
def __new__(cls):
if EndPoint.__instance is None:
EndPoint.__instance = object.__new__(cls)
return EndPoint.__instance
class EndPoint(object):
def __init__(self):
cli_args = Command()
ep = dict()
......@@ -116,6 +121,12 @@ class EndPoint(object):
self.BMA_ENDPOINT = " ".join([api, ep["domain"], ep["port"]])
class ClientInstance(object):
def __init__(self):
self.client = Client(EndPoint().BMA_ENDPOINT)
def parse_endpoint(rep):
rep: raw endpoint, sep: split endpoint
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment