Skip to content

Commit

Permalink
Use PyParsing snake_case names
Browse files Browse the repository at this point in the history
PyParsing has adopted PEP-8. Replaced all the compatibility synonyms
with the new snake_case names.

Fixes puddletag#695
  • Loading branch information
corubba committed Feb 11, 2022
1 parent a7e8280 commit 7005c61
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
2 changes: 0 additions & 2 deletions console
Expand Up @@ -290,8 +290,6 @@ def main():
'format': Format}
options, actions = parseoptions(classes)
files = options.filename
identifier = QuotedString('"') | Combine(NotAny('\\') + Word(alphanums + ' !"#$%&\'()*+-./:;<=>?@[\\]^_`{|}~'))
tags = delimitedList(identifier)
commands = []
for command, args in [list(action.items())[0] for action in actions]:
# Instantiate the class for the command
Expand Down
2 changes: 1 addition & 1 deletion docs/_sources/download.txt
Expand Up @@ -21,7 +21,7 @@ Install instructions follow below.

+ At least `Python 3.8<http://python.org>`_
+ `PyQt5<http://www.riverbankcomputing.co.uk/software/pyqt/intro>`_ for the GUI.
+ `PyParsing (≥1.5.1) <http://pyparsing.wikispaces.com>`_ takes care of the parsing...
+ `PyParsing (≥3.0) <https://pypi.org/project/pyparsing/>`_ mtakes care of the parsing...
+ `Mutagen (≥1.45) <http://code.google.com/p/mutagen/>`_ is used as the tagging lib and...
+ `Chromaprint (≥ 0.4) <http://acoustid.org/chromaprint>`_ (optional) for AcoustID support.

Expand Down
2 changes: 1 addition & 1 deletion docs/download.html
Expand Up @@ -93,7 +93,7 @@ <h1>Download<a class="headerlink" href="#download" title="Permalink to this head
<ul class="simple">
<li><p>At least <a href="#id6"><span class="problematic" id="id7">`Python 3.8&lt;http://python.org&gt;`_</span></a></p></li>
<li><p><a href="#id8"><span class="problematic" id="id9">`PyQt5&lt;http://www.riverbankcomputing.co.uk/software/pyqt/intro&gt;`_</span></a> for the GUI.</p></li>
<li><p><a class="reference external" href="http://pyparsing.wikispaces.com">PyParsing (≥1.5.1)</a> takes care of the parsing…</p></li>
<li><p><a class="reference external" href="https://pypi.org/project/pyparsing/">PyParsing (≥3.0)</a> takes care of the parsing…</p></li>
<li><p><a class="reference external" href="http://code.google.com/p/mutagen/">Mutagen (≥1.45)</a> is used as the tagging lib and…</p></li>
<li><p><a class="reference external" href="http://acoustid.org/chromaprint">Chromaprint (≥ 0.4)</a> (optional) for AcoustID support.</p></li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion docsrc/download.txt
Expand Up @@ -21,7 +21,7 @@ Install instructions follow below.

+ At least `Python 3.8<http://python.org>`_
+ `PyQt5<http://www.riverbankcomputing.co.uk/software/pyqt/intro>`_ for the GUI.
+ `PyParsing (≥1.5.1) <http://pyparsing.wikispaces.com>`_ takes care of the parsing...
+ `PyParsing (≥3.0) <https://pypi.org/project/pyparsing/>`_ mtakes care of the parsing...
+ `Mutagen (≥1.45) <http://code.google.com/p/mutagen/>`_ is used as the tagging lib and...
+ `Chromaprint (≥ 0.4) <http://acoustid.org/chromaprint>`_ (optional) for AcoustID support.

Expand Down
6 changes: 3 additions & 3 deletions puddlestuff/actiondlg.py
Expand Up @@ -9,7 +9,7 @@
from PyQt5.QtWidgets import QAbstractItemView, QAction, QApplication, QCheckBox, QComboBox, QCompleter, \
QDialog, QFrame, QGridLayout, QInputDialog, QLabel, QLineEdit, QListWidgetItem, QMenu, QMessageBox, \
QScrollArea, QSizePolicy, QSpinBox, QStackedWidget, QToolButton, QVBoxLayout, QWidget
from pyparsing import delimitedList, alphanums, Combine, Word, QuotedString
from pyparsing import delimited_list, alphanums, Combine, Word, QuotedString

from . import findfunc, functions
from . import functions_dialogs
Expand Down Expand Up @@ -187,7 +187,7 @@ def __init__(self, funcname, selected_fields=False, userargs=None,
QWidget.__init__(self, parent)
identifier = QuotedString('"') | Combine(Word
(alphanums + ' !"#$%&\'()*+-./:;<=>?@[\\]^_`{|}~'))
tags = delimitedList(identifier)
tags = delimited_list(identifier)
self.func = Function(funcname)
docstr = self.func.doc[1:]
self.vbox = QVBoxLayout()
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(self, funcname, selected_fields=False, userargs=None,
# Loop that creates all the controls
self.controls = []
for argno, line in enumerate(docstr):
args = tags.parseString(line)
args = tags.parse_string(line)
label = args[0]
ctype = args[1]
default = args[2:]
Expand Down
34 changes: 18 additions & 16 deletions puddlestuff/audio_filter.py
Expand Up @@ -2,7 +2,9 @@
import logging
import re

from pyparsing import *
from pyparsing import (CaselessLiteral, OpAssoc, Combine, Word,
alphanums, QuotedString, infix_notation)


from . import findfunc, audioinfo
from .puddleobjects import gettaglist
Expand Down Expand Up @@ -164,31 +166,31 @@ def __bool__(self):


bool_exprs = [
(CaselessLiteral("missing"), 1, opAssoc.RIGHT, Missing),
(CaselessLiteral("present"), 1, opAssoc.RIGHT, Present),
(CaselessLiteral("greater"), 2, opAssoc.LEFT, Greater),
(CaselessLiteral("less"), 2, opAssoc.LEFT, Less),
(CaselessLiteral("equal"), 2, opAssoc.LEFT, Equal),
(CaselessLiteral("has"), 2, opAssoc.LEFT, Has),
(CaselessLiteral("matches"), 2, opAssoc.LEFT, Matches),
(CaselessLiteral("is"), 2, opAssoc.LEFT, BoolIs),
(CaselessLiteral("and"), 2, opAssoc.LEFT, BoolAnd),
(CaselessLiteral("or"), 2, opAssoc.LEFT, BoolOr),
(CaselessLiteral("not"), 1, opAssoc.RIGHT, BoolNot),
(CaselessLiteral("missing"), 1, OpAssoc.RIGHT, Missing),
(CaselessLiteral("present"), 1, OpAssoc.RIGHT, Present),
(CaselessLiteral("greater"), 2, OpAssoc.LEFT, Greater),
(CaselessLiteral("less"), 2, OpAssoc.LEFT, Less),
(CaselessLiteral("equal"), 2, OpAssoc.LEFT, Equal),
(CaselessLiteral("has"), 2, OpAssoc.LEFT, Has),
(CaselessLiteral("matches"), 2, OpAssoc.LEFT, Matches),
(CaselessLiteral("is"), 2, OpAssoc.LEFT, BoolIs),
(CaselessLiteral("and"), 2, OpAssoc.LEFT, BoolAnd),
(CaselessLiteral("or"), 2, OpAssoc.LEFT, BoolOr),
(CaselessLiteral("not"), 1, OpAssoc.RIGHT, BoolNot),
]

field_expr = Combine('%' + Word(alphanums + '_') + '%')
tokens = QuotedString('"', unquoteResults=False) \
tokens = QuotedString('"', unquote_results=False) \
| field_expr | Word(alphanums + '_')
bool_expr = infixNotation(tokens, bool_exprs)
bool_expr.enablePackrat()
bool_expr = infix_notation(tokens, bool_exprs)
bool_expr.enable_packrat()


def parse(audio, expr):
for i in bool_exprs:
i[3].audio = audio
try:
res = bool_expr.parseString(expr)[0]
res = bool_expr.parse_string(expr)[0]
except ParseException as e:
res = expr
if isinstance(res, str):
Expand Down
36 changes: 18 additions & 18 deletions puddlestuff/findfunc.py
Expand Up @@ -10,8 +10,8 @@
from functools import partial

from pyparsing import (Word, alphas, Literal, OneOrMore, alphanums,
nums, delimitedList, Combine, QuotedString,
CharsNotIn, originalTextFor, nestedExpr,
nums, delimited_list, Combine, QuotedString,
CharsNotIn, original_text_for, nested_expr,
Optional)

from . import audioinfo
Expand Down Expand Up @@ -216,27 +216,27 @@ def func_tokens(dictionary, parse_action):
func_name = Word(alphas + '_', alphanums + '_')

func_ident = Combine('$' + func_name.copy()('funcname'))
func_tok = func_ident + originalTextFor(nestedExpr())('args')
func_tok.leaveWhitespace()
func_tok.setParseAction(parse_action)
func_tok.enablePackrat()
func_tok = func_ident + original_text_for(nested_expr())('args')
func_tok.leave_whitespace()
func_tok.set_parse_action(parse_action)
func_tok.enable_packrat()

rx_tok = Combine(Literal('$').suppress() + Word(nums)('num'))

def replace_token(tokens):
index = int(tokens.num)
return dictionary.get(index, '')

rx_tok.setParseAction(replace_token)
rx_tok.set_parse_action(replace_token)

strip = lambda s, l, tok: tok[0].strip()
text_tok = CharsNotIn(',').setParseAction(strip)
text_tok = CharsNotIn(',').set_parse_action(strip)
quote_tok = QuotedString('"')

if dictionary:
arglist = Optional(delimitedList(quote_tok | rx_tok | text_tok))
arglist = Optional(delimited_list(quote_tok | rx_tok | text_tok))
else:
arglist = Optional(delimitedList(quote_tok | text_tok))
arglist = Optional(delimited_list(quote_tok | text_tok))

return func_tok, arglist, rx_tok

Expand Down Expand Up @@ -768,12 +768,12 @@ def what(s, loc, tok):
return "(.*)"
return "(.*?)"

expression.setParseAction(what)
expression.set_parse_action(what)
global numtimes
numtimes = len([z for z in expression.scanString(pattern)])
numtimes = len([z for z in expression.scan_string(pattern)])
if not numtimes:
return
pattern = expression.transformString(pattern)
pattern = expression.transform_string(pattern)
try:
tags = re.search(pattern, text).groups()
except AttributeError:
Expand Down Expand Up @@ -834,9 +834,9 @@ def reInit(self):
self.doc = self.function.__doc__.split("\n")

identifier = QuotedString('"') | Combine(Word(alphanums + ' !"#$%&\'()*+-./:;<=>?@[\\]^_`{|}~'))
tags = delimitedList(identifier)
tags = delimited_list(identifier)

self.info = [z for z in tags.parseString(self.doc[0])]
self.info = [z for z in tags.parse_string(self.doc[0])]

def setArgs(self, args):
self.args = args
Expand Down Expand Up @@ -900,15 +900,15 @@ def description(self):

def _getControls(self, index=1):
identifier = QuotedString('"') | CharsNotIn(',')
arglist = delimitedList(identifier)
arglist = delimited_list(identifier)
docstr = self.doc[1:]
if index:
return [(arglist.parseString(line)[index]).strip()
return [(arglist.parse_string(line)[index]).strip()
for line in docstr]
else:
ret = []
for line in docstr:
ret.append([z.strip() for z in arglist.parseString(line)])
ret.append([z.strip() for z in arglist.parse_string(line)])
return ret

def setTag(self, tag):
Expand Down
6 changes: 3 additions & 3 deletions puddlestuff/tagsources/mp3tag/__init__.py
Expand Up @@ -35,8 +35,8 @@ def getnum(s, l, t):
return int(''.join(t))


STRING = QuotedString('"', '\\', unquoteResults=False).setParseAction(unquote)
NUMBER = Combine(Optional('-') + Word(nums)).setParseAction(getnum)
STRING = QuotedString('"', '\\', unquote_results=False).set_parse_action(unquote)
NUMBER = Combine(Optional('-') + Word(nums)).set_parse_action(getnum)
COVER = '#cover-url'

ARGUMENT = STRING | NUMBER
Expand Down Expand Up @@ -153,7 +153,7 @@ def parse_func(lineno, line):
funcname = line.split(None, 1)[0].strip()
arg_string = line[len(funcname):]
args = (z[0]
for z in ARGUMENT.searchString(arg_string).asList())
for z in ARGUMENT.search_string(arg_string).as_list())
args = [i.replace('\\\\', '\\') if isinstance(i, str) else i
for i in args]
if funcname and not funcname.startswith('#'):
Expand Down
2 changes: 1 addition & 1 deletion puddletag
Expand Up @@ -125,7 +125,7 @@ def check_libs():
('configobj', '(usually python3-configobj)',
'http://code.google.com/p/configobj/'),
('pyparsing', '(python3-pyparsing or python3-parsing in most distros)',
'http://pyparsing.wikispaces.com/'),
'https://github.com/pyparsing/pyparsing/'),
('PyQt5', '(python3-pyqt5 usually)',
'http://www.riverbankcomputing.co.uk/software/pyqt/intro')]

Expand Down

0 comments on commit 7005c61

Please sign in to comment.