Avoid "DeprecationWarning: invalid escape sequence"

Without this change, many warnings like this will be generated while running pytest:
```
test/test_template.py:3
  /build/source/test/test_template.py:3: DeprecationWarning: invalid escape sequence '\/'
    """!
```
This can also be seen when manually running python with warnings enabled.

This happens because the comment uses a multiline string and Python interprets the backslash in the logo as an escape character and complains that \/ is not a valid escape sequence. To fix this, prepend the string with the letter r to indicate that the backslash should be treated as a literal character, see https://docs.python.org/3/reference/lexical_analysis.html#index-20.
I also applied this change to all the comment strings since that shouldn't break anything and to establish it as a pattern for the future so this problem hopefully never happens again.

This is what I did specifically:
- Change the comment at the top of bw_client.py and bw_server.py to start with `"""!` since that seems to be the pattern here
- Search-and-Replace all occurances of `"""!` with `r"""!`
- Manually change the strings in `logoToLog()` in boswatch/utils/header.py
This commit is contained in:
Luflosi 2023-09-19 16:13:23 +02:00
parent 1b95474bc2
commit d4dcc75711
No known key found for this signature in database
GPG key ID: 4E41E29EDCC345D0
50 changed files with 327 additions and 327 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -28,13 +28,13 @@ logging.debug("- %s loaded", __name__)
class BoswatchPlugin(PluginBase):
"""!Description of the Plugin"""
r"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""
r"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -52,7 +52,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(apipath, apicall)
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -68,7 +68,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(apipath, apicall)
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -84,7 +84,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(apipath, apicall)
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
@param bwPacket: bwPacket instance
Remove if not implemented"""

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -27,13 +27,13 @@ logging.debug("- %s loaded", __name__)
class BoswatchPlugin(PluginBase):
"""!Description of the Plugin"""
r"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""
r"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -41,7 +41,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(urls)
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -49,7 +49,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(urls)
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -57,7 +57,7 @@ class BoswatchPlugin(PluginBase):
self._makeRequests(urls)
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
@param bwPacket: bwPacket instance
Remove if not implemented"""

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -28,14 +28,14 @@ logging.debug("- %s loaded", __name__)
class BoswatchPlugin(PluginBase):
"""!Description of the Plugin"""
r"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""
r"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def onLoad(self):
"""!Called by import of the plugin
r"""!Called by import of the plugin
Remove if not implemented"""
self.sqlInserts = {
"pocsag": "INSERT INTO boswatch (packetTimestamp, packetMode, pocsag_ric, pocsag_subric, pocsag_subricText, pocsag_message, pocsag_bitrate, serverName, serverVersion, serverBuildDate, serverBranch, clientName, clientIP, clientVersion, clientBuildDate, clientBranch, inputSource, frequency) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
@ -63,7 +63,7 @@ class BoswatchPlugin(PluginBase):
self.cursor.close()
def setup(self):
"""!Called before alarm
r"""!Called before alarm
Remove if not implemented"""
try:
self.connection.ping(reconnect=True, attempts=3, delay=2)
@ -74,7 +74,7 @@ class BoswatchPlugin(PluginBase):
self.cursor = self.connection.cursor()
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -105,7 +105,7 @@ class BoswatchPlugin(PluginBase):
self.cursor.execute(self.sqlInserts.get("fms"), val)
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -132,7 +132,7 @@ class BoswatchPlugin(PluginBase):
self.cursor.execute(self.sqlInserts.get("pocsag"), val)
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -155,7 +155,7 @@ class BoswatchPlugin(PluginBase):
self.cursor.execute(self.sqlInserts.get("pocsag"), val)
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
@param bwPacket: bwPacket instance
Remove if not implemented"""
@ -177,12 +177,12 @@ class BoswatchPlugin(PluginBase):
self.cursor.execute(self.sqlInserts.get("msg"), val)
def teardown(self):
"""!Called after alarm
r"""!Called after alarm
Remove if not implemented"""
self.connection.commit()
self.cursor.close()
def onUnload(self):
"""!Called by destruction of the plugin
r"""!Called by destruction of the plugin
Remove if not implemented"""
self.connection.close()

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -24,12 +24,12 @@ logging.debug("- %s loaded", __name__)
class PluginBase(ABC):
"""!Main plugin class"""
r"""!Main plugin class"""
_pluginsActive = []
def __init__(self, pluginName, config):
"""!init preload some needed locals and then call onLoad() directly"""
r"""!init preload some needed locals and then call onLoad() directly"""
self._pluginName = pluginName
self.config = config
self._pluginsActive.append(self)
@ -54,13 +54,13 @@ class PluginBase(ABC):
self.onLoad()
def _cleanup(self):
"""!Cleanup routine calls onUnload() directly"""
r"""!Cleanup routine calls onUnload() directly"""
logging.debug("[%s] onUnload()", self._pluginName)
self._pluginsActive.remove(self)
self.onUnload()
def _run(self, bwPacket):
"""!start an complete running turn of an plugin.
r"""!start an complete running turn of an plugin.
Calls setup(), alarm() and teardown() in this order.
The alarm() method serves the BOSWatch packet to the plugin.
@ -121,7 +121,7 @@ class PluginBase(ABC):
return None
def _getStatistics(self):
"""!Returns statistical information's from last plugin run
r"""!Returns statistical information's from last plugin run
@return Statistics as pyton dict"""
stats = {"type": "plugin",
@ -137,55 +137,55 @@ class PluginBase(ABC):
return stats
def onLoad(self):
"""!Called by import of the plugin
r"""!Called by import of the plugin
can be inherited"""
pass
def setup(self):
"""!Called before alarm
r"""!Called before alarm
can be inherited"""
pass
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
can be inherited
@param bwPacket: bwPacket instance"""
logging.warning("ZVEI not implemented in %s", self._pluginName)
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
can be inherited
@param bwPacket: bwPacket instance"""
logging.warning("POCSAG not implemented in %s", self._pluginName)
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
can be inherited
@param bwPacket: bwPacket instance"""
logging.warning("ZVEI not implemented in %s", self._pluginName)
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
can be inherited
@param bwPacket: bwPacket instance"""
logging.warning("MSG not implemented in %s", self._pluginName)
def teardown(self):
"""!Called after alarm
r"""!Called after alarm
can be inherited"""
pass
def onUnload(self):
"""!Called on shutdown of boswatch
r"""!Called on shutdown of boswatch
can be inherited"""
pass
def parseWildcards(self, msg):
"""!Return the message with parsed wildcards"""
r"""!Return the message with parsed wildcards"""
if self._bwPacket is None:
logging.warning("wildcard replacing not allowed - no bwPacket set")
return msg

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -51,14 +51,14 @@ class MQBot(telegram.bot.Bot):
class BoswatchPlugin(PluginBase):
"""!Description of the Plugin"""
r"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""
r"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def onLoad(self):
"""!Called by import of the plugin"""
r"""!Called by import of the plugin"""
if self.config.get("queue", default=True):
q = mq.MessageQueue()
request = Request(con_pool_size=8)
@ -69,14 +69,14 @@ class BoswatchPlugin(PluginBase):
print('normal')
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
@param bwPacket: bwPacket instance"""
msg = self.parseWildcards(self.config.get("message_fms", default="{FMS}"))
self._sendMessage(msg)
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
@param bwPacket: bwPacket instance"""
msg = self.parseWildcards(self.config.get("message_pocsag", default="{RIC}({SRIC})\n{MSG}"))
@ -88,14 +88,14 @@ class BoswatchPlugin(PluginBase):
self._sendLocation(lat, lon)
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance"""
msg = self.parseWildcards(self.config.get("message_zvei", default="{TONE}"))
self._sendMessage(msg)
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
@param bwPacket: bwPacket instance"""
msg = self.parseWildcards(self.config.get("message_msg"))

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,55 +26,55 @@ logging.debug("- %s loaded", __name__)
class BoswatchPlugin(PluginBase):
"""!Description of the Plugin"""
r"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""
r"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def onLoad(self):
"""!Called by import of the plugin
r"""!Called by import of the plugin
Remove if not implemented"""
pass
def setup(self):
"""!Called before alarm
r"""!Called before alarm
Remove if not implemented"""
pass
def fms(self, bwPacket):
"""!Called on FMS alarm
r"""!Called on FMS alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
pass
def pocsag(self, bwPacket):
"""!Called on POCSAG alarm
r"""!Called on POCSAG alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
pass
def zvei(self, bwPacket):
"""!Called on ZVEI alarm
r"""!Called on ZVEI alarm
@param bwPacket: bwPacket instance
Remove if not implemented"""
pass
def msg(self, bwPacket):
"""!Called on MSG packet
r"""!Called on MSG packet
@param bwPacket: bwPacket instance
Remove if not implemented"""
pass
def teardown(self):
"""!Called after alarm
r"""!Called after alarm
Remove if not implemented"""
pass
def onUnload(self):
"""!Called by destruction of the plugin
r"""!Called by destruction of the plugin
Remove if not implemented"""
pass