ó ®XRc@sÍddlZddlZddlZddljjZddljZddlj Z ddl j Z ddljZddlmZddljZddlmZmZmZddlZdejfd„ƒYZdejfd„ƒYZdejfd „ƒYZd ejfd „ƒYZd efd „ƒYZdejfd„ƒYZdej fd„ƒYZ dej!fd„ƒYZ!dej"fd„ƒYZ"dej#fd„ƒYZ#dej$fd„ƒYZ$dS(iÿÿÿÿN(tchoose(tBooleanQueryExceptiont ParseErrortQueryLengthExceededt QueryLexercBseZRS((t__name__t __module__(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR&st QueryParsercBseZdZd„ZRS(sYThis class exists so that the classes the parent class query parser uses to build the AST are the ones defined in this module and not the parent class's module. This is done so that a single query parser can be shared between the client and server modules but will construct an AST using the appropriate classes.cCsxtjj||ƒtjtj}i}x?|jjƒD].}t||ƒsTt ‚t ||ƒ||(R RRtRETURN_ACTIONS(R((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyt__str__PscCstjj|_dS(s€Makes this node return packages instead of actions. Returns None because no changes need to be made to the tree.N(RRtRETURN_PACKAGESR tNone(R((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pytpropagate_pkg_returnVs(RRR R"R$R&R)(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRFs     tOrQuerycBseZd„ZRS(cCsj|jj|ƒ}|s0t|jjƒ|_n|jj|ƒ}|s`t|jjƒ|_n|pi|S(N(RRRR R(RRRR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR^s(RRR(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR*]st PkgConversioncBseZd„ZRS(cCs|jj|ƒS(N(tqueryR(RR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRis(RRR(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR+hst PhraseQuerycBseZd„ZRS(cCs|jj|ƒS(N(R,R(RR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRns(RRR(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR-mst FieldQuerycBseZd„ZRS(cCs|jj|ƒS(N(R,R(RR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRss(RRR(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR.rstTopQuerycBsMeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z RS(sžThis class handles raising the exception if the search was conducted without using indexes. It yields all results, then raises the exception.cOs#tjj|||Žt|_dS(N(RR/R tFalset_TopQuery__use_slow_search(RR!R#((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR |scCs|jS(s)Return whether slow search has been used.(R1(R((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pytget_use_slow_search€scCs ||_dS(s&Set whether slow search has been used.N(R1(Rtval((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pytset_use_slow_search…scKs)tjj|d|jd|j|dS(snThis function provides the necessary information to the AST so that a search can be performed.R2R4N(RR/R$R2R4(RR#((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR$Šs cgsAx"tjj||ŒD] }|VqW|jr=tjƒ‚ndS(s¸This function performs performs local client side search. If slow search was used, then after all results have been returned, it raises SlowSearchUsed.N(RR/R"R1t api_errorstSlowSearchUsed(RR!ti((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR"“s  cCs|jj|ƒS(N(R,R(RR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRžscCs:|j}t|tƒr$|j}nt||ƒ|_dS(N(R,t isinstanceR/R*(RRR((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pytadd_or¡s  ( RRRR R2R4R$R"RR9(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR/ws    t TermQuerycBs†eZdZiZiZd„Zd„Zd„Zd„Zd„Z d„Z d„Z d„Z d „Z d „Zd „Zd „ZRS( s`This class handles the client specific search logic for searching for a base query term.cCsDtjj||ƒd|_d|_d|_d|_d|_dS(N( RR:R R(t_impl_fmri_to_patht_efnt_data_fast_removetfull_fmri_hasht_data_fast_add(Rtterm((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR ¯s     cCs||j}||krdStjj||ƒ||}tjtjƒ|dR0tsetNoIndexExceptiontTrueRX(RRYR2R4R#RURN((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR$Ós&       cCsÈ|r|j|ƒS|jƒs±y|jj|jƒWn tjk rXtjƒ‚nX|j|ƒ}|j ||ƒ}|j |ƒ}t j |j |ƒ|j|ƒƒ}|S|j|||ƒSdS(s6This function performs performs local client side search. The "restriction" parameter is a generator over the results that another branch of the AST has already found. If it exists, those results are treated as the domain for search. If it does not exist, search uses the set of actions from installed packages as the domain. The "fmris" parameter is a function which produces an object which iterates over the names of installed fmris. The "manifest_func" parameter is a function which takes a fmri and returns a path to the manifest for that fmri. The "excludes" parameter is a list of the variants defined for this image.N(t_restricted_search_internalR2R>tcheck_against_fileR<R[tIncorrectIndexFileHashR5t_search_internalt_search_fast_updatet_check_fast_removet itertoolstchaint _get_resultst_get_fast_resultst slow_search(Rt restrictiontfmrist manifest_functexcludestbase_rest client_restit((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR"þs      cs‡fd†|DƒS(sñThis function removes any results from the generator "res" (the search results) that are actions from packages known to have been removed from the image since the last time the index was built.c3sE|];\}}}}}ˆjj|ƒs|||||fVqdS(N(R=t has_entity(t.0tp_strtotatstf(R(s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pys ,s((Rtres((Rs=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRc%s c Cs¿|jjƒdk st‚|j}|j}|j}|sEt}ni}g}x|jj D]õ}|j py|j |ƒs‚q^nt j |ƒ} || ƒ} tjj| dtd|ƒ} x•| D]} | \} }}}|jpï||jk sÂ|jp||jk rqÂn| |kr+g|| }tj|ƒ‚nXdS(sLegacy function used to search indexes which have a pkg directory with fmri offset information instead of the fmri_offsets.v1 file. This function is in this subclass to translate the error from a search_error to an api_error.N(RR:t_read_pkg_dirsR[tInconsistentIndexExceptionR5(RRjte((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRŸªscCs½|j rF|jdkrF|jdkrF|jdkrF|jdks~|j r_|jdks~|jj|ƒ s~|dkr‚tS|jdƒ}|jt|ƒ|_d|_t|_t S(Ntfiletlinkthardlinkt directoryRLt/( R†R‡RˆR‰R|t startswithR0trstriptlenR](Rtimg_root((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyRµs   (RRRRPRDR RERVRXR$R"RcRbRgRhRŸR(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyR:¨s     + ' 7 8 (%tosR RRtpkg.client.api_errorstclientR5t pkg.manifestRƒtpkg.search_storagetsearch_storageRFtpkg.search_errorst search_errorsR[tpkg.fmriRt pkg.chooseRtpkg.query_parsert query_parserRRRRRdRRRRtobjectRR*R+R-R.R/R:(((s=/usr/lib/python2.7/vendor-packages/pkg/client/query_parser.pyts,     1