Package fife :: Package extensions :: Package serializers :: Module simplexml :: Class SimpleXMLSerializer
[hide private]
[frames] | no frames]

Class SimpleXMLSerializer

source code

builtins.object --+    
                  |    
   SimpleSerializer --+
                      |
                     SimpleXMLSerializer

This class is a simple interface to get and store data in XML files.

Usage:

       from fife.extensions.serializers.simplexml import SimpleXMLSerializer
       serializer = SimpleXMLSerializer(filename="somefile.xml")
       serializer.set("module_name", "variable_name", "value")
       somevariable = serializer.get("module_name", "variable_name",                                                                     "default_value")
Instance Methods [hide private]
 
__init__(self, filename=None) source code
 
load(self, filename=None)
Loads the XML file into memory and validates it.
source code
 
save(self, filename=None)
Saves the XML file.
source code
 
getValue(self, e_type, e_value) source code
 
get(self, module, name, defaultValue=None)
Gets the value of a specified variable
source code
 
set(self, module, name, value, extra_attrs={})
Sets a variable to specified value.
source code
 
remove(self, module, name)
Removes a variable
source code
 
getModuleNameList(self)
@return A list of the names of the modules in the XML file as strings.
source code
 
getAllSettings(self, module) source code
 
_validateTree(self)
Iterates the XML tree and prints warning when an invalid tag is found.
source code
 
_getModuleTree(self, module)
Returns a module element from the XML tree.
source code
 
_indent(self, elem, level=0)
Adds whitespace, so the resulting XML-file is properly indented.
source code
 
_serializeList(self, list)
Serializes a list, so it can be stored in a text file
source code
 
_deserializeList(self, string)
Deserializes a list back into a list object
source code
 
_serializeDict(self, dict)
Serializes a list, so it can be stored in a text file
source code
 
_deserializeDict(self, serial)
Deserializes a list back into a dict object
source code
Method Details [hide private]

__init__(self, filename=None)
(Constructor)

source code 
Overrides: SimpleSerializer.__init__

load(self, filename=None)

source code 

Loads the XML file into memory and validates it.

Raises a SerializerError exception if the file is not specified.

Parameters:
  • filename (str) - The file to load
Overrides: SimpleSerializer.load

Note: If the file does not exist it will automatically create a blank file for you.

save(self, filename=None)

source code 

Saves the XML file.

Parameters:
  • filename (str) - The file to save
Overrides: SimpleSerializer.save

Note: This Overwrites the file if it exists.

get(self, module, name, defaultValue=None)

source code 

Gets the value of a specified variable

Parameters:
  • module - Name of the module to get the variable from
  • name - Variable name
  • defaultValue (str or unicode or int or float or bool or list or dict) - Specifies the default value to return if the variable is not found
Overrides: SimpleSerializer.get

set(self, module, name, value, extra_attrs={})

source code 

Sets a variable to specified value.

Parameters:
  • module - Module where the variable should be set
  • name - Name of the variable
  • value (str or unicode or int or float or bool or list or dict) - Value to assign to the variable
  • extra_attrs (dict) - Extra attributes to be stored in the XML-file
Overrides: SimpleSerializer.set

remove(self, module, name)

source code 

Removes a variable

Parameters:
  • module - Module where the variable should be set
  • name - Name of the variable

getModuleNameList(self)

source code 

@return A list of the names of the modules in the XML file as strings.

Overrides: SimpleSerializer.getModuleNameList

getAllSettings(self, module)

source code 
Overrides: SimpleSerializer.getAllSettings
(inherited documentation)

_validateTree(self)

source code 

Iterates the XML tree and prints warning when an invalid tag is found.

Raises an InvalidFormat exception if there is a format error.

_getModuleTree(self, module)

source code 

Returns a module element from the XML tree. If no module with the specified name exists, a new element will be created.

Parameters:
  • module (string) - The module to get from the settings tree

_indent(self, elem, level=0)

source code 

Adds whitespace, so the resulting XML-file is properly indented. Shamelessly stolen from http://effbot.org/zone/element-lib.htm