From 94aa766b8f86cff259213b76e729a9bb2ecb5e4a Mon Sep 17 00:00:00 2001 From: Michiel De Witte Date: Wed, 21 Feb 2018 13:23:47 +0100 Subject: [PATCH 1/3] removed forced logging --- coapthon/client/coap.py | 5 ----- coapthon/forward_proxy/coap.py | 5 +---- coapthon/reverse_proxy/coap.py | 6 +----- coapthon/server/coap.py | 5 ----- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/coapthon/client/coap.py b/coapthon/client/coap.py index a9badd8..471282e 100644 --- a/coapthon/client/coap.py +++ b/coapthon/client/coap.py @@ -14,18 +14,13 @@ from coapthon.messages.message import Message from coapthon.messages.request import Request from coapthon.messages.response import Response from coapthon.serializer import Serializer -from coapthon.utils import create_logging import collections __author__ = 'Giacomo Tanganelli' -if not os.path.isfile("logging.conf"): - create_logging() - logger = logging.getLogger(__name__) -logging.config.fileConfig("logging.conf", disable_existing_loggers=False) class CoAP(object): diff --git a/coapthon/forward_proxy/coap.py b/coapthon/forward_proxy/coap.py index 5b42ddb..b448cca 100644 --- a/coapthon/forward_proxy/coap.py +++ b/coapthon/forward_proxy/coap.py @@ -17,15 +17,12 @@ from coapthon.messages.message import Message from coapthon.messages.request import Request from coapthon.resources.resource import Resource from coapthon.serializer import Serializer -from coapthon.utils import Tree, create_logging +from coapthon.utils import Tree __author__ = 'Giacomo Tanganelli' -if not os.path.isfile("logging.conf"): - create_logging() logger = logging.getLogger(__name__) -logging.config.fileConfig("logging.conf", disable_existing_loggers=False) class CoAP(object): diff --git a/coapthon/reverse_proxy/coap.py b/coapthon/reverse_proxy/coap.py index 50db0d2..61ba364 100644 --- a/coapthon/reverse_proxy/coap.py +++ b/coapthon/reverse_proxy/coap.py @@ -21,16 +21,12 @@ from coapthon.messages.request import Request from coapthon.resources.remoteResource import RemoteResource from coapthon.resources.resource import Resource from coapthon.serializer import Serializer -from coapthon.utils import Tree, create_logging +from coapthon.utils import Tree __author__ = 'Giacomo Tanganelli' -if not os.path.isfile("logging.conf"): - create_logging() - logger = logging.getLogger(__name__) -logging.config.fileConfig("logging.conf", disable_existing_loggers=False) class CoAP(object): diff --git a/coapthon/server/coap.py b/coapthon/server/coap.py index e2b4e5e..5a52102 100644 --- a/coapthon/server/coap.py +++ b/coapthon/server/coap.py @@ -17,18 +17,13 @@ from coapthon.messages.response import Response from coapthon.resources.resource import Resource from coapthon.serializer import Serializer from coapthon.utils import Tree -from coapthon.utils import create_logging import collections __author__ = 'Giacomo Tanganelli' -if not os.path.isfile("logging.conf"): - create_logging() - logger = logging.getLogger(__name__) -logging.config.fileConfig("logging.conf", disable_existing_loggers=False) class CoAP(object): From e9a08fa1d9e2b06c96841e97309d14fae74e317c Mon Sep 17 00:00:00 2001 From: Michiel De Witte Date: Fri, 2 Mar 2018 15:42:22 +0100 Subject: [PATCH 2/3] set receiver thread as daemon --- coapthon/client/coap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/coapthon/client/coap.py b/coapthon/client/coap.py index 471282e..d2bed4c 100644 --- a/coapthon/client/coap.py +++ b/coapthon/client/coap.py @@ -169,6 +169,7 @@ class CoAP(object): if self._receiver_thread is None or not self._receiver_thread.isAlive(): self._receiver_thread = threading.Thread(target=self.receive_datagram) + self._receiver_thread.daemon = True self._receiver_thread.start() def _start_retransmission(self, transaction, message): From f81f415da8ce6bdde1541a6a2bd70b07e6a38ba6 Mon Sep 17 00:00:00 2001 From: office-gateway Date: Mon, 5 Mar 2018 16:41:11 +0100 Subject: [PATCH 3/3] Let the outbound payload be binary --- coapthon/serializer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/coapthon/serializer.py b/coapthon/serializer.py index c85445d..f938eeb 100644 --- a/coapthon/serializer.py +++ b/coapthon/serializer.py @@ -219,8 +219,12 @@ class Serializer(object): fmt += "B" values.append(defines.PAYLOAD_MARKER) - fmt += str(len(bytes(payload, "utf-8"))) + "s" - values.append(bytes(payload, "utf-8")) + if isinstance(payload, bytes): + fmt += str(len(payload)) + "s" + values.append(payload) + else: + fmt += str(len(bytes(payload, "utf-8"))) + "s" + values.append(bytes(payload, "utf-8")) # for b in str(payload): # fmt += "c" # values.append(bytes(b, "utf-8"))