diff --git a/README.rst b/README.rst index 66bc41a..ff416e2 100644 --- a/README.rst +++ b/README.rst @@ -1,5 +1,5 @@ mwparserfromhell -======================== +================ **mwparserfromhell** (the *MediaWiki Parser from Hell*) is a Python package that provides an easy-to-use and outrageously powerful parser for MediaWiki_ diff --git a/mwparserfromhell/smart_list.py b/mwparserfromhell/smart_list.py index 1f1f505..9a77e19 100644 --- a/mwparserfromhell/smart_list.py +++ b/mwparserfromhell/smart_list.py @@ -289,17 +289,21 @@ class _ListProxy(list): @property def _start(self): + """The starting index of this list, inclusive.""" return self._sliceinfo[0] @property def _stop(self): + """The ending index of this list, exclusive.""" return self._sliceinfo[1] @property def _step(self): + """The number to increase the index by between items.""" return self._sliceinfo[2] def _render(self): + """Return the actual list from the stored start/stop/step.""" return list(self._parent)[self._start:self._stop:self._step] @inheritdoc diff --git a/mwparserfromhell/utils.py b/mwparserfromhell/utils.py index eea2946..41a2044 100644 --- a/mwparserfromhell/utils.py +++ b/mwparserfromhell/utils.py @@ -27,7 +27,6 @@ provide additional functionality. from __future__ import unicode_literals -import mwparserfromhell from .compat import bytes, str from .nodes import Node from .smart_list import SmartList @@ -44,19 +43,21 @@ def parse_anything(value): :py:class:`~.Template`, such as :py:meth:`wikicode.insert() <.Wikicode.insert>` or setting :py:meth:`template.name <.Template.name>`. """ - wikicode = mwparserfromhell.wikicode.Wikicode - if isinstance(value, wikicode): + from . import parse + from .wikicode import Wikicode + + if isinstance(value, Wikicode): return value elif isinstance(value, Node): - return wikicode(SmartList([value])) + return Wikicode(SmartList([value])) elif isinstance(value, str): - return mwparserfromhell.parse(value) + return parse(value) elif isinstance(value, bytes): - return mwparserfromhell.parse(value.decode("utf8")) + return parse(value.decode("utf8")) elif isinstance(value, int): - return mwparserfromhell.parse(str(value)) + return parse(str(value)) elif value is None: - return wikicode(SmartList()) + return Wikicode(SmartList()) try: nodelist = SmartList() for item in value: @@ -64,4 +65,4 @@ def parse_anything(value): except TypeError: error = "Needs string, Node, Wikicode, int, None, or iterable of these, but got {0}: {1}" raise ValueError(error.format(type(value).__name__, value)) - return wikicode(nodelist) + return Wikicode(nodelist) diff --git a/mwparserfromhell/wikicode.py b/mwparserfromhell/wikicode.py index f355cc8..cebc61b 100644 --- a/mwparserfromhell/wikicode.py +++ b/mwparserfromhell/wikicode.py @@ -143,6 +143,7 @@ class Wikicode(StringMixIn): the starting indentation. """ def write(*args): + """Write a new line following the proper indentation rules.""" if lines and lines[-1] is marker: # Continue from the last line lines.pop() # Remove the marker last = lines.pop()