def parse_mappings(mapping_list, unique_values=True):
 mappings = {}
 for mapping in mapping_list:
  mapping = mapping.strip()
  if (not mapping):
   continue
  split_result = mapping.split(':')
  if (len(split_result) != 2):
   raise ValueError((_("Invalid mapping: '%s'") % mapping))
  key = split_result[0].strip()
  if (not key):
   raise ValueError((_("Missing key in mapping: '%s'") % mapping))
  value = split_result[1].strip()
  if (not value):
   raise ValueError((_("Missing value in mapping: '%s'") % mapping))
  if (key in mappings):
   raise ValueError((_("Key %(key)s in mapping: '%(mapping)s' not unique") % locals()))
  if (unique_values and (value in mappings.itervalues())):
   raise ValueError((_("Value %(value)s in mapping: '%(mapping)s' not unique") % locals()))
  mappings[key] = value
 return mappings

def parse_mappings ( mapping_list , unique_values = True ) : mappings = { } for mapping in mapping_list : mapping = mapping . strip ( ) if ( not mapping ) : continue split_result = mapping . split ( ':' ) if ( len ( split_result ) != 2 ) : raise ValueError ( ( _ ( "Invalid mapping: '%s'" ) % mapping ) ) key = split_result [ 0 ] . strip ( ) if ( not key ) : raise ValueError ( ( _ ( "Missing key in mapping: '%s'" ) % mapping ) ) value = split_result [ 1 ] . strip ( ) if ( not value ) : raise ValueError ( ( _ ( "Missing value in mapping: '%s'" ) % mapping ) ) if ( key in mappings ) : raise ValueError ( ( _ ( "Key %(key)s in mapping: '%(mapping)s' not unique" ) % locals ( ) ) ) if ( unique_values and ( value in mappings . itervalues ( ) ) ) : raise ValueError ( ( _ ( "Value %(value)s in mapping: '%(mapping)s' not unique" ) % locals ( ) ) ) mappings [ key ] = value return mappings
parse a list of of mapping strings into a dictionary .