Browse Source

Wikicode.matches() can now take a tuple or list.

tags/v0.3.3
Ben Kurtovic 11 years ago
parent
commit
aabe711ee6
4 changed files with 6 additions and 4 deletions
  1. +2
    -2
      CHANGELOG
  2. +1
    -1
      docs/changelog.rst
  3. +1
    -1
      mwparserfromhell/wikicode.py
  4. +2
    -0
      tests/test_wikicode.py

+ 2
- 2
CHANGELOG View File

@@ -5,8 +5,8 @@ v0.4 (unreleased):
is a breaking change if you rely on the default behavior. is a breaking change if you rely on the default behavior.
- The 'matches' argument of Wikicode's filter methods now accepts a function - 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. (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. - C code cleanup and speed improvements.


v0.3.2 (released September 1, 2013): v0.3.2 (released September 1, 2013):


+ 1
- 1
docs/changelog.rst View File

@@ -14,7 +14,7 @@ Unreleased
- The *matches* argument of :py:class:`Wikicode's <.Wikicode>` - The *matches* argument of :py:class:`Wikicode's <.Wikicode>`
:py:meth:`.filter` methods now accepts a function (taking one argument, a :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: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 strings/:py:class:`.Wikicode` objects instead of just a single string or
:py:class:`.Wikicode`. :py:class:`.Wikicode`.
- C code cleanup and speed improvements. - C code cleanup and speed improvements.


+ 1
- 1
mwparserfromhell/wikicode.py View File

@@ -370,7 +370,7 @@ class Wikicode(StringMixIn):
cmp = lambda a, b: (a[0].upper() + a[1:] == b[0].upper() + b[1:] cmp = lambda a, b: (a[0].upper() + a[1:] == b[0].upper() + b[1:]
if a and b else a == b) if a and b else a == b)
this = self.strip_code().strip() this = self.strip_code().strip()
if isinstance(other, tuple):
if isinstance(other, (tuple, list)):
for obj in other: for obj in other:
that = parse_anything(obj).strip_code().strip() that = parse_anything(obj).strip_code().strip()
if cmp(this, that): if cmp(this, that):


+ 2
- 0
tests/test_wikicode.py View File

@@ -254,7 +254,9 @@ class TestWikicode(TreeEqualityTestCase):
self.assertTrue(code1.matches(("cleanup", "stub"))) self.assertTrue(code1.matches(("cleanup", "stub")))
self.assertTrue(code2.matches(("cleanup", "stub"))) self.assertTrue(code2.matches(("cleanup", "stub")))
self.assertFalse(code2.matches(("StuB", "sTUb", "foobar"))) 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(code2.matches(["StuB", "sTUb", "foo", "bar", "Stub"]))
self.assertTrue(code3.matches("")) self.assertTrue(code3.matches(""))
self.assertTrue(code3.matches("<!-- nothing -->")) self.assertTrue(code3.matches("<!-- nothing -->"))
self.assertTrue(code3.matches(("a", "b", ""))) self.assertTrue(code3.matches(("a", "b", "")))


Loading…
Cancel
Save