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


Commits:
b3a81423 by lovetox at 2020-11-28T09:00:38+01:00
VCard: Raise error on empty text elements

- - - - -
7c4f7f58 by lovetox at 2020-11-28T09:22:59+01:00
VCard: Add is_empty() for properties

- - - - -


1 changed file:

- nbxmpp/modules/vcard4.py


Changes:

=====================================
nbxmpp/modules/vcard4.py
=====================================
@@ -373,6 +373,10 @@ class UriProperty:
         node.addChild('uri', payload=self.value)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.value
+
 
 @dataclass
 class TextProperty:
@@ -402,6 +406,10 @@ class TextProperty:
         node.addChild('text', payload=self.value)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.value
+
 
 @dataclass
 class TextListProperty:
@@ -421,6 +429,8 @@ class TextListProperty:
             raise ValueError('no value found')
 
         values = get_data_from_children(node, 'text')
+        if not values:
+            raise ValueError('no values found')
 
         parameters = get_parameters(node)
 
@@ -433,6 +443,10 @@ class TextListProperty:
         add_children(node, 'text', self.values)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.values
+
 
 @dataclass
 class MultipleValueProperty:
@@ -462,6 +476,10 @@ class MultipleValueProperty:
         node.addChild(self.value_type, payload=self.value)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.value
+
 
 @dataclass
 class SourceProperty(UriProperty):
@@ -536,6 +554,16 @@ class NProperty:
         add_children(node, 'suffix', self.suffix)
         return node
 
+    @property
+    def is_empty(self):
+        if (self.surname or
+                self.given or
+                self.additional or
+                self.suffix or
+                self.prefix):
+            return False
+        return True
+
 
 @dataclass
 class NicknameProperty(TextListProperty):
@@ -597,6 +625,12 @@ class GenderProperty:
             node.addChild('identity', payload=self.sex)
         return node
 
+    @property
+    def is_empty(self):
+        if self.sex or self.identity:
+            return False
+        return True
+
 
 @dataclass
 class AdrProperty:
@@ -643,6 +677,18 @@ class AdrProperty:
         add_children(node, 'country', self.country)
         return node
 
+    @property
+    def is_empty(self):
+        if (self.pobox or
+                self.ext or
+                self.street or
+                self.locality or
+                self.region or
+                self.code or
+                self.country):
+            return False
+        return True
+
 
 @dataclass
 class TelProperty(MultipleValueProperty):
@@ -690,6 +736,10 @@ class LangProperty:
         node.addChild('language-tag', payload=self.value)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.value
+
 
 @dataclass
 class TzProperty(MultipleValueProperty):
@@ -830,6 +880,10 @@ class ClientpidmapProperty:
         node.addChild('uri', payload=self.uri)
         return node
 
+    @property
+    def is_empty(self):
+        return not self.uri
+
 
 @dataclass
 class UrlProperty(UriProperty):



View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/ce7fc5350858adf553a74cd675c074684b22086e...7c4f7f5850c048a8b11853a54682dfa2e775ba9e

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/python-nbxmpp/-/compare/ce7fc5350858adf553a74cd675c074684b22086e...7c4f7f5850c048a8b11853a54682dfa2e775ba9e
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to