Skip to content

Commit

Permalink
simplify parsing by removing unsupported operators
Browse files Browse the repository at this point in the history
Mopidy can't handle not-matching, so no need to implement this. This is
a seperate commit, so if in the future Mopidy gains this ability, it can
be easily reintroduced.
  • Loading branch information
girst committed Jan 14, 2022
1 parent 36985e0 commit ecc666c
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions mopidy_mpd/protocol/filter_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,11 @@ def __exit__(self, exc_type, exc_value, traceback):
c = takeChar(self.it)
Assert(c == ')', "')' expected")

operators_inverted = {
'==': '!=',
'!=': '==',
'=~': '!~',
'!~': '=~',
'contains': '!contains',
'!contains': 'contains',
}

def parse_subexpression(it):
with parenthesis(it):
if it.peek() == '!': # (!EXPRESSION)
takeChar(it) # consume '!'
subexpression = parse_subexpression(it)
Assert(
# Mopidy doesn't support either-this-or-that style queries.
len(subexpression) == 1,
"inverting (AND) not supported"
)
filter_type, operator, value = subexpression[0]
inverted_operator = operators_inverted[operator]
return [(filter_type, inverted_operator, value)]
# Mopidy cannot handle '!=', so there's no point in handling this
raise exceptions.MpdArgError('non-matching not supported in Mopidy')

elif it.peek() == '(': # (EXPRESSION1 AND EXPRESSION2 ...)
subexpressions = [parse_subexpression(it)]
Expand All @@ -125,7 +108,11 @@ def parse_subexpression(it):
else: # TAG, 'any', 'file', 'filename', 'AudioFormat'
operator = takeWord(it, is_operator).lower()
Assert(
operator in operators_inverted.keys(),
operator not in ('!=', '!~', '!contains'),
"non-matching not supported in Mopidy"
)
Assert(
operator in ('==', '=~', 'contains'),
'invalid operator'
)
value = takeQuoted(it)
Expand Down

0 comments on commit ecc666c

Please sign in to comment.