예제 #1
0
 def test_string_from_file(self):
     true_list = ['1', 'true', 't', 'yes', 'y', 'on', 'enabled', 'enable']
     for true_str in true_list:
         assert Commons.string_from_file(true_str)
     false_list = ['0', 'false', 'f', 'no', 'n', 'off', 'disabled', 'disable']
     for false_str in false_list:
         assert not Commons.string_from_file(false_str)
     null_list = ['', 'nul', 'null', 'none', 'nil']
     for null_str in null_list:
         assert Commons.string_from_file(null_str) is None
     invalid_list = ["hello", "example", "test"]
     for invalid_str in invalid_list:
         assert Commons.string_from_file(invalid_str) == invalid_str
예제 #2
0
 def load_from_xml():
     try:
         doc = ElementTree.parse("config/config.xml")
     except (OSError, IOError):
         print("No current config, loading from default.")
         doc = ElementTree.parse("config/config-default.xml")
     new_hallo = Hallo()
     root = doc.getroot()
     new_hallo.default_nick = root.findtext("default_nick")
     new_hallo.default_prefix = Commons.string_from_file(root.findtext("default_prefix"))
     new_hallo.default_full_name = root.findtext("default_full_name")
     new_hallo.function_dispatcher = FunctionDispatcher.from_xml(
         ElementTree.tostring(root.find("function_dispatcher")), new_hallo)
     user_group_list_xml = root.find("user_group_list")
     for user_group_xml in user_group_list_xml.findall("user_group"):
         user_group_obj = UserGroup.from_xml(ElementTree.tostring(user_group_xml), new_hallo)
         new_hallo.add_user_group(user_group_obj)
     server_list_xml = root.find("server_list")
     for server_xml in server_list_xml.findall("server"):
         server_obj = new_hallo.server_factory.new_server_from_xml(ElementTree.tostring(server_xml))
         new_hallo.add_server(server_obj)
     if root.find("permission_mask") is not None:
         new_hallo.permission_mask = PermissionMask.from_xml(ElementTree.tostring(root.find("permission_mask")))
     api_key_list_xml = root.find("api_key_list")
     for api_key_xml in api_key_list_xml.findall("api_key"):
         api_key_name = api_key_xml.findtext("name")
         api_key_key = api_key_xml.findtext("key")
         new_hallo.add_api_key(api_key_name, api_key_key)
     return new_hallo
예제 #3
0
 def from_xml(xml_string, server):
     """
     Loads a new Channel object from XML
     :param xml_string: XML string representation of the channel
     :type xml_string: str
     :param server: Server the channel is on
     :type server: Server.Server
     """
     doc = minidom.parseString(xml_string)
     new_name = doc.getElementsByTagName("channel_name")[0].firstChild.data
     channel = Channel(new_name, server)
     channel.logging = Commons.string_from_file(doc.getElementsByTagName("logging")[0].firstChild.data)
     channel.use_caps_lock = Commons.string_from_file(doc.getElementsByTagName("caps_lock")[0].firstChild.data)
     if len(doc.getElementsByTagName("password")) != 0:
         channel.password = doc.getElementsByTagName("password")[0].firstChild.data
     channel.passive_enabled = Commons.string_from_file(
         doc.getElementsByTagName("passive_enabled")[0].firstChild.data)
     channel.auto_join = Commons.string_from_file(doc.getElementsByTagName("auto_join")[0].firstChild.data)
     if len(doc.getElementsByTagName("permission_mask")) != 0:
         channel.permission_mask = PermissionMask.from_xml(doc.getElementsByTagName("permission_mask")[0].toxml())
     return channel
예제 #4
0
 def from_xml(xml_string):
     """
     Loads a new Destination object from XML
     :param xml_string: XML string to parse to create new PermissionMask
     :rtype : PermissionMask
     """
     doc = minidom.parseString(xml_string)
     new_mask = PermissionMask()
     # Load rights
     rights_list_elem = doc.getElementsByTagName("right_list")[0]
     for right_elem in rights_list_elem.getElementsByTagName("right"):
         right_name = right_elem.getElementsByTagName("name")[0].firstChild.data
         right_value = Commons.string_from_file(right_elem.getElementsByTagName("value")[0].firstChild.data)
         new_mask.set_right(right_name, right_value)
     return new_mask
예제 #5
0
 def from_xml(xml_string, server):
     """
     Loads a new User object from XML
     :param xml_string: XML string representation of the user to create
     :type xml_string: str
     :param server: Server which the user is on
     :type server: Server.Server
     """
     doc = minidom.parseString(xml_string)
     new_name = doc.getElementsByTagName("user_name")[0].firstChild.data
     new_user = User(new_name, server)
     new_user.logging = Commons.string_from_file(doc.getElementsByTagName("logging")[0].firstChild.data)
     new_user.use_caps_lock = Commons.string_from_file(doc.getElementsByTagName("caps_lock")[0].firstChild.data)
     # Load UserGroups from XML
     user_group_list_elem = doc.getElementsByTagName("user_group_membership")[0]
     for user_group_elem in user_group_list_elem.getElementsByTagName("user_group_name"):
         user_group_name = user_group_elem.firstChild.data
         user_group = server.hallo.get_user_group_by_name(user_group_name)
         if user_group is not None:
             new_user.add_user_group(user_group)
     # Add PermissionMask, if one exists
     if len(doc.getElementsByTagName("permission_mask")) != 0:
         new_user.permission_mask = PermissionMask.from_xml(doc.getElementsByTagName("permission_mask")[0].toxml())
     return new_user