mirror of
https://github.com/beetbox/beets.git
synced 2025-12-31 04:52:49 +01:00
Revise not query syntax, cleanup, modify docstring
* Revise the NotQuery syntax, replacing the '¬' character with '^'. Fix tests to conform to this change, and cleanup the PARSE_QUERY_PART_REGEX. * Modify parse_query_part() docstring to mention the negate parameter on the returned tuple, and added an example.
This commit is contained in:
parent
e69b3b3c5d
commit
40bfed756b
2 changed files with 11 additions and 12 deletions
|
|
@ -23,9 +23,7 @@ import beets
|
|||
|
||||
PARSE_QUERY_PART_REGEX = re.compile(
|
||||
# Non-capturing optional segment for the keyword.
|
||||
r'(?:'
|
||||
ur'(-|\u00ac)' # Negation prefixes
|
||||
r')?'
|
||||
r'(-|\^)?' # Negation prefixes.
|
||||
|
||||
r'(?:'
|
||||
r'(\S+?)' # The field key.
|
||||
|
|
@ -41,9 +39,9 @@ PARSE_QUERY_PART_REGEX = re.compile(
|
|||
def parse_query_part(part, query_classes={}, prefixes={},
|
||||
default_class=query.SubstringQuery):
|
||||
"""Take a query in the form of a key/value pair separated by a
|
||||
colon and return a tuple of `(key, value, cls)`. `key` may be None,
|
||||
colon and return a tuple of `(key, value, cls, negate)`. `key` may be None,
|
||||
indicating that any field may be matched. `cls` is a subclass of
|
||||
`FieldQuery`.
|
||||
`FieldQuery`. `negate` is a boolean indicating if the query is negated.
|
||||
|
||||
The optional `query_classes` parameter maps field names to default
|
||||
query types; `default_class` is the fallback. `prefixes` is a map
|
||||
|
|
@ -57,10 +55,11 @@ def parse_query_part(part, query_classes={}, prefixes={},
|
|||
class is available, `default_class` is used.
|
||||
|
||||
For instance,
|
||||
'stapler' -> (None, 'stapler', SubstringQuery)
|
||||
'color:red' -> ('color', 'red', SubstringQuery)
|
||||
':^Quiet' -> (None, '^Quiet', RegexpQuery)
|
||||
'color::b..e' -> ('color', 'b..e', RegexpQuery)
|
||||
'stapler' -> (None, 'stapler', SubstringQuery, False)
|
||||
'color:red' -> ('color', 'red', SubstringQuery, False)
|
||||
':^Quiet' -> (None, '^Quiet', RegexpQuery, False)
|
||||
'color::b..e' -> ('color', 'b..e', RegexpQuery, False)
|
||||
'-color:red' -> ('color', 'red', SubstringQuery, True)
|
||||
|
||||
Prefixes may be "escaped" with a backslash to disable the keying
|
||||
behavior.
|
||||
|
|
|
|||
|
|
@ -890,7 +890,7 @@ class NotQueryTest(DummyDataTestCase):
|
|||
def test_get_prefixes_keyed(self):
|
||||
"""Test both negation prefixes on a keyed query."""
|
||||
q0 = '-title:qux'
|
||||
q1 = '\u00actitle:qux'
|
||||
q1 = '^title:qux'
|
||||
results0 = self.lib.items(q0)
|
||||
results1 = self.lib.items(q1)
|
||||
self.assert_items_matched(results0, ['foo bar', 'beets 4 eva'])
|
||||
|
|
@ -899,13 +899,13 @@ class NotQueryTest(DummyDataTestCase):
|
|||
def test_get_prefixes_unkeyed(self):
|
||||
"""Test both negation prefixes on an unkeyed query."""
|
||||
q0 = '-qux'
|
||||
q1 = '\u00acqux'
|
||||
q1 = '^qux'
|
||||
results0 = self.lib.items(q0)
|
||||
results1 = self.lib.items(q1)
|
||||
self.assert_items_matched(results0, ['foo bar', 'beets 4 eva'])
|
||||
self.assert_items_matched(results1, ['foo bar', 'beets 4 eva'])
|
||||
|
||||
def test_get_keyed_regexp(self):
|
||||
def test_get_one_keyed_regexp(self):
|
||||
q = r'-artist::t.+r'
|
||||
results = self.lib.items(q)
|
||||
self.assert_items_matched(results, ['foo bar', 'baz qux'])
|
||||
|
|
|
|||
Loading…
Reference in a new issue