Browse Source

Final fixes and cleanup before release.

tags/v0.1
Ben Kurtovic 12 years ago
parent
commit
1905456b4d
4 changed files with 16 additions and 10 deletions
  1. +1
    -1
      README.rst
  2. +4
    -0
      mwparserfromhell/smart_list.py
  3. +10
    -9
      mwparserfromhell/utils.py
  4. +1
    -0
      mwparserfromhell/wikicode.py

+ 1
- 1
README.rst View File

@@ -1,5 +1,5 @@
mwparserfromhell mwparserfromhell
========================
================


**mwparserfromhell** (the *MediaWiki Parser from Hell*) is a Python package **mwparserfromhell** (the *MediaWiki Parser from Hell*) is a Python package
that provides an easy-to-use and outrageously powerful parser for MediaWiki_ that provides an easy-to-use and outrageously powerful parser for MediaWiki_


+ 4
- 0
mwparserfromhell/smart_list.py View File

@@ -289,17 +289,21 @@ class _ListProxy(list):


@property @property
def _start(self): def _start(self):
"""The starting index of this list, inclusive."""
return self._sliceinfo[0] return self._sliceinfo[0]


@property @property
def _stop(self): def _stop(self):
"""The ending index of this list, exclusive."""
return self._sliceinfo[1] return self._sliceinfo[1]


@property @property
def _step(self): def _step(self):
"""The number to increase the index by between items."""
return self._sliceinfo[2] return self._sliceinfo[2]


def _render(self): def _render(self):
"""Return the actual list from the stored start/stop/step."""
return list(self._parent)[self._start:self._stop:self._step] return list(self._parent)[self._start:self._stop:self._step]


@inheritdoc @inheritdoc


+ 10
- 9
mwparserfromhell/utils.py View File

@@ -27,7 +27,6 @@ provide additional functionality.


from __future__ import unicode_literals from __future__ import unicode_literals


import mwparserfromhell
from .compat import bytes, str from .compat import bytes, str
from .nodes import Node from .nodes import Node
from .smart_list import SmartList from .smart_list import SmartList
@@ -44,19 +43,21 @@ def parse_anything(value):
:py:class:`~.Template`, such as :py:meth:`wikicode.insert() :py:class:`~.Template`, such as :py:meth:`wikicode.insert()
<.Wikicode.insert>` or setting :py:meth:`template.name <.Template.name>`. <.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 return value
elif isinstance(value, Node): elif isinstance(value, Node):
return wikicode(SmartList([value]))
return Wikicode(SmartList([value]))
elif isinstance(value, str): elif isinstance(value, str):
return mwparserfromhell.parse(value)
return parse(value)
elif isinstance(value, bytes): elif isinstance(value, bytes):
return mwparserfromhell.parse(value.decode("utf8"))
return parse(value.decode("utf8"))
elif isinstance(value, int): elif isinstance(value, int):
return mwparserfromhell.parse(str(value))
return parse(str(value))
elif value is None: elif value is None:
return wikicode(SmartList())
return Wikicode(SmartList())
try: try:
nodelist = SmartList() nodelist = SmartList()
for item in value: for item in value:
@@ -64,4 +65,4 @@ def parse_anything(value):
except TypeError: except TypeError:
error = "Needs string, Node, Wikicode, int, None, or iterable of these, but got {0}: {1}" error = "Needs string, Node, Wikicode, int, None, or iterable of these, but got {0}: {1}"
raise ValueError(error.format(type(value).__name__, value)) raise ValueError(error.format(type(value).__name__, value))
return wikicode(nodelist)
return Wikicode(nodelist)

+ 1
- 0
mwparserfromhell/wikicode.py View File

@@ -143,6 +143,7 @@ class Wikicode(StringMixIn):
the starting indentation. the starting indentation.
""" """
def write(*args): def write(*args):
"""Write a new line following the proper indentation rules."""
if lines and lines[-1] is marker: # Continue from the last line if lines and lines[-1] is marker: # Continue from the last line
lines.pop() # Remove the marker lines.pop() # Remove the marker
last = lines.pop() last = lines.pop()


Loading…
Cancel
Save