def _get_attribute(self, request, attribute_name):
    """
    Retrieves an attribute from the request in a safe
    manner (casting it according to form data).

    :type request: Request
    :param request: The request to be used to retrieve the
    attribute.
    :type attribute_name: String
    :param attribute_name: The name of the attribute to be retrieved.
    :rtype: Object
    :return: The retrieved attribute (safely casted).
    """

    # retrieves the attribute value from the attribute
    # name and casts it (avoiding form data problems)
    attribute_value = request.get_attribute(attribute_name)
    attribute_value = self._cast_attribute_value(attribute_value)

    # returns the attribute value
    return attribute_value