def GetFieldInDocument(document, field_name, return_type=None):
 if (return_type is not None):
  field_list = [f for f in document.field_list() if (f.name() == field_name)]
  field_types_dict = {}
  for f in field_list:
   field_types_dict.setdefault(f.value().type(), f)
  if (return_type == EXPRESSION_RETURN_TYPE_TEXT):
   if (document_pb.FieldValue.HTML in field_types_dict):
    return field_types_dict[document_pb.FieldValue.HTML]
   if (document_pb.FieldValue.ATOM in field_types_dict):
    return field_types_dict[document_pb.FieldValue.ATOM]
   return field_types_dict.get(document_pb.FieldValue.TEXT)
  elif (return_type == EXPRESSION_RETURN_TYPE_NUMERIC):
   if (document_pb.FieldValue.NUMBER in field_types_dict):
    return field_types_dict[document_pb.FieldValue.NUMBER]
   return field_types_dict.get(document_pb.FieldValue.DATE)
  else:
   return field_types_dict.get(return_type)
 else:
  for f in document.field_list():
   if (f.name() == field_name):
    return f
 return None

def GetFieldInDocument ( document , field_name , return_type = None ) : if ( return_type is not None ) : field_list = [ f for f in document . field_list ( ) if ( f . name ( ) == field_name ) ] field_types_dict = { } for f in field_list : field_types_dict . setdefault ( f . value ( ) . type ( ) , f ) if ( return_type == EXPRESSION_RETURN_TYPE_TEXT ) : if ( document_pb . FieldValue . HTML in field_types_dict ) : return field_types_dict [ document_pb . FieldValue . HTML ] if ( document_pb . FieldValue . ATOM in field_types_dict ) : return field_types_dict [ document_pb . FieldValue . ATOM ] return field_types_dict . get ( document_pb . FieldValue . TEXT ) elif ( return_type == EXPRESSION_RETURN_TYPE_NUMERIC ) : if ( document_pb . FieldValue . NUMBER in field_types_dict ) : return field_types_dict [ document_pb . FieldValue . NUMBER ] return field_types_dict . get ( document_pb . FieldValue . DATE ) else : return field_types_dict . get ( return_type ) else : for f in document . field_list ( ) : if ( f . name ( ) == field_name ) : return f return None
find and return the field with the provided name and type .