From aabe711ee6bf989227fc6937598e362283b76ae2 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 19 Oct 2013 18:54:13 -0400 Subject: [PATCH] Wikicode.matches() can now take a tuple or list. --- CHANGELOG | 4 ++-- docs/changelog.rst | 2 +- mwparserfromhell/wikicode.py | 2 +- tests/test_wikicode.py | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a00f8f3..fc6cd3c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,8 +5,8 @@ v0.4 (unreleased): is a breaking change if you rely on the default behavior. - The 'matches' argument of Wikicode's filter methods now accepts a function (taking one argument, a Node, and returning a bool) in addition to a regex. -- Wikicode.matches() now accepts a tuple of strings/Wikicode objects instead of - just a single string or Wikicode. +- Wikicode.matches() now accepts a tuple or list of strings/Wikicode objects + instead of just a single string or Wikicode. - C code cleanup and speed improvements. v0.3.2 (released September 1, 2013): diff --git a/docs/changelog.rst b/docs/changelog.rst index 6708f0f..c7c5c56 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,7 +14,7 @@ Unreleased - The *matches* argument of :py:class:`Wikicode's <.Wikicode>` :py:meth:`.filter` methods now accepts a function (taking one argument, a :py:class:`.Node`, and returning a bool) in addition to a regex. -- :py:meth:`.Wikicode.matches` now accepts a tuple of +- :py:meth:`.Wikicode.matches` now accepts a tuple or list of strings/:py:class:`.Wikicode` objects instead of just a single string or :py:class:`.Wikicode`. - C code cleanup and speed improvements. diff --git a/mwparserfromhell/wikicode.py b/mwparserfromhell/wikicode.py index b7d2ab2..4a0763d 100644 --- a/mwparserfromhell/wikicode.py +++ b/mwparserfromhell/wikicode.py @@ -370,7 +370,7 @@ class Wikicode(StringMixIn): cmp = lambda a, b: (a[0].upper() + a[1:] == b[0].upper() + b[1:] if a and b else a == b) this = self.strip_code().strip() - if isinstance(other, tuple): + if isinstance(other, (tuple, list)): for obj in other: that = parse_anything(obj).strip_code().strip() if cmp(this, that): diff --git a/tests/test_wikicode.py b/tests/test_wikicode.py index 632c6b4..26168a0 100644 --- a/tests/test_wikicode.py +++ b/tests/test_wikicode.py @@ -254,7 +254,9 @@ class TestWikicode(TreeEqualityTestCase): self.assertTrue(code1.matches(("cleanup", "stub"))) self.assertTrue(code2.matches(("cleanup", "stub"))) self.assertFalse(code2.matches(("StuB", "sTUb", "foobar"))) + self.assertFalse(code2.matches(["StuB", "sTUb", "foobar"])) self.assertTrue(code2.matches(("StuB", "sTUb", "foo", "bar", "Stub"))) + self.assertTrue(code2.matches(["StuB", "sTUb", "foo", "bar", "Stub"])) self.assertTrue(code3.matches("")) self.assertTrue(code3.matches("")) self.assertTrue(code3.matches(("a", "b", "")))