[Git][gajim/python-nbxmpp][master] 3 commits: Add some enum propertys

Philipp Hörist gitlab at dev.gajim.org
Tue Jan 1 18:25:10 CET 2019


Philipp Hörist pushed to branch master at gajim / python-nbxmpp


Commits:
ed7bdb6c by Philipp Hörist at 2019-01-01T15:22:49Z
Add some enum propertys

- - - - -
ecc356ec by Philipp Hörist at 2019-01-01T15:43:19Z
Add EntityCaps (XEP-0115) module

- - - - -
da5f7ab1 by Philipp Hörist at 2019-01-01T17:24:58Z
Dont fail on unknown errors

- - - - -


4 changed files:

- nbxmpp/const.py
- nbxmpp/dispatcher_nb.py
- + nbxmpp/modules/entity_caps.py
- nbxmpp/structs.py


Changes:

=====================================
nbxmpp/const.py
=====================================
@@ -73,6 +73,30 @@ class PresenceType(Enum):
     def is_unavailable(self):
         return self == PresenceType.UNAVAILABLE
 
+    @property
+    def is_error(self):
+        return self == PresenceType.ERROR
+
+    @property
+    def is_probe(self):
+        return self == PresenceType.PROBE
+
+    @property
+    def is_unsubscribe(self):
+        return self == PresenceType.UNSUBSCRIBE
+
+    @property
+    def is_unsubscribed(self):
+        return self == PresenceType.UNSUBSCRIBED
+
+    @property
+    def is_subscribe(self):
+        return self == PresenceType.SUBSCRIBE
+
+    @property
+    def is_subscribed(self):
+        return self == PresenceType.SUBSCRIBED
+
 
 class PresenceShow(Enum):
     ONLINE = 'online'
@@ -81,6 +105,26 @@ class PresenceShow(Enum):
     XA = 'xa'
     DND = 'dnd'
 
+    @property
+    def is_online(self):
+        return self == PresenceShow.ONLINE
+
+    @property
+    def is_chat(self):
+        return self == PresenceShow.CHAT
+
+    @property
+    def is_away(self):
+        return self == PresenceShow.AWAY
+
+    @property
+    def is_xa(self):
+        return self == PresenceShow.XA
+
+    @property
+    def is_dnd(self):
+        return self == PresenceShow.DND
+
 
 class StatusCode(Enum):
     NON_ANONYMOUS = '100'
@@ -191,3 +235,5 @@ class Error(Enum):
     SUBSCRIPTION_REQUIRED = 'subscription-required'
     UNDEFINED_CONDITION = 'undefined-condition'
     UNEXPECTED_REQUEST = 'unexpected-request'
+    POLICY_VIOLATION = 'policy-violation'
+    UNKNOWN_ERROR = 'unknown-error'


=====================================
nbxmpp/dispatcher_nb.py
=====================================
@@ -52,6 +52,7 @@ from nbxmpp.modules.idle import Idle
 from nbxmpp.modules.signed import Signed
 from nbxmpp.modules.vcard_avatar import VCardAvatar
 from nbxmpp.modules.captcha import Captcha
+from nbxmpp.modules.entity_caps import EntityCaps
 from nbxmpp.modules.misc import unwrap_carbon
 from nbxmpp.util import get_properties_struct
 
@@ -171,6 +172,7 @@ class XMPPDispatcher(PlugIn):
         self._modules['Idle'] = Idle(self._owner)
         self._modules['Signed'] = Signed(self._owner)
         self._modules['VCardAvatar'] = VCardAvatar(self._owner)
+        self._modules['EntityCaps'] = EntityCaps(self._owner)
 
         for instance in self._modules.values():
             for handler in instance.handlers:


=====================================
nbxmpp/modules/entity_caps.py
=====================================
@@ -0,0 +1,48 @@
+# Copyright (C) 2018 Philipp Hörist <philipp AT hoerist.com>
+#
+# This file is part of nbxmpp.
+#
+# This program 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; either version 3
+# of the License, or (at your option) any later version.
+#
+# This program 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 this program; If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+
+from nbxmpp.protocol import NS_CAPS
+from nbxmpp.structs import StanzaHandler
+from nbxmpp.structs import EntityCapsData
+
+log = logging.getLogger('nbxmpp.m.entity_caps')
+
+
+class EntityCaps:
+    def __init__(self, client):
+        self._client = client
+        self.handlers = [
+            StanzaHandler(name='presence',
+                          callback=self._process_entity_caps,
+                          ns=NS_CAPS,
+                          priority=15),
+        ]
+
+    @staticmethod
+    def _process_entity_caps(_con, stanza, properties):
+        caps = stanza.getTag('c', namespace=NS_CAPS)
+        if caps is None:
+            properties.entity_caps = EntityCapsData()
+            return
+
+        properties.entity_caps = EntityCapsData(
+            hash=caps.getAttr('hash'),
+            node=caps.getAttr('node'),
+            ver=caps.getAttr('ver')
+        )


=====================================
nbxmpp/structs.py
=====================================
@@ -47,6 +47,9 @@ MucUserData.__new__.__defaults__ = (None, None, None, None, None)
 MucDestroyed = namedtuple('MucDestroyed', 'alternate reason password')
 MucDestroyed.__new__.__defaults__ = (None, None, None)
 
+EntityCapsData = namedtuple('EntityCapsData', 'hash node ver')
+EntityCapsData.__new__.__defaults__ = (None, None, None)
+
 class Properties:
     pass
 
@@ -140,6 +143,7 @@ class PresenceProperties:
         self.muc_user = None
         self.muc_nickname = None
         self.muc_destroyed = None
+        self.entity_caps = None
 
     @property
     def is_self_presence(self):
@@ -220,7 +224,10 @@ class ErrorProperties:
     def __init__(self, stanza):
         for child in stanza.getTag('error').getChildren():
             if child.getNamespace() == NS_STANZAS:
-                self.type = Error(child.name)
+                try:
+                    self.type = Error(child.name)
+                except ValueError:
+                    self.type = Error('unknown-error')
                 break
         self.legacy_code = stanza.getErrorCode()
         self.legacy_type = stanza.getErrorType()



View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/0ee912a2923d897c34f462a987866b8144a19425...da5f7ab1da8e8c139fdcc0bad250fa8ccd79ae07

-- 
View it on GitLab: https://dev.gajim.org/gajim/python-nbxmpp/compare/0ee912a2923d897c34f462a987866b8144a19425...da5f7ab1da8e8c139fdcc0bad250fa8ccd79ae07
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/20190101/6ea61503/attachment-0001.html>


More information about the Commits mailing list