'Convert metadata value to the specified data type.
This method is called during metadata query to help convert the
querying metadata to the data type specified by user. If there is no
data type given, the metadata will be parsed by ast.literal_eval to
try to do a smart converting.
NOTE (flwang) Using "_" as prefix to avoid an InvocationError raised
from wsmeext/sphinxext.py. It\'s OK to call it outside the Query class.
Because the "public" side of that class is actually the outside of the
API, and the "private" side is the API implementation. The method is
only used in the API implementation, so it\'s OK.
:returns: metadata value converted with the specified data type.'

def _get_value_as_type(self, forced_type=None):

    type = (forced_type or self.type)
    try:
        converted_value = self.value
        if (not type):
            try:
                converted_value = ast.literal_eval(self.value)
            except (ValueError, SyntaxError):
                pass
        else:
            if (type not in self._supported_types):
                raise TypeError()
            converted_value = self._type_converters[type](self.value)
            if isinstance(converted_value, datetime.datetime):
                converted_value = timeutils.normalize_time(converted_value)
    except ValueError:
        msg = (_('Unable    to    convert    the    value    %(value)s    to    the    expected    data    type    %(type)s.') % {'value': self.value, 'type': type})
        raise ClientSideError(msg)
    except TypeError:
        msg = (_('The    data    type    %(type)s    is    not    supported.    The    supported    data    type    list    is:    %(supported)s') % {'type': type, 'supported': self._supported_types})
        raise ClientSideError(msg)
    except Exception:
        msg = (_('Unexpected    exception    converting    %(value)s    to    the    expected    data    type    %(type)s.') % {'value': self.value, 'type': type})
        raise ClientSideError(msg)
    return converted_value
