From 2793af7d7013f41a98a61e0bd5b134d69a50ffba Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 25 Sep 2012 15:13:33 -0700 Subject: [PATCH] zero, the: Python 2.6-compatible format strings --- beetsplug/the.py | 8 ++++---- beetsplug/zero.py | 18 ++++++++++-------- test/test_zero.py | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/beetsplug/the.py b/beetsplug/the.py index df2673793..ab3e9f0a4 100644 --- a/beetsplug/the.py +++ b/beetsplug/the.py @@ -64,12 +64,12 @@ class ThePlugin(BeetsPlugin): try: re.compile(p) except re.error: - print(u'[the] invalid pattern: {}'.format(p), + print(u'[the] invalid pattern: {0}'.format(p), file=sys.stderr) else: if not (p.startswith('^') or p.endswith('$')): if not the_options['silent']: - print(u'[the] warning: pattern \"{}\" will not ' + print(u'[the] warning: pattern \"{0}\" will not ' 'match string start/end'.format(p), file=sys.stderr) if the_options['a']: @@ -79,7 +79,7 @@ class ThePlugin(BeetsPlugin): if not the_options['patterns'] and not the_options['silent']: print('[the] no patterns defined!') if the_options['debug']: - print(u'[the] patterns: {}' + print(u'[the] patterns: {0}' .format(' '.join(the_options['patterns'])), file=sys.stderr) @@ -118,7 +118,7 @@ def func_the(text): if r != text: break if the_options['debug']: - print(u'[the] \"{}\" -> \"{}\"'.format(text, r), file=sys.stderr) + print(u'[the] \"{0}\" -> \"{1}\"'.format(text, r), file=sys.stderr) return r else: return u'' diff --git a/beetsplug/zero.py b/beetsplug/zero.py index 331089681..01e0cd102 100644 --- a/beetsplug/zero.py +++ b/beetsplug/zero.py @@ -43,9 +43,9 @@ class ZeroPlugin(BeetsPlugin): return cls._instance def __str__(self): - return ('[zero]\n debug = {}\n fields = {}\n patterns = {}\n' - ' warned = {}'.format(self.debug, self.fields, self.patterns, - self.warned)) + return ('[zero]\n debug = {0}\n fields = {1}\n patterns = {2}\n' + ' warned = {3}'.format(self.debug, self.fields, self.patterns, + self.warned)) def dbg(self, *args): """Prints message to stderr.""" @@ -59,7 +59,9 @@ class ZeroPlugin(BeetsPlugin): self.debug = ui.config_val(config, 'zero', 'debug', True, bool) for f in ui.config_val(config, 'zero', 'fields', '').split(): if f not in ITEM_KEYS: - self.dbg('invalid field \"{}\" (try \'beet fields\')') + self.dbg( + 'invalid field \"{0}\" (try \'beet fields\')'.format(f) + ) else: self.fields.append(f) p = ui.config_val(config, 'zero', f, '').split() @@ -100,16 +102,16 @@ class ZeroPlugin(BeetsPlugin): try: fval = getattr(item, fn) except AttributeError: - self.dbg('? no such field: {}'.format(fn)) + self.dbg('? no such field: {0}'.format(fn)) else: if not self.match_patterns(fval, self.patterns[fn]): - self.dbg('\"{}\" ({}) is not match any of: {}' + self.dbg('\"{0}\" ({1}) is not match any of: {2}' .format(fval, fn, ' '.join(self.patterns[fn]))) continue - self.dbg('\"{}\" ({}) match: {}' + self.dbg('\"{0}\" ({1}) match: {2}' .format(fval, fn, ' '.join(self.patterns[fn]))) setattr(item, fn, type(fval)()) - self.dbg('{}={}'.format(fn, getattr(item, fn))) + self.dbg('{0}={1}'.format(fn, getattr(item, fn))) @ZeroPlugin.listen('import_task_choice') diff --git a/test/test_zero.py b/test/test_zero.py index 01fa46bd0..7732ca4e9 100644 --- a/test/test_zero.py +++ b/test/test_zero.py @@ -5,7 +5,7 @@ from beets.library import Item from beetsplug.zero import ZeroPlugin -class ThePluginTest(unittest.TestCase): +class ZeroPluginTest(unittest.TestCase): def test_singleton(self): z1 = ZeroPlugin()