Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwurstsalat <mailtrash@posteo.de>2022-11-29 21:30:31 +0300
committerwurstsalat <mailtrash@posteo.de>2022-11-29 21:30:31 +0300
commit171a6f5cf951bed6d5c8fb28d406a134662701cf (patch)
treeeef9edecda0aa3a51c1cf9b54f565ea44be1d6df
parentfae39c2c296db70bd2bfc2ea77f08c86e36edac2 (diff)
[anti_spam] Type annotations, linting
-rw-r--r--anti_spam/__init__.py2
-rw-r--r--anti_spam/anti_spam.py3
-rw-r--r--anti_spam/config_dialog.py14
-rw-r--r--anti_spam/modules/anti_spam.py15
4 files changed, 21 insertions, 13 deletions
diff --git a/anti_spam/__init__.py b/anti_spam/__init__.py
index 466ff6a..18d5883 100644
--- a/anti_spam/__init__.py
+++ b/anti_spam/__init__.py
@@ -1 +1 @@
-from .anti_spam import AntiSpamPlugin
+from .anti_spam import AntiSpamPlugin # type: ignore
diff --git a/anti_spam/anti_spam.py b/anti_spam/anti_spam.py
index 15f54b5..3feda08 100644
--- a/anti_spam/anti_spam.py
+++ b/anti_spam/anti_spam.py
@@ -11,7 +11,6 @@
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
-#
'''
:author: Yann Leboulanger <asterix@lagaule.org>
@@ -30,7 +29,7 @@ from anti_spam.config_dialog import AntiSpamConfigDialog
class AntiSpamPlugin(GajimPlugin):
- def init(self):
+ def init(self) -> None:
self.description = _('Allows you to block various kinds of incoming '
'messages (Spam, XHTML formatting, etc.)')
self.config_dialog = partial(AntiSpamConfigDialog, self)
diff --git a/anti_spam/config_dialog.py b/anti_spam/config_dialog.py
index 2e31d70..8022331 100644
--- a/anti_spam/config_dialog.py
+++ b/anti_spam/config_dialog.py
@@ -17,6 +17,7 @@ from __future__ import annotations
from typing import Any
from typing import cast
+from typing import TYPE_CHECKING
from gi.repository import Gtk
@@ -27,9 +28,12 @@ from gajim.gui.const import SettingType
from gajim.plugins.plugins_i18n import _
+if TYPE_CHECKING:
+ from .anti_spam import AntiSpamPlugin
+
class AntiSpamConfigDialog(SettingsDialog):
- def __init__(self, plugin, parent):
+ def __init__(self, plugin: AntiSpamPlugin, parent: Gtk.Window) -> None:
self.plugin = plugin
msgtxt_limit = cast(int, self.plugin.config['msgtxt_limit'])
max_length = '' if msgtxt_limit == 0 else msgtxt_limit
@@ -91,8 +95,12 @@ class AntiSpamConfigDialog(SettingsDialog):
'in group chats')),
]
- SettingsDialog.__init__(self, parent, _('Anti Spam Configuration'),
- Gtk.DialogFlags.MODAL, settings, None)
+ SettingsDialog.__init__(self,
+ parent,
+ _('Anti Spam Configuration'),
+ Gtk.DialogFlags.MODAL,
+ settings,
+ '')
def _on_setting(self, value: Any, data: Any) -> None:
self.plugin.config[data] = value
diff --git a/anti_spam/modules/anti_spam.py b/anti_spam/modules/anti_spam.py
index 0c05fb7..1b546c9 100644
--- a/anti_spam/modules/anti_spam.py
+++ b/anti_spam/modules/anti_spam.py
@@ -11,7 +11,6 @@
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
-#
from __future__ import annotations
@@ -28,7 +27,7 @@ from nbxmpp.structs import StanzaHandler
from gajim.common import app
from gajim.common import ged
-from gajim.common import types
+from gajim.common.client import Client
from gajim.common.events import MessageSent
from gajim.common.modules.base import BaseModule
@@ -38,7 +37,7 @@ zeroconf = False
class AntiSpam(BaseModule):
- def __init__(self, client: types.Client) -> None:
+ def __init__(self, client: Client) -> None:
BaseModule.__init__(self, client, plugin=True)
self.handlers = [
@@ -68,10 +67,11 @@ class AntiSpam(BaseModule):
self._contacted_jids.add(event.jid)
def _message_received(self,
- _con: types.xmppClient,
+ _con: Client,
_stanza: Message,
properties: MessageProperties
) -> None:
+
if properties.is_sent_carbon:
# Another device already sent a message
assert properties.jid
@@ -135,7 +135,7 @@ class AntiSpam(BaseModule):
if is_muc_pm or roster_item is None:
assert properties.body
if answer in properties.body.split('\n'):
- if msg_from not in whitelist:
+ if str(msg_from) not in whitelist:
whitelist.append(str(msg_from))
# We need to explicitly save, because 'append' does not
# implement the __setitem__ method
@@ -152,10 +152,11 @@ class AntiSpam(BaseModule):
self._log.info('Anti spam question sent to %s', jid)
def _subscribe_received(self,
- _con: types.xmppClient,
+ _con: Client,
_stanza: Presence,
properties: PresenceProperties
) -> None:
+
msg_from = properties.jid
block_sub = self._config['block_subscription_requests']
roster_item = self._client.get_module('Roster').get_item(msg_from)
@@ -166,5 +167,5 @@ class AntiSpam(BaseModule):
raise NodeProcessed
-def get_instance(*args: Any, **kwargs: Any) -> None:
+def get_instance(*args: Any, **kwargs: Any) -> tuple[AntiSpam, str]:
return AntiSpam(*args, **kwargs), 'AntiSpam'