From bae4e80500b552f7b3658a1a6a158fef02047f58 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Wed, 7 May 2025 11:31:20 +0200 Subject: Remove the existing handler (and unused) in socketserver --- consumer.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'consumer.py') diff --git a/consumer.py b/consumer.py index 9e36dd0..31fd581 100644 --- a/consumer.py +++ b/consumer.py @@ -1,20 +1,22 @@ -from typing import Dict +import time +import abc +from threading import Thread +from queue import Queue, Empty, Full from zope import component, interface +from interfaces import endpoint, configuration +from interfaces.configuration import IConfiguration from interfaces.message import ISocketMessage, Debug @interface.implementer(ISocketMessage) -class Mapping(object): +class Mapping(): """ Send an event requesting a layer change to the endpoint. """ def __init__(self, message): self.content = {"layer": message} -import abc -from threading import Thread -from queue import Queue, Empty, Full class EventConsummer(Thread, metaclass=abc.ABCMeta): """ Thread processing messages. This class does nothing and is intended to @@ -65,9 +67,6 @@ class EventConsummer(Thread, metaclass=abc.ABCMeta): except Full: component.handle(Debug("Ignoring event: queue is full")) -import time -from interfaces import endpoint, configuration -from interfaces.configuration import IConfiguration class SocketMessageConsumer(EventConsummer): """ Provide a handler consuming events and sending them to the endpoint. @@ -128,8 +127,7 @@ class SocketMessageConsumer(EventConsummer): configuration = component.getUtility(IConfiguration) if isinstance(mapping, dict): self._endpoint.send(mapping) - elif isinstance(data, str): - # TODO Query the json from the configuration + elif isinstance(mapping, str): layer = configuration.get(mapping, None) if layer is not None: self._endpoint.send(layer) @@ -137,7 +135,9 @@ class SocketMessageConsumer(EventConsummer): if name is not None: # We received a name to associate the configuration with. # Register the element in the configuration - # TODO use an event configuration[name] = mapping for key in mapping.keys(): - component.handle(Debug("Associating %s with %s" % (name, key))) + # We do not want to log the keycode sent to the keyboard, only + # the name is interresting. We are supposed to have only one, but + # it’s the easer way to log it + component.handle(Debug(f"Associating {name} with {key}")) -- cgit v1.2.3