Explorar el Código

Final fixes and cleanup before release.

tags/v0.1
Ben Kurtovic hace 12 años
padre
commit
1905456b4d
Se han modificado 4 ficheros con 16 adiciones y 10 borrados
  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 Ver fichero

@@ -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_


+ 4
- 0
mwparserfromhell/smart_list.py Ver fichero

@@ -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


+ 10
- 9
mwparserfromhell/utils.py Ver fichero

@@ -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)

+ 1
- 0
mwparserfromhell/wikicode.py Ver fichero

@@ -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()


Cargando…
Cancelar
Guardar