Coverage for slidge/slixfix/xep_0077/stanza.py: 57%

44 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-07 05:11 +0000

1# Slixmpp: The Slick XMPP Library 

2# Copyright (C) 2012 Nathanael C. Fritz, Lance J.T. Stout 

3# This file is part of Slixmpp. 

4# See the file LICENSE for copying permission. 

5from __future__ import unicode_literals 

6 

7from typing import ClassVar, Set 

8 

9from slixmpp.xmlstream import ElementBase 

10 

11 

12class Register(ElementBase): 

13 namespace = "jabber:iq:register" 

14 name = "query" 

15 plugin_attrib = "register" 

16 interfaces = { 

17 "username", 

18 "password", 

19 "email", 

20 "nick", 

21 "name", 

22 "first", 

23 "last", 

24 "address", 

25 "city", 

26 "state", 

27 "zip", 

28 "phone", 

29 "url", 

30 "date", 

31 "misc", 

32 "text", 

33 "key", 

34 "registered", 

35 "remove", 

36 "instructions", 

37 "fields", 

38 } 

39 sub_interfaces = interfaces 

40 form_fields = { 

41 "username", 

42 "password", 

43 "email", 

44 "nick", 

45 "name", 

46 "first", 

47 "last", 

48 "address", 

49 "city", 

50 "state", 

51 "zip", 

52 "phone", 

53 "url", 

54 "date", 

55 "misc", 

56 "text", 

57 "key", 

58 } 

59 

60 def get_registered(self): 

61 present = self.xml.find("{%s}registered" % self.namespace) 

62 return present is not None 

63 

64 def get_remove(self): 

65 present = self.xml.find("{%s}remove" % self.namespace) 

66 return present is not None 

67 

68 def set_registered(self, value): 

69 if value: 

70 self.add_field("registered") 

71 else: 

72 del self["registered"] 

73 

74 def set_remove(self, value): 

75 if value: 

76 self.add_field("remove") 

77 else: 

78 del self["remove"] 

79 

80 def add_field(self, value): 

81 self._set_sub_text(value, "", keep=True) 

82 

83 def get_fields(self): 

84 fields = set() 

85 for field in self.form_fields: 

86 if self.xml.find("{%s}%s" % (self.namespace, field)) is not None: 

87 fields.add(field) 

88 return fields 

89 

90 def set_fields(self, fields): 

91 del self["fields"] 

92 for field in fields: 

93 self._set_sub_text(field, "", keep=True) 

94 

95 def del_fields(self): 

96 for field in self.form_fields: 

97 self._del_sub(field) 

98 

99 

100class RegisterFeature(ElementBase): 

101 name = "register" 

102 namespace = "http://jabber.org/features/iq-register" 

103 plugin_attrib = name 

104 interfaces: ClassVar[Set[str]] = set()