Package conduit :: Module TypeConverter :: Class TypeConverter
[hide private]

Class TypeConverter

source code

Maintains a dictionary of dictionaries, indexed by the type converted FROM which maps to a list of types that can be converted TO

An example statically constructed conversion dictionary is:
   self.convertables = {
                       "from1" : 
                               {
                                   "to1":from1_to_to1_converter,
                                   "to2":from1_to_to2_converter
                               },
                       "from2" : 
                               {
                                   "to3":from2_to_to3_converter,
                                   "to1":from2_to_to1_converter
                               },
                       "from3" :                                        
                               {
                                   "to5":from3_to_to5_converter
                               }
                       }


Instance Methods [hide private]
 
__init__(self, moduleManager)
Builds the conversion dictionary
source code
 
_add_converter(self, converterWrapper) source code
 
_retain_info_in_conversion(self, fromdata, todata)
Retains the original datatype properties through a type conversion.
source code
 
_get_conversions(self, from_type, to_type)
Returns the conversions required fromtype -> totype.
source code
 
_conversion_exists(self, from_type, to_type) source code
 
_convert(self, conversions, data) source code
 
conversion_exists(self, from_type, to_type)
Checks if all conversion(s) exists to convert from from_type into to_type
source code
 
convert(self, from_type, to_type, data)
Converts a conduit.DataType.DataType (or derived) of type from_type into to_type and returns that newly converted type.
source code
 
get_convertables_list(self)
Returns a list of 2-tuples specifying conversions (from->to)
source code
Instance Variables [hide private]
dict of dicts, see description in conduit.TypeConverter.TypeConverter convertables
The name of the contained module
Method Details [hide private]

__init__(self, moduleManager)
(Constructor)

source code 
Builds the conversion dictionary
Parameters:
  • dynamic_modules - The dynamically loaded converters

_retain_info_in_conversion(self, fromdata, todata)

source code 
Retains the original datatype properties through a type conversion. Properties retained include;
  • gnome-open'able URI
  • modification time
  • original UID
Call this function from a typeconverter

_get_conversions(self, from_type, to_type)

source code 

Returns the conversions required fromtype -> totype. Considers if fromtype and/or totype are super/subclasses of each other. The args string is always taken from the destination, i.e. the totype.

Does not check if the conversion actually exists.
Returns:
list of (fromtype, totype, args) tuples

convert(self, from_type, to_type, data)

source code 
Converts a conduit.DataType.DataType (or derived) of type from_type into to_type and returns that newly converted type. If no conversion is needed, the original data is returned.
Parameters:
  • from_type (string) - The name of the type converted from
  • to_type (string) - The name of the type to convert to
  • data (conduit.DataType.DataType) - The DataType to convert