[docs]deflist_tokens(url:str,pattern:Optional[str]=None,field:Optional[str]=None,count:bool=False,number:int=100,on_truncation:Literal["message","warning","none"]="message")->List[Dict]:""" List available tokens in the SewerRat database. Args: url: URL to the SewerRat REST API. pattern: Pattern for filtering tokens, using the usual ``*`` and ``?`` wildcards. Only tokens matching to the pattern will be returned. If ``None``, no filtering is performed. field: Metadata property field for filtering tokens. Only tokens found in the specified field will be returned. If ``None``, no filtering is performed. count: Whether to count the number of metadata files associated with each token. number: Integer specifying the maximum number of results to return. This can also be ``float("inf")`` to retrieve all available results. on_truncation: String specifying the action to take when the number of search results is capped by ``number``. Returns: List of dictionaries where each dictionary corresponds to a token and contains: - ``token``, string containing the token. - ``count``, integer specifying the number of files associated with the token. This is only present if ``count=True`` in the function call. """query=[]ifpatternisnotNone:query.append("pattern="+urllib.parse.quote_plus(pattern))iffieldisnotNone:query.append("field="+urllib.parse.quote_plus(field))ifcount:query.append("count=true")stub="/tokens"use_question=Trueiflen(query)>0:stub+="?"+"&".join(query)use_question=Falseoriginal_number=numberifon_truncation!="none":number+=1collected=[]whilelen(collected)<number:current_url=url+stubifnumber!=float("inf"):sep="&"ifuse_question:sep="?"current_url+=sep+"limit="+str(number-len(collected))res=requests.get(current_url)ifres.status_code>=300:raiseut.format_error(res)payload=res.json()collected+=payload["results"]if"next"notinpayload:breakstub=payload["next"]use_question=Falsereturnut.handle_truncated_pages(on_truncation,original_number,collected)