From 608607b721578ad820ba8a2bd85780f49a19b54c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Mon, 31 Dec 2018 10:54:51 +0100 Subject: [PATCH] Remove old PEP code --- gajim/common/connection_handlers_events.py | 25 ------- gajim/common/modules/pep.py | 34 ++++----- gajim/common/pep.py | 81 ---------------------- 3 files changed, 15 insertions(+), 125 deletions(-) delete mode 100644 gajim/common/pep.py diff --git a/gajim/common/connection_handlers_events.py b/gajim/common/connection_handlers_events.py index 93b54eaec..64f7ebf51 100644 --- a/gajim/common/connection_handlers_events.py +++ b/gajim/common/connection_handlers_events.py @@ -33,7 +33,6 @@ from gajim.common.modules import dataforms from gajim.common.modules.misc import parse_idle from gajim.common.modules.misc import parse_delay from gajim.common.const import KindConstant, SSLError -from gajim.common.pep import SUPPORTED_PERSONAL_USER_EVENTS from gajim.common.jingle_transport import JingleTransportSocks5 from gajim.common.file_props import FilesProp @@ -429,30 +428,6 @@ class GPGPasswordRequiredEvent(nec.NetworkIncomingEvent): self.keyid = app.config.get_per('accounts', self.conn.name, 'keyid') return True -class PEPReceivedEvent(nec.NetworkIncomingEvent, HelperEvent): - name = 'pep-received' - - def generate(self): - if not self.stanza.getTag('event'): - return - if self.stanza.getTag('error'): - log.debug('PEPReceivedEvent received error stanza. Ignoring') - return - - try: - self.get_jid_resource() - except Exception: - return - - self.event_tag = self.stanza.getTag('event') - - for pep_class in SUPPORTED_PERSONAL_USER_EVENTS: - pep = pep_class.get_tag_as_PEP(self.fjid, self.conn.name, - self.event_tag) - if pep: - self.pep_type = pep.type_ - return True - class PlainConnectionEvent(nec.NetworkIncomingEvent): name = 'plain-connection' diff --git a/gajim/common/modules/pep.py b/gajim/common/modules/pep.py index c56b63128..95b01d526 100644 --- a/gajim/common/modules/pep.py +++ b/gajim/common/modules/pep.py @@ -93,27 +93,23 @@ class PEP: handlers = self._pep_handlers.get(namespace, None) if handlers is None: - # Old Fallback - from gajim.common.connection_handlers_events import PEPReceivedEvent as OldPEPReceivedEvent - app.nec.push_incoming_event( - OldPEPReceivedEvent(None, conn=self._con, stanza=stanza)) raise nbxmpp.NodeProcessed - else: - # Check if this is a retraction - retract = items.getTag('retract') - if retract is not None: - id_ = retract.getAttr('id') - log.info('Received retract of id: %s', id_) - raise nbxmpp.NodeProcessed - # Check if we have items - items_ = items.getTags('item') - if items_ is None: - log.warning('Malformed PEP event received: %s', stanza) - raise nbxmpp.NodeProcessed - for handler in handlers: - handler(jid, items_[0]) - raise nbxmpp.NodeProcessed + # Check if this is a retraction + retract = items.getTag('retract') + if retract is not None: + id_ = retract.getAttr('id') + log.info('Received retract of id: %s', id_) + raise nbxmpp.NodeProcessed + + # Check if we have items + items_ = items.getTags('item') + if items_ is None: + log.warning('Malformed PEP event received: %s', stanza) + raise nbxmpp.NodeProcessed + for handler in handlers: + handler(jid, items_[0]) + raise nbxmpp.NodeProcessed def send_stored_publish(self) -> None: for module in self._store_publish_modules: diff --git a/gajim/common/pep.py b/gajim/common/pep.py deleted file mode 100644 index f936fe3e9..000000000 --- a/gajim/common/pep.py +++ /dev/null @@ -1,81 +0,0 @@ -# Copyright (C) 2007 Piotr Gaczkowski -# Copyright (C) 2007-2014 Yann Leboulanger -# Copyright (C) 2008 Brendan Taylor -# Jean-Marie Traissard -# Jonathan Schleifer -# Stephan Erb -# -# This file is part of Gajim. -# -# Gajim is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published -# by the Free Software Foundation; version 3 only. -# -# Gajim is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Gajim. If not, see . - -from typing import Any # pylint: disable=unused-import -from typing import List # pylint: disable=unused-import - -import logging - -from gajim.common import app - -log = logging.getLogger('gajim.c.pep') - -class AbstractPEP: - - type_ = '' - namespace = '' - - @classmethod - def get_tag_as_PEP(cls, jid, account, event_tag): - items = event_tag.getTag('items', {'node': cls.namespace}) - if items: - log.debug('Received PEP "user %s" from %s', cls.type_, jid) - return cls(jid, account, items) - return None - - def __init__(self, jid, account, items): - self.data, self._retracted = self._extract_info(items) - - self._update_contacts(jid, account) - if jid == app.get_jid_from_account(account): - self._update_account(account) - self._on_receive(jid, account) - - def _extract_info(self, items): - '''To be implemented by subclasses''' - raise NotImplementedError - - def _update_contacts(self, jid, account): - for contact in app.contacts.get_contacts(account, jid): - if self._retracted: - if self.type_ in contact.pep: - del contact.pep[self.type_] - else: - contact.pep[self.type_] = self - - def _update_account(self, account): - acc = app.connections[account] - if self._retracted: - if self.type_ in acc.pep: - del acc.pep[self.type_] - else: - acc.pep[self.type_] = self - - def as_markup_text(self): - '''SHOULD be implemented by subclasses''' - return '' - - def _on_receive(self, jid, account): - '''SHOULD be implemented by subclasses''' - pass - - -SUPPORTED_PERSONAL_USER_EVENTS = [] # type: List[Any]