[docs]classQuery(Generic[T]):r"""This class represents the query data sent from flow launcher This class implements a generic for the :attr:`~flogin.query.Query.condition_data` attribute, which will be used for typechecking purposes. .. container:: operations .. describe:: x == y Compare the keywords, text, and is_query values of two query objects. .. describe:: hash(x) Gets the hash of the query's raw text Attributes ---------- raw_text: :class:`str`: The raw and complete query, which includes the keyword is_requery: :class:`bool` Whether the query is a requery or not text: :class:`str` The actual query, excluding any keywords keyword: :class:`str` The keyword used to initiate the query """def__init__(self,data:RawQuery,plugin:PluginT)->None:self.__search_condition_data:T|None=Noneself._data=dataself.plugin=plugin@propertydefcondition_data(self)->T|None:"""Any | None: If used in a :class:`~flogin.search_handler.SearchHandler`, this attribute will return any extra data that the condition gave."""returnself.__search_condition_data@condition_data.setterdefcondition_data(self,value:T)->None:self.__search_condition_data=value@propertydefis_requery(self)->bool:returnself._data["isReQuery"]@propertydefkeyword(self)->str:returnself._data["actionKeyword"]@propertydefraw_text(self)->str:returnself._data["rawQuery"]@propertydeftext(self)->str:returnself._data["search"]def__eq__(self,other:Any)->bool:return(isinstance(other,Query)andother.raw_text==self.raw_textandother.is_requery==self.is_requery)def__hash__(self)->int:returnhash(self.raw_text)def__repr__(self)->str:returnf"<Query {self.raw_text=}{self.text=}{self.keyword=}{self.is_requery=}{self.condition_data=}>"
[docs]asyncdefupdate_results(self,results:list[Result])->None:r"""|coro| Tells flow to change the results shown to the user, using the query from this query object. This method provides quick acess to :func:`flogin.flow.api.FlowLauncherAPI.update_results`. Because of that, this method will only take affect if the user has not changed the query. Parameters ---------- results: list[:class:`~flogin.jsonrpc.results.Result`] The new results Returns ------- None """returnawaitself.plugin.api.update_results(self.raw_text,results)
[docs]asyncdefupdate(self,*,text:str,keyword:str|None=MISSING,requery:bool=False)->None:r"""|coro| Applies updates to the query with flow, and to this object. This method provides quick acess to :func:`flogin.flow.api.FlowLauncherAPI.change_query` Parameters ---------- text: :class:`str` The text that will be used with the query. keyword: :class:`str` The keyword that will be used with the query. Defaults to the pre-existing value of :attr:`Query.keyword`. Set this to ``None`` or `"*"` for no keyword to be used. requery: :class:`bool` Whether or not to re-send a query request in the event that the new query is the same as the current query Returns -------- None """ifkeywordisMISSING:keyword=self.keywordifkeywordisNoneorkeyword=="*":raw_text=textself._data["actionKeyword"]="*"else:raw_text=f"{keyword}{text}"self._data["actionKeyword"]=keywordself._data["rawQuery"]=raw_textself._data["search"]=textself._data["isReQuery"]=requeryreturnawaitself.plugin.api.change_query(raw_text,requery=requery)