From 1cd8d33f0826fd2daa2f7ca1dcc287ab91062783 Mon Sep 17 00:00:00 2001 From: jan iversen Date: Wed, 14 Jun 2023 14:16:35 +0200 Subject: [PATCH] Remove handler= for server classes. (#1602) --- API_changes.rst | 1 + examples/server_async.py | 4 ---- examples/server_sync.py | 4 ---- pymodbus/server/async_io.py | 22 ++++------------------ 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/API_changes.rst b/API_changes.rst index 3b95e708c..79d3fee46 100644 --- a/API_changes.rst +++ b/API_changes.rst @@ -6,6 +6,7 @@ PyModbus - API changes. Version 3.4.0 ------------- - ModbusClient .connect() returns True/False (connected or not) +- ModbueServer handler= no longer accepted ------------- Version 3.3.1 diff --git a/examples/server_async.py b/examples/server_async.py index 9f0b683f2..1458ecd75 100755 --- a/examples/server_async.py +++ b/examples/server_async.py @@ -154,7 +154,6 @@ async def run_async_server(args): address=address, # listen address # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session allow_reuse_address=True, # allow the reuse of an address # ignore_missing_slaves=True, # ignore request to a missing slave # broadcast_enable=False, # treat slave_id 0 as broadcast address, @@ -169,7 +168,6 @@ async def run_async_server(args): address=address, # listen address # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session # ignore_missing_slaves=True, # ignore request to a missing slave # broadcast_enable=False, # treat slave_id 0 as broadcast address, # timeout=1, # waiting time for request to complete @@ -185,7 +183,6 @@ async def run_async_server(args): port=args.port, # serial port # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session # stopbits=1, # The number of stop bits to use # bytesize=8, # The bytesize of the serial messages # parity="N", # Which kind of parity to use @@ -205,7 +202,6 @@ async def run_async_server(args): # custom_functions=[], # allow custom handling address=address, # listen address framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session allow_reuse_address=True, # allow the reuse of an address certfile=helper.get_certificate( "crt" diff --git a/examples/server_sync.py b/examples/server_sync.py index 6ac1c6835..24d461ef7 100755 --- a/examples/server_sync.py +++ b/examples/server_sync.py @@ -66,7 +66,6 @@ def run_sync_server(args): address=address, # listen address # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # TBD handler=None, # handler for each session allow_reuse_address=True, # allow the reuse of an address # ignore_missing_slaves=True, # ignore request to a missing slave # broadcast_enable=False, # treat slave_id 0 as broadcast address, @@ -81,7 +80,6 @@ def run_sync_server(args): address=address, # listen address # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # TBD handler=None, # handler for each session # ignore_missing_slaves=True, # ignore request to a missing slave # broadcast_enable=False, # treat slave_id 0 as broadcast address, # timeout=1, # waiting time for request to complete @@ -97,7 +95,6 @@ def run_sync_server(args): port=args.port, # serial port # custom_functions=[], # allow custom handling framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session # stopbits=1, # The number of stop bits to use # bytesize=7, # The bytesize of the serial messages # parity="E", # Which kind of parity to use @@ -117,7 +114,6 @@ def run_sync_server(args): # custom_functions=[], # allow custom handling address=address, # listen address framer=args.framer, # The framer strategy to use - # handler=None, # handler for each session allow_reuse_address=True, # allow the reuse of an address certfile=helper.get_certificate( "crt" diff --git a/pymodbus/server/async_io.py b/pymodbus/server/async_io.py index 1b3254205..9a5f737ad 100644 --- a/pymodbus/server/async_io.py +++ b/pymodbus/server/async_io.py @@ -68,7 +68,7 @@ def sslctx_provider( class ModbusBaseRequestHandler(asyncio.BaseProtocol): """Implements modbus slave wire protocol. - This uses the asyncio.Protocol to implement the client handler. + This uses the asyncio.Protocol to implement the server protocol. When a connection is established, the asyncio.Protocol.connection_made callback is called. This callback will setup the connection and @@ -491,7 +491,6 @@ def __init__( path, framer=None, identity=None, - handler=None, **kwargs, ): """Initialize the socket server. @@ -503,9 +502,6 @@ def __init__( :param path: unix socket path :param framer: The framer strategy to use :param identity: An optional identify structure - :param handler: A handler for each client session; default is - ModbusConnectedRequestHandler. The handler class - receives connection create/teardown events :param allow_reuse_address: Whether the server will allow the reuse of an address. :param ignore_missing_slaves: True to not send errors on a request @@ -522,7 +518,7 @@ def __init__( self.context = context or ModbusServerContext() self.control = ModbusControlBlock() self.path = path - self.handler = handler or ModbusConnectedRequestHandler + self.handler = ModbusConnectedRequestHandler self.handler.server = self self.ignore_missing_slaves = kwargs.get( "ignore_missing_slaves", Defaults.IgnoreMissingSlaves @@ -594,7 +590,6 @@ def __init__( framer=None, identity=None, address=None, - handler=None, allow_reuse_address=False, backlog=20, **kwargs, @@ -608,9 +603,6 @@ def __init__( :param framer: The framer strategy to use :param identity: An optional identify structure :param address: An optional (interface, port) to bind to. - :param handler: A handler for each client session; default is - ModbusConnectedRequestHandler. The handler class - receives connection create/teardown events :param allow_reuse_address: Whether the server will allow the reuse of an address. :param backlog: is the maximum number of queued connections @@ -631,7 +623,7 @@ def __init__( self.context = context or ModbusServerContext() self.control = ModbusControlBlock() self.address = address or ("", Defaults.TcpPort) - self.handler = handler or ModbusConnectedRequestHandler + self.handler = ModbusConnectedRequestHandler self.handler.server = self self.ignore_missing_slaves = kwargs.get( "ignore_missing_slaves", Defaults.IgnoreMissingSlaves @@ -717,7 +709,6 @@ def __init__( # pylint: disable=too-many-arguments keyfile=None, password=None, reqclicert=False, - handler=None, allow_reuse_address=False, backlog=20, **kwargs, @@ -737,9 +728,6 @@ def __init__( # pylint: disable=too-many-arguments :param keyfile: The key file path for TLS (used if sslctx is None) :param password: The password for for decrypting the private key file :param reqclicert: Force the sever request client's certificate - :param handler: A handler for each client session; default is - ModbusConnectedRequestHandler. The handler class - receives connection create/teardown events :param allow_reuse_address: Whether the server will allow the reuse of an address. :param backlog: is the maximum number of queued connections @@ -757,7 +745,6 @@ def __init__( # pylint: disable=too-many-arguments framer=framer, identity=identity, address=address, - handler=handler, allow_reuse_address=allow_reuse_address, backlog=backlog, **kwargs, @@ -780,7 +767,6 @@ def __init__( framer=None, identity=None, address=None, - handler=None, backlog=20, **kwargs, ): @@ -811,7 +797,7 @@ def __init__( self.context = context or ModbusServerContext() self.control = ModbusControlBlock() self.address = address or ("", Defaults.TcpPort) - self.handler = handler or ModbusDisconnectedRequestHandler + self.handler = ModbusDisconnectedRequestHandler self.ignore_missing_slaves = kwargs.get( "ignore_missing_slaves", Defaults.IgnoreMissingSlaves )