[Git][gajim/gajim][master] 3 commits: Fix pylint errors in dataforms module

Philipp Hörist gitlab at dev.gajim.org
Sat Jul 7 20:02:08 CEST 2018


Philipp Hörist pushed to branch master at gajim / gajim


Commits:
af7ac921 by Philipp Hörist at 2018-07-07T19:36:24+02:00
Fix pylint errors in dataforms module

- - - - -
e918ac85 by Philipp Hörist at 2018-07-07T20:00:09+02:00
Remove streamhost redirect

After asking around this is a dead feature.
Because servers cannot be sure if clients support redirection, a server
using this feature would essentially risk that his users are not able to
connect at all.

- - - - -
3a6f6670 by Philipp Hörist at 2018-07-07T20:01:47+02:00
Check if we have a nbxmpp Client object

In some cases the XMPPDispatcher which handles the callbacks is not
yet created.

- - - - -


4 changed files:

- gajim/common/connection.py
- gajim/common/connection_handlers.py
- gajim/common/connection_handlers_events.py
- gajim/common/dataforms.py


Changes:

=====================================
gajim/common/connection.py
=====================================
--- a/gajim/common/connection.py
+++ b/gajim/common/connection.py
@@ -593,7 +593,6 @@ class Connection(CommonConnection, ConnectionHandlers):
         self.connected_hostname = None
         # Holds the full jid we received on the bind event
         self.registered_name = None
-        self.redirected = None
         self.last_time_to_reconnect = None
         self.new_account_info = None
         self.new_account_form = None
@@ -794,12 +793,7 @@ class Connection(CommonConnection, ConnectionHandlers):
                 # show error dialog
                 self._connection_lost()
         else:
-            if self.redirected:
-                self.disconnect(on_purpose=True)
-                self.connect()
-                return
-            else:
-                self.disconnect()
+            self.disconnect()
         self.on_purpose = False
     # END disconnectedReconnCB
 
@@ -988,25 +982,21 @@ class Connection(CommonConnection, ConnectionHandlers):
                     self.name, 'try_connecting_for_foo_secs')
             proxy = helpers.get_proxy_info(self.name)
             use_srv = app.config.get_per('accounts', self.name, 'use_srv')
-            if self.redirected:
-                use_custom = True
-                custom_h = self.redirected['host']
-                custom_p = self.redirected['port']
-            else:
-                use_custom = app.config.get_per('accounts', self.name,
-                    'use_custom_host')
-                if use_custom:
-                    custom_h = app.config.get_per('accounts', self.name,
-                        'custom_host')
-                    custom_p = app.config.get_per('accounts', self.name,
-                        'custom_port')
-                    try:
-                        helpers.idn_to_ascii(custom_h)
-                    except Exception:
-                        app.nec.push_incoming_event(InformationEvent(
-                            None, dialog_name='invalid-custom-hostname',
-                            args=custom_h))
-                        use_custom = False
+
+            use_custom = app.config.get_per('accounts', self.name,
+                'use_custom_host')
+            if use_custom:
+                custom_h = app.config.get_per('accounts', self.name,
+                    'custom_host')
+                custom_p = app.config.get_per('accounts', self.name,
+                    'custom_port')
+                try:
+                    helpers.idn_to_ascii(custom_h)
+                except Exception:
+                    app.nec.push_incoming_event(InformationEvent(
+                        None, dialog_name='invalid-custom-hostname',
+                        args=custom_h))
+                    use_custom = False
 
         # create connection if it doesn't already exist
         self.connected = 1
@@ -1018,10 +1008,8 @@ class Connection(CommonConnection, ConnectionHandlers):
             h = custom_h
             p = custom_p
             ssl_p = custom_p
-            if not self.redirected:
-                use_srv = False
+            use_srv = False
 
-        self.redirected = None
         # SRV resolver
         self._proxy = proxy
         self._hosts = [
@@ -1148,11 +1136,6 @@ class Connection(CommonConnection, ConnectionHandlers):
 
         self._current_host = host
 
-        if self.redirected:
-            self.disconnect(on_purpose=True)
-            self.connect()
-            return
-
         self._current_type = self._current_host['type']
 
         port = self._current_host['port']


=====================================
gajim/common/connection_handlers.py
=====================================
--- a/gajim/common/connection_handlers.py
+++ b/gajim/common/connection_handlers.py
@@ -774,7 +774,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
         self.privacy_default_list = None
 
         app.nec.register_incoming_event(StreamConflictReceivedEvent)
-        app.nec.register_incoming_event(StreamOtherHostReceivedEvent)
         app.nec.register_incoming_event(MessageReceivedEvent)
         app.nec.register_incoming_event(ArchivingErrorReceivedEvent)
         app.nec.register_incoming_event(
@@ -799,8 +798,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
             ged.POSTGUI, self._nec_unsubscribed_presence_received_end)
         app.ged.register_event_handler('agent-removed', ged.CORE,
             self._nec_agent_removed)
-        app.ged.register_event_handler('stream-other-host-received', ged.CORE,
-            self._nec_stream_other_host_received)
         app.ged.register_event_handler('blocking', ged.CORE,
             self._nec_blocking)
 
@@ -826,8 +823,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
             ged.POSTGUI, self._nec_unsubscribed_presence_received_end)
         app.ged.remove_event_handler('agent-removed', ged.CORE,
             self._nec_agent_removed)
-        app.ged.remove_event_handler('stream-other-host-received', ged.CORE,
-            self._nec_stream_other_host_received)
         app.ged.remove_event_handler('blocking', ged.CORE, self._nec_blocking)
 
     def add_sha(self, p, send_caps=True):
@@ -1383,11 +1378,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
                 probe = nbxmpp.Presence(jid, 'probe', frm=self.get_own_jid())
                 self.connection.send(probe)
 
-    def _nec_stream_other_host_received(self, obj):
-        if obj.conn.name != self.name:
-            return
-        self.redirected = obj.redirected
-
     def _StreamCB(self, con, obj):
         log.debug('StreamCB')
         app.nec.push_incoming_event(StreamReceivedEvent(None,
@@ -1456,5 +1446,7 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream):
             con.RegisterHandler(*handler)
 
     def _unregister_handlers(self):
+        if not self.connection:
+            return
         for handler in modules.get_handlers(self):
             self.connection.UnregisterHandler(*handler)


=====================================
gajim/common/connection_handlers_events.py
=====================================
--- a/gajim/common/connection_handlers_events.py
+++ b/gajim/common/connection_handlers_events.py
@@ -331,28 +331,6 @@ class StreamConflictReceivedEvent(nec.NetworkIncomingEvent):
             self.conn = self.base_event.conn
             return True
 
-class StreamOtherHostReceivedEvent(nec.NetworkIncomingEvent):
-    name = 'stream-other-host-received'
-    base_network_events = ['stream-received']
-
-    def generate(self):
-        self.conn = self.base_event.conn
-        self.stanza = self.base_event.stanza
-        other_host = self.stanza.getTag('see-other-host')
-        if other_host and self.conn._current_type in ('ssl', 'tls'):
-            host = other_host.getData()
-            if ':' in host:
-                host_l = host.split(':', 1)
-                h = host_l[0]
-                p = host_l[1]
-            else:
-                h = host
-                p = 5222
-            if h.startswith('[') and h.endswith(']'):
-                h = h[1:-1]
-            self.redirected = {'host': h, 'port': p}
-            return True
-
 class PresenceHelperEvent:
     def _generate_show(self):
         self.show = self.stanza.getShow()


=====================================
gajim/common/dataforms.py
=====================================
--- a/gajim/common/dataforms.py
+++ b/gajim/common/dataforms.py
@@ -1,46 +1,50 @@
-# this will go to src/common/xmpp later, for now it is in src/common
-# -*- coding:utf-8 -*-
-## src/common/dataforms.py
-##
-## Copyright (C) 2006-2007 Tomasz Melcer <liori AT exroot.org>
-## Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
-## Copyright (C) 2007 Stephan Erb <steve-e AT h3c.de>
-##
-## 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 <http://www.gnu.org/licenses/>.
-##
+# Copyright (C) 2006-2007 Tomasz Melcer <liori AT exroot.org>
+# Copyright (C) 2006-2014 Yann Leboulanger <asterix AT lagaule.org>
+# Copyright (C) 2007 Stephan Erb <steve-e AT h3c.de>
+#
+# 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 <http://www.gnu.org/licenses/>.
 
 """
-This module contains wrappers for different parts of data forms (JEP 0004). For
+This module contains wrappers for different parts of data forms (XEP-0004). For
 information how to use them, read documentation
 """
 
 import nbxmpp
+
 from gajim.common import helpers
 
+
 # exceptions used in this module
-# base class
-class Error(Exception): pass
+class Error(Exception):
+    pass
+
+
 # when we get nbxmpp.Node which we do not understand
-class UnknownDataForm(Error): pass
+class UnknownDataForm(Error):
+    pass
+
+
 # when we get nbxmpp.Node which contains bad fields
-class WrongFieldValue(Error): pass
+class WrongFieldValue(Error):
+    pass
+
 
 # helper class to change class of already existing object
 class ExtendedNode(nbxmpp.Node, object):
     @classmethod
-    def __new__(cls,  *a, **b):
+    def __new__(cls, *a, **b):
         if 'extend' not in b.keys() or not b['extend']:
             return object.__new__(cls)
 
@@ -49,23 +53,25 @@ class ExtendedNode(nbxmpp.Node, object):
         extend.__class__ = cls
         return extend
 
+
 # helper to create fields from scratch
 def Field(typ, **attrs):
     ''' Helper function to create a field of given type. '''
     f = {
-            'boolean': BooleanField,
-            'fixed': StringField,
-            'hidden': StringField,
-            'text-private': StringField,
-            'text-single': StringField,
-            'jid-multi': JidMultiField,
-            'jid-single': JidSingleField,
-            'list-multi': ListMultiField,
-            'list-single': ListSingleField,
-            'text-multi': TextMultiField,
+        'boolean': BooleanField,
+        'fixed': StringField,
+        'hidden': StringField,
+        'text-private': StringField,
+        'text-single': StringField,
+        'jid-multi': JidMultiField,
+        'jid-single': JidSingleField,
+        'list-multi': ListMultiField,
+        'list-single': ListSingleField,
+        'text-multi': TextMultiField,
     }[typ](typ=typ, **attrs)
     return f
 
+
 def ExtendField(node):
     """
     Helper function to extend a node to field of appropriate type
@@ -73,23 +79,24 @@ def ExtendField(node):
     # when validation (XEP-122) will go in, we could have another classes
     # like DateTimeField - so that dicts in Field() and ExtendField() will
     # be different...
-    typ=node.getAttr('type')
+    typ = node.getAttr('type')
     f = {
-            'boolean': BooleanField,
-            'fixed': StringField,
-            'hidden': StringField,
-            'text-private': StringField,
-            'text-single': StringField,
-            'jid-multi': JidMultiField,
-            'jid-single': JidSingleField,
-            'list-multi': ListMultiField,
-            'list-single': ListSingleField,
-            'text-multi': TextMultiField,
+        'boolean': BooleanField,
+        'fixed': StringField,
+        'hidden': StringField,
+        'text-private': StringField,
+        'text-single': StringField,
+        'jid-multi': JidMultiField,
+        'jid-single': JidSingleField,
+        'list-multi': ListMultiField,
+        'list-single': ListSingleField,
+        'text-multi': TextMultiField,
     }
     if typ not in f:
         typ = 'text-single'
     return f[typ](extend=node)
 
+
 def ExtendForm(node):
     """
     Helper function to extend a node to form of appropriate type
@@ -99,6 +106,7 @@ def ExtendForm(node):
     else:
         return SimpleDataForm(extend=node)
 
+
 class DataField(ExtendedNode):
     """
     Keeps data about one field - var, field type, labels, instructions... Base
@@ -107,7 +115,7 @@ class DataField(ExtendedNode):
     """
 
     def __init__(self, typ=None, var=None, value=None, label=None, desc=None,
-                    required=False, options=None, extend=None):
+                 required=False, options=None, extend=None):
 
         if extend is None:
             ExtendedNode.__init__(self, 'field')
@@ -118,7 +126,7 @@ class DataField(ExtendedNode):
                 self.value = value
             if label is not None:
                 self.label = label
-            if desc  is not None:
+            if desc is not None:
                 self.desc = desc
             self.required = required
             self.options = options
@@ -162,10 +170,10 @@ class DataField(ExtendedNode):
         """
         Human-readable field name
         """
-        l = self.getAttr('label')
-        if not l:
-            l = self.var
-        return l
+        label_ = self.getAttr('label')
+        if not label_:
+            label_ = self.var
+        return label_
 
     @label.setter
     def label(self, value):
@@ -236,6 +244,7 @@ class DataField(ExtendedNode):
     def is_valid(self):
         return True
 
+
 class Uri(nbxmpp.Node):
     def __init__(self, uri_tag):
         nbxmpp.Node.__init__(self, node=uri_tag)
@@ -270,6 +279,7 @@ class Uri(nbxmpp.Node):
     def uri_data(self):
         self.setData(None)
 
+
 class Media(nbxmpp.Node):
     def __init__(self, media_tag):
         nbxmpp.Node.__init__(self, node=media_tag)
@@ -292,6 +302,7 @@ class Media(nbxmpp.Node):
         for element in self.getTags('uri'):
             self.delChild(element)
 
+
 class BooleanField(DataField):
     @property
     def value(self):
@@ -304,7 +315,7 @@ class BooleanField(DataField):
         if v in ('1', 'true'):
             return True
         if v is None:
-            return False # default value is False
+            return False  # default value is False
         raise WrongFieldValue
 
     @value.setter
@@ -317,6 +328,7 @@ class BooleanField(DataField):
         if t is not None:
             self.delChild(t)
 
+
 class StringField(DataField):
     """
     Covers fields of types: fixed, hidden, text-private, text-single
@@ -341,9 +353,10 @@ class StringField(DataField):
     def value(self):
         try:
             self.delChild(self.getTag('value'))
-        except ValueError: # if there already were no value tag
+        except ValueError:  # if there already were no value tag
             pass
 
+
 class ListField(DataField):
     """
     Covers fields of types: jid-multi, jid-single, list-multi, list-single
@@ -359,17 +372,18 @@ class ListField(DataField):
             v = element.getTagData('value')
             if v is None:
                 raise WrongFieldValue
-            l = element.getAttr('label')
-            if not l:
-                l = v
-            options.append((l, v))
+            label = element.getAttr('label')
+            if not label:
+                label = v
+            options.append((label, v))
         return options
 
     @options.setter
     def options(self, values):
         del self.options
         for value, label in values:
-            self.addChild('option', {'label': label}).setTagData('value', value)
+            self.addChild('option',
+                          {'label': label}).setTagData('value', value)
 
     @options.deleter
     def options(self):
@@ -381,10 +395,11 @@ class ListField(DataField):
             v = element.getTagData('value')
             if v is None:
                 raise WrongFieldValue
-            l = element.getAttr('label')
-            if not l:
-                l = v
-            yield (v, l)
+            label = element.getAttr('label')
+            if not label:
+                label = v
+            yield (v, label)
+
 
 class ListSingleField(ListField, StringField):
     """
@@ -397,6 +412,7 @@ class ListSingleField(ListField, StringField):
             return False
         return True
 
+
 class JidSingleField(ListSingleField):
     """
     Covers jid-single fields
@@ -406,12 +422,13 @@ class JidSingleField(ListSingleField):
             try:
                 helpers.parse_jid(self.value)
                 return True
-            except:
+            except Exception:
                 return False
         if self.required:
             return False
         return True
 
+
 class ListMultiField(ListField):
     """
     Covers list-multi fields
@@ -449,6 +466,7 @@ class ListMultiField(ListField):
             return False
         return True
 
+
 class JidMultiField(ListMultiField):
     """
     Covers jid-multi fields
@@ -458,13 +476,14 @@ class JidMultiField(ListMultiField):
             for value in self.values:
                 try:
                     helpers.parse_jid(value)
-                except:
+                except Exception:
                     return False
             return True
         if self.required:
             return False
         return True
 
+
 class TextMultiField(DataField):
     @property
     def value(self):
@@ -489,6 +508,7 @@ class TextMultiField(DataField):
         for element in self.getTags('value'):
             self.delChild(element)
 
+
 class DataRecord(ExtendedNode):
     """
     The container for data fields - an xml element which has DataField elements
@@ -560,6 +580,7 @@ class DataRecord(ExtendedNode):
                 return False
         return True
 
+
 class DataForm(ExtendedNode):
     def __init__(self, type_=None, title=None, instructions=None, extend=None):
         if extend is None:
@@ -567,11 +588,11 @@ class DataForm(ExtendedNode):
             nbxmpp.Node.__init__(self, 'x', attrs={'xmlns': nbxmpp.NS_DATA})
 
         if type_ is not None:
-            self.type_=type_
+            self.type_ = type_
         if title is not None:
-            self.title=title
+            self.title = title
         if instructions is not None:
-            self.instructions=instructions
+            self.instructions = instructions
 
     @property
     def type_(self):
@@ -623,7 +644,8 @@ class DataForm(ExtendedNode):
     @instructions.setter
     def instructions(self, value):
         del self.instructions
-        if value == '': return
+        if value == '':
+            return
         for line in value.split('\n'):
             self.addChild('instructions').setData(line)
 
@@ -632,11 +654,12 @@ class DataForm(ExtendedNode):
         for value in self.getTags('instructions'):
             self.delChild(value)
 
+
 class SimpleDataForm(DataForm, DataRecord):
-    def __init__(self, type_=None, title=None, instructions=None, fields=None, \
-    extend=None):
+    def __init__(self, type_=None, title=None, instructions=None, fields=None,
+                 extend=None):
         DataForm.__init__(self, type_=type_, title=title,
-                instructions=instructions, extend=extend)
+                          instructions=instructions, extend=extend)
         DataRecord.__init__(self, fields=fields, extend=self, associated=self)
 
     def get_purged(self):
@@ -647,12 +670,12 @@ class SimpleDataForm(DataForm, DataRecord):
         for f in c.iter_fields():
             if f.required:
                 # add <value> if there is not
-                if hasattr(f, 'value') and  not f.value:
+                if hasattr(f, 'value') and not f.value:
                     f.value = ''
                 # Keep all required fields
                 continue
-            if (hasattr(f, 'value') and not f.value and f.value != 0) or (
-            hasattr(f, 'values') and len(f.values) == 0):
+            if ((hasattr(f, 'value') and not f.value and f.value != 0) or
+                    (hasattr(f, 'values') and len(f.values) == 0)):
                 to_be_removed.append(f)
             else:
                 del f.label
@@ -662,11 +685,12 @@ class SimpleDataForm(DataForm, DataRecord):
             c.delChild(f)
         return c
 
+
 class MultipleDataForm(DataForm):
     def __init__(self, type_=None, title=None, instructions=None, items=None,
-    extend=None):
+                 extend=None):
         DataForm.__init__(self, type_=type_, title=title,
-                instructions=instructions, extend=extend)
+                          instructions=instructions, extend=extend)
         # all records, recorded into DataRecords
         if extend is None:
             if items is not None:



View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/ff2fab73a15732511ba6d4490b35347e7be2167e...3a6f667008d0bb53fa7b1c69cb2a11399e9b98dc

-- 
View it on GitLab: https://dev.gajim.org/gajim/gajim/compare/ff2fab73a15732511ba6d4490b35347e7be2167e...3a6f667008d0bb53fa7b1c69cb2a11399e9b98dc
You're receiving this email because of your account on dev.gajim.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gajim.org/pipermail/commits/attachments/20180707/896a74ae/attachment-0001.html>


More information about the Commits mailing list