query_parser.py revision 1100
1516N/A#!/usr/bin/python2.4
3N/A#
3N/A# CDDL HEADER START
3N/A#
3N/A# The contents of this file are subject to the terms of the
3N/A# Common Development and Distribution License (the "License").
3N/A# You may not use this file except in compliance with the License.
3N/A#
3N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3N/A# or http://www.opensolaris.org/os/licensing.
3N/A# See the License for the specific language governing permissions
3N/A# and limitations under the License.
3N/A#
3N/A# When distributing Covered Code, include this CDDL HEADER in each
3N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3N/A# If applicable, add the following below this CDDL HEADER, with the
3N/A# fields enclosed by brackets "[]" replaced with your own identifying
3N/A# information: Portions Copyright [yyyy] [name of copyright owner]
3N/A#
3N/A# CDDL HEADER END
3N/A#
3N/A
3N/A#
2639N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3N/A# Use is subject to license terms.
3N/A#
852N/A
59N/Aimport sys
59N/Aimport pkg.query_parser as qp
1698N/Afrom pkg.query_parser import BooleanQueryException, ParseError
3N/A
2639N/Aclass QueryLexer(qp.QueryLexer):
2639N/A pass
30N/A
175N/Aclass QueryParser(qp.QueryParser):
30N/A """This class exists so that the classes the parent class query parser
30N/A uses to build the AST are the ones defined in this module and not the
30N/A parent class's module. This is done so that a single query parser can
30N/A be shared between the client and server modules but will construct an
30N/A AST using the appropriate classes."""
30N/A
30N/A def __init__(self, lexer):
30N/A qp.QueryParser.__init__(self, lexer)
30N/A mod = sys.modules[QueryParser.__module__]
30N/A tmp = {}
30N/A for class_name in self.query_objs.keys():
933N/A assert hasattr(mod, class_name)
933N/A tmp[class_name] = getattr(mod, class_name)
933N/A self.query_objs = tmp
416N/A
933N/A# Because many classes do not have client specific modifications, they
933N/A# simply subclass the parent module's classes.
3N/Aclass Query(qp.Query):
933N/A pass
933N/A
852N/Aclass AndQuery(qp.AndQuery):
416N/A pass
3N/A
3N/Aclass OrQuery(qp.OrQuery):
3N/A pass
3N/A
1698N/Aclass PkgConversion(qp.PkgConversion):
1698N/A pass
1698N/A
1698N/Aclass PhraseQuery(qp.PhraseQuery):
1698N/A pass
1698N/A
1698N/Aclass FieldQuery(qp.FieldQuery):
526N/A pass
852N/A
526N/Aclass TopQuery(qp.TopQuery):
526N/A pass
526N/A
526N/Aclass TermQuery(qp.TermQuery):
526N/A """This class handles the client specific search logic for searching
526N/A for a specific query term."""
526N/A
526N/A def search(self, restriction, fmris):
526N/A """This function performs the specific steps needed to do
1698N/A search on a server.
2639N/A
2639N/A The "restriction" parameter is a generator over results that
2639N/A another branch of the AST has already found. If it's not None,
2639N/A then it's treated as the domain for search. If it is None then
1698N/A the actions of all known packages is the domain for search.
1698N/A
3N/A The "fmris" parameter is a function which produces an object
1698N/A which iterates over all known fmris."""
1698N/A
1698N/A if restriction:
1698N/A return self._restricted_search_internal(restriction)
146N/A base_res = self._search_internal(fmris)
526N/A it = self._get_results(base_res)
852N/A return it
526N/A