def ValueOf(self, expression, default_value=None, return_type=None):
    """Returns the value of an expression on a document.

    Args:
      expression: The expression string.
      default_value: The value to return if the expression cannot be evaluated.
      return_type: The type the expression should evaluate to. Used to create
        multiple sorts for ambiguous expressions. If None, the expression
        evaluates to the inferred type or first type of a field it encounters in
        a document.

    Returns:
      The value of the expression on the evaluator's document, or default_value
      if the expression cannot be evaluated on the document.

    Raises:
      ExpressionEvaluationError: sort expression cannot be evaluated
      because the expression or default value is malformed. Callers of
      ValueOf should catch and return error to user in response.
      QueryExpressionEvaluationError: same as ExpressionEvaluationError but
      these errors should return query as error status to users.
    """
    expression_tree = Parse(expression)
    if not expression_tree.getType() and expression_tree.children:
      expression_tree = expression_tree.children[0]





    name = query_parser.GetQueryNodeText(expression_tree)
    schema = self._inverted_index.GetSchema()
    if (expression_tree.getType() == ExpressionParser.NAME and
        name in schema):
      contains_text_result = False
      for field_type in schema[name].type_list():
        if field_type in search_util.TEXT_DOCUMENT_FIELD_TYPES:
          contains_text_result = True


      if (schema.IsType(name, document_pb.FieldValue.DATE) and
          not contains_text_result):
        if isinstance(default_value, basestring):
          try:
            default_value = search_util.DeserializeDate(default_value)
          except __HOLE__:
            raise QueryExpressionEvaluationError(
                'Default text value is not appropriate for sort expression \'' +
                name + '\': failed to parse date \"' + default_value + '\"')
    result = default_value
    try:
      result = self._Eval(expression_tree, return_type=return_type)
    except _ExpressionError, e:


      logging.debug('Skipping expression %s: %s', expression, e)
    except search_util.UnsupportedOnDevError, e:


      logging.warning(e.args[0])

    return result
dataset/ETHPy150Open GoogleCloudPlatform/python-compat-runtime/appengine-compat/exported_appengine_sdk/google/appengine/api/search/stub/expression_evaluator.py/ExpressionEvaluator.ValueOf