From d9cc85c1dfdc4e9807f072007c6cb043a3543235 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 6 Jul 2021 16:23:06 +0200 Subject: [PATCH] fix issues raising pylint warnings + small bug fixes Change-Id: Ib63bf13ad06446d3ec3b8cd0b16f9426cef9e3f4 --- secop/client/__init__.py | 2 +- secop/datatypes.py | 2 +- secop/errors.py | 2 +- secop/params.py | 3 --- secop/properties.py | 8 ++++---- secop/protocol/interface/tcp.py | 5 +++-- 6 files changed, 10 insertions(+), 12 deletions(-) diff --git a/secop/client/__init__.py b/secop/client/__init__.py index a1855e5..346179e 100644 --- a/secop/client/__init__.py +++ b/secop/client/__init__.py @@ -517,7 +517,7 @@ class SecopClient(ProxyClient): raise ConnectionError('connection closed before reply') action, _, data = entry[2] # pylint: disable=unpacking-non-sequence if action.startswith(ERRORPREFIX): - errcls = self.error_map(data[0] + "Error") + errcls = self.error_map(data[0]) raise errcls(data[1]) return entry[2] # reply diff --git a/secop/datatypes.py b/secop/datatypes.py index b46b667..03847ba 100644 --- a/secop/datatypes.py +++ b/secop/datatypes.py @@ -194,7 +194,7 @@ class FloatRange(DataType): try: value = float(value) except Exception: - raise BadValueError('Can not __call__ %r to float' % value) + raise BadValueError('Can not convert %r to float' % value) # map +/-infty to +/-max possible number value = clamp(-sys.float_info.max, value, sys.float_info.max) diff --git a/secop/errors.py b/secop/errors.py index 53300e7..368ad0f 100644 --- a/secop/errors.py +++ b/secop/errors.py @@ -143,7 +143,7 @@ EXCEPTIONS = dict( NoSuchCommand=NoSuchCommandError, CommandFailed=CommandFailedError, CommandRunning=CommandRunningError, - Readonly=ReadOnlyError, + ReadOnly=ReadOnlyError, BadValue=BadValueError, CommunicationFailed=CommunicationFailedError, HardwareError=HardwareError, diff --git a/secop/params.py b/secop/params.py index 174480c..44d2933 100644 --- a/secop/params.py +++ b/secop/params.py @@ -149,9 +149,6 @@ class Parameter(Accessible): handler = Property( '[internal] overload the standard read and write functions', ValueType(), export=False, default=None, settable=False) - persistent = Property( - '[internal] persistent setting', BoolType(), - export=False, default=False) initwrite = Property( '''[internal] write this parameter on initialization diff --git a/secop/properties.py b/secop/properties.py index 4111b53..55a1cd7 100644 --- a/secop/properties.py +++ b/secop/properties.py @@ -134,7 +134,7 @@ class HasProperties(HasDescriptors): propertyValues = None def __init__(self): - super(HasProperties, self).__init__() + super().__init__() # store property values in the instance, keep descriptors on the class self.propertyValues = {} # pre-init @@ -168,9 +168,9 @@ class HasProperties(HasDescriptors): if pn in getattr(base, 'propertyDict', {}): if callable(value): raise ProgrammingError('method %s.%s collides with property of %s' % - (cls.__name__, pn, base.__name__)) + (cls.__name__, pn, base.__name__)) from None raise ProgrammingError('can not set property %s.%s to %r' % - (cls.__name__, pn, value)) + (cls.__name__, pn, value)) from None cls.propertyDict[pn] = po def checkProperties(self): @@ -181,7 +181,7 @@ class HasProperties(HasDescriptors): self.propertyValues[pn] = po.datatype(self.propertyValues[pn]) except (KeyError, BadValueError): name = getattr(self, 'name', self.__class__.__name__) - raise ConfigError('%s.%s needs a value of type %r!' % (name, pn, po.datatype)) + raise ConfigError('%s.%s needs a value of type %r!' % (name, pn, po.datatype)) from None for pn, po in self.propertyDict.items(): if pn.startswith('min'): maxname = 'max' + pn[3:] diff --git a/secop/protocol/interface/tcp.py b/secop/protocol/interface/tcp.py index 6048a3c..417db97 100644 --- a/secop/protocol/interface/tcp.py +++ b/secop/protocol/interface/tcp.py @@ -26,6 +26,7 @@ import socketserver import sys import threading import time +import errno from secop.datatypes import BoolType, StringType from secop.errors import SECoPError @@ -192,9 +193,9 @@ class TCPServer(socketserver.ThreadingTCPServer): self, ('0.0.0.0', port), TCPRequestHandler, bind_and_activate=True) break except OSError as e: - if e.args[0] == 98: # address already in use + if e.args[0] == errno.EADDRINUSE: # address already in use # this may happen despite of allow_reuse_address - time.sleep(0.3 * (1 << ntry)) + time.sleep(0.3 * (1 << ntry)) # max accumulated sleep time: 0.3 * 31 = 9.3 sec else: self.log.error('could not initialize TCP Server: %r' % e) raise