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"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,19 +26,19 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Adds descriptions to bwPackets"""
r"""!Adds descriptions to bwPackets"""
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"""
for descriptor in self.config:
if descriptor.get("wildcard", default=None):
self.registerWildcard(descriptor.get("wildcard"), descriptor.get("descrField"))
def doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
for descriptor in self.config:
@ -54,5 +54,5 @@ class BoswatchModule(ModuleBase):
return bwPacket
def onUnload(self):
"""!Called by destruction of the plugin"""
r"""!Called by destruction of the plugin"""
pass

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,21 +26,21 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Description of the Module"""
r"""!Description of the Module"""
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'
self._filterLists = {}
logging.debug("Configured ignoreTime: %d", self.config.get("ignoreTime", default=10))
logging.debug("Configured maxEntry: %d", self.config.get("maxEntry", default=10))
def onLoad(self):
"""!Called by import of the plugin
r"""!Called by import of the plugin
Remove if not implemented"""
pass
def doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
if bwPacket.get("mode") == "fms":
@ -62,7 +62,7 @@ class BoswatchModule(ModuleBase):
return self._check(bwPacket, filterFields)
def onUnload(self):
"""!Called by destruction of the plugin
r"""!Called by destruction of the plugin
Remove if not implemented"""
pass

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,17 +26,17 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Filter of specific bwPacket mode"""
r"""!Filter of specific bwPacket mode"""
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"""
pass
def doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
@ -48,5 +48,5 @@ class BoswatchModule(ModuleBase):
return False
def onUnload(self):
"""!Called by destruction of the plugin"""
r"""!Called by destruction of the plugin"""
pass

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,17 +26,17 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Regex based filter mechanism"""
r"""!Regex based filter mechanism"""
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"""
pass
def doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
for regexFilter in self.config:
@ -61,5 +61,5 @@ class BoswatchModule(ModuleBase):
return False # False -> Router will stop further processing
def onUnload(self):
"""!Called by destruction of the plugin"""
r"""!Called by destruction of the plugin"""
pass

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -27,13 +27,13 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Description of the Module"""
r"""!Description of the Module"""
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 doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
if bwPacket.get("mode") == "pocsag":
@ -42,7 +42,7 @@ class BoswatchModule(ModuleBase):
return bwPacket
def geocode(self, bwPacket):
"""!find address in message and get latitude and longitude
r"""!find address in message and get latitude and longitude
@param bwPacket: A BOSWatch packet instance"""
try:

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -24,12 +24,12 @@ logging.debug("- %s loaded", __name__)
class ModuleBase(ABC):
"""!Main module class"""
r"""!Main module class"""
_modulesActive = []
def __init__(self, moduleName, config):
"""!init preload some needed locals and then call onLoad() directly"""
r"""!init preload some needed locals and then call onLoad() directly"""
self._moduleName = moduleName
self.config = config
self._modulesActive.append(self)
@ -46,13 +46,13 @@ class ModuleBase(ABC):
self.onLoad()
def _cleanup(self):
"""!Cleanup routine calls onUnload() directly"""
r"""!Cleanup routine calls onUnload() directly"""
logging.debug("[%s] onUnload()", self._moduleName)
self._modulesActive.remove(self)
self.onUnload()
def _run(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance
@return bwPacket or False"""
@ -75,7 +75,7 @@ class ModuleBase(ABC):
return bwPacket
def _getStatistics(self):
"""!Returns statistical information's from last module run
r"""!Returns statistical information's from last module run
@return Statistics as pyton dict"""
stats = {"type": "module",
@ -86,25 +86,25 @@ class ModuleBase(ABC):
return stats
def onLoad(self):
"""!Called by import of the module
r"""!Called by import of the module
can be inherited"""
pass
def doWork(self, bwPacket):
"""!Called module run
r"""!Called module run
can be inherited
@param bwPacket: bwPacket instance"""
logging.warning("no functionality in module %s", self._moduleName)
def onUnload(self):
"""!Called on shutdown of boswatch
r"""!Called on shutdown of boswatch
can be inherited"""
pass
@staticmethod
def registerWildcard(newWildcard, bwPacketField):
"""!Register a new wildcard
r"""!Register a new wildcard
@param newWildcard: wildcard where parser searching for
@param bwPacketField: field from bwPacket where holds replacement data"""

View file

@ -1,6 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
r"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
@ -26,18 +26,18 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(ModuleBase):
"""!Description of the Module"""
r"""!Description of the Module"""
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 doWork(self, bwPacket):
"""!start an run of the module.
r"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
if bwPacket.get("mode") == "fms":
@ -52,6 +52,6 @@ class BoswatchModule(ModuleBase):
return bwPacket
def onUnload(self):
"""!Called by destruction of the plugin
r"""!Called by destruction of the plugin
Remove if not implemented"""
pass