Source code for sewerrat.query

-from typing import Optional, List, Dict
+from typing import Optional, List, Dict, Literal
 import requests
+import warnings
 
 from . import _utils as ut
 
 
 
[docs] -def query(url, text: Optional[str] = None, user: Optional[str] = None, path: Optional[str] = None, after: Optional[int] = None, before: Optional[int] = None, number: int = 100) -> List[Dict]: +def query( + url: str, + text: Optional[str] = None, + user: Optional[str] = None, + path: Optional[str] = None, + after: Optional[int] = None, + before: Optional[int] = None, + number: int = 100, + on_truncation: Literal["message", "warning", "none"] = "message") -> List[Dict]: """ Query the metadata in the SewerRat backend based on free text, the owner, creation time, etc. This function does not require filesystem access. @@ -284,6 +293,10 @@

Source code for sewerrat.query

 
         number:
             Integer specifying the maximum number of results to return.
+
+        on_truncation:
+            String specifying the action to take when the number of search
+            results is capped by ``number``.
     
     Returns:
         List of dictionaries where each inner dictionary corresponds to a
@@ -318,7 +331,11 @@ 

Source code for sewerrat.query

     else:
         raise ValueError("at least one search filter must be present")
 
-    stub = "/query?translate=true&limit=" + str(number)
+    if on_truncation != "none":
+        original_number = number
+        number += 1
+
+    stub = "/query?translate=true"
     collected = []
 
     while len(collected) < number:
@@ -332,6 +349,15 @@ 

Source code for sewerrat.query

             break
         stub = payload["next"]
 
+    if on_truncation != "none":
+        if len(collected) > original_number:
+            msg = "truncated query results to the first " + str(original_number) + " matches"
+            if on_truncation == "warning":
+                warnings.warn(msg)
+            else:
+                print(msg)
+            collected = collected[:original_number]
+
     return collected
@@ -366,7 +392,7 @@

Source code for sewerrat.query

       
     
   
-
+
diff --git a/_modules/sewerrat/register.html b/_modules/sewerrat/register.html index a6c38c7..d70935a 100644 --- a/_modules/sewerrat/register.html +++ b/_modules/sewerrat/register.html @@ -5,7 +5,7 @@ - sewerrat.register - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat.register - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -165,7 +165,7 @@
@@ -189,7 +189,7 @@ +
diff --git a/_modules/sewerrat/retrieve_directory.html b/_modules/sewerrat/retrieve_directory.html index 8069763..174fff6 100644 --- a/_modules/sewerrat/retrieve_directory.html +++ b/_modules/sewerrat/retrieve_directory.html @@ -5,7 +5,7 @@ - sewerrat.retrieve_directory - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat.retrieve_directory - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -165,7 +165,7 @@
@@ -189,7 +189,7 @@ +
diff --git a/_modules/sewerrat/retrieve_file.html b/_modules/sewerrat/retrieve_file.html index c5109c1..06a8fdd 100644 --- a/_modules/sewerrat/retrieve_file.html +++ b/_modules/sewerrat/retrieve_file.html @@ -5,7 +5,7 @@ - sewerrat.retrieve_file - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat.retrieve_file - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -165,7 +165,7 @@
@@ -189,7 +189,7 @@ +
diff --git a/_modules/sewerrat/retrieve_metadata.html b/_modules/sewerrat/retrieve_metadata.html index 3e52ec5..235a3d4 100644 --- a/_modules/sewerrat/retrieve_metadata.html +++ b/_modules/sewerrat/retrieve_metadata.html @@ -5,7 +5,7 @@ - sewerrat.retrieve_metadata - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat.retrieve_metadata - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -165,7 +165,7 @@
@@ -189,7 +189,7 @@ +
diff --git a/_modules/sewerrat/start_sewerrat.html b/_modules/sewerrat/start_sewerrat.html index dd55489..fb90193 100644 --- a/_modules/sewerrat/start_sewerrat.html +++ b/_modules/sewerrat/start_sewerrat.html @@ -5,7 +5,7 @@ - sewerrat.start_sewerrat - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat.start_sewerrat - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -165,7 +165,7 @@
@@ -189,7 +189,7 @@ +
diff --git a/_static/documentation_options.js b/_static/documentation_options.js index 5769d97..6a4c7fb 100644 --- a/_static/documentation_options.js +++ b/_static/documentation_options.js @@ -1,5 +1,5 @@ const DOCUMENTATION_OPTIONS = { - VERSION: '0.0.post1.dev1+g3e87e4b', + VERSION: '0.0.post1.dev1+g1317074', LANGUAGE: 'en', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/api/modules.html b/api/modules.html index 1454a48..d5d4bcb 100644 --- a/api/modules.html +++ b/api/modules.html @@ -6,7 +6,7 @@ - sewerrat - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -166,7 +166,7 @@
diff --git a/api/sewerrat.html b/api/sewerrat.html index 1fdaa0a..bbb4b9d 100644 --- a/api/sewerrat.html +++ b/api/sewerrat.html @@ -6,7 +6,7 @@ - sewerrat package - SewerRat 0.0.post1.dev1+g3e87e4b documentation + sewerrat package - SewerRat 0.0.post1.dev1+g1317074 documentation @@ -166,7 +166,7 @@