From ba333c77e174b4a2663ff9dad10950e9bc00d323 Mon Sep 17 00:00:00 2001 From: Tracy Poff Date: Fri, 4 Mar 2022 22:42:00 -0500 Subject: [PATCH] Support qkeep=True to keep all query parameters. --- src/promnesia/cannon.py | 5 ++++- tests/cannon.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/promnesia/cannon.py b/src/promnesia/cannon.py index 902b8bdb..b76cb9f0 100755 --- a/src/promnesia/cannon.py +++ b/src/promnesia/cannon.py @@ -105,11 +105,13 @@ def canonify_domain(dom: str) -> str: # TODO perhaps, decide if fragment is meaningful (e.g. wiki) or random sequence of letters? class Spec(NamedTuple): - qkeep : Optional[Collection[str]] = None + qkeep : Optional[Union[Collection[str], bool]] = None qremove: Optional[Set[str]] = None fkeep : bool = False def keep_query(self, q: str) -> Optional[int]: # returns order + if self.qkeep is True: + return 1 qkeep = { q: i for i, q in enumerate(chain(default_qkeep, self.qkeep or [])) } @@ -183,6 +185,7 @@ def make(cls, **kwargs) -> 'Spec': 'ycombinator.com' : S(qkeep={'id'}), # todo just keep id by default? 'play.google.com' : S(qkeep={'id'}), 'answers.yahoo.com' : S(qkeep={'qid'}), + 'isfdb.org': S(qkeep=True), } _def_spec = S() diff --git a/tests/cannon.py b/tests/cannon.py index b8960b89..5cd6ef50 100644 --- a/tests/cannon.py +++ b/tests/cannon.py @@ -302,3 +302,11 @@ def test_error(): ]) def test_empty_query_parameter(url, expected): assert canonify(url) == expected + +@pytest.mark.parametrize("url,expected", [ + ('http://www.isfdb.org/cgi-bin/title.cgi?2172', 'isfdb.org/cgi-bin/title.cgi?2172='), + ('http://www.isfdb.org/cgi-bin/title.cgi?2172+1', 'isfdb.org/cgi-bin/title.cgi?2172%201='), + ('http://www.isfdb.org/cgi-bin/title.cgi?2172&foo=bar&baz&quux', 'isfdb.org/cgi-bin/title.cgi?2172=&baz=&foo=bar&quux='), +]) +def test_qkeep_true(url, expected): + assert canonify(url) == expected