def RestoreFromIndexValue(index_value, data_type):
 raw_type = _PROPERTY_TYPE_TO_INDEX_VALUE_TYPE.get(data_type)
 if (raw_type is None):
  raise datastore_errors.BadValueError(('Unsupported data type (%r)' % data_type))
 if (index_value is None):
  return index_value
 if (not isinstance(index_value, raw_type)):
  raise datastore_errors.BadValueError(('Unsupported converstion. Expected %r got %r' % (type(index_value), raw_type)))
 meaning = _PROPERTY_MEANINGS.get(data_type)
 if (isinstance(index_value, str) and (meaning not in _NON_UTF8_MEANINGS)):
  index_value = unicode(index_value, 'utf-8')
 conv = _PROPERTY_CONVERSIONS.get(meaning)
 if (not conv):
  return index_value
 try:
  value = conv(index_value)
 except (KeyError, ValueError, IndexError, TypeError, AttributeError) as msg:
  raise datastore_errors.BadValueError(('Error converting value: %r\nException was: %s' % (index_value, msg)))
 return value

def RestoreFromIndexValue ( index_value , data_type ) : raw_type = _PROPERTY_TYPE_TO_INDEX_VALUE_TYPE . get ( data_type ) if ( raw_type is None ) : raise datastore_errors . BadValueError ( ( 'Unsupported data type (%r)' % data_type ) ) if ( index_value is None ) : return index_value if ( not isinstance ( index_value , raw_type ) ) : raise datastore_errors . BadValueError ( ( 'Unsupported converstion. Expected %r got %r' % ( type ( index_value ) , raw_type ) ) ) meaning = _PROPERTY_MEANINGS . get ( data_type ) if ( isinstance ( index_value , str ) and ( meaning not in _NON_UTF8_MEANINGS ) ) : index_value = unicode ( index_value , 'utf-8' ) conv = _PROPERTY_CONVERSIONS . get ( meaning ) if ( not conv ) : return index_value try : value = conv ( index_value ) except ( KeyError , ValueError , IndexError , TypeError , AttributeError ) as msg : raise datastore_errors . BadValueError ( ( 'Error converting value: %r\nException was: %s' % ( index_value , msg ) ) ) return value
restores a index value to the correct datastore type .