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