Explorar el Código

Handle integers as MediaWiki does.

tags/v0.1
Ben Kurtovic hace 12 años
padre
commit
6fefc28cba
Se han modificado 2 ficheros con 8 adiciones y 7 borrados
  1. +2
    -4
      mwparserfromhell/nodes/template.py
  2. +6
    -3
      mwparserfromhell/parser/builder.py

+ 2
- 4
mwparserfromhell/nodes/template.py Ver fichero

@@ -76,7 +76,7 @@ class Template(Node):
code.replace(node, node.replace(char, replacement))

def _blank_param_value(self, value):
match = re.search("^(\s*).*?(\s*)$", unicode(value), FLAGS)
match = re.search(r"^(\s*).*?(\s*)$", unicode(value), FLAGS)
value.nodes = [Text(match.group(1)), Text(match.group(2))]

def _select_theory(self, theories):
@@ -149,10 +149,8 @@ class Template(Node):
else:
int_keys = set()
for param in self.params:
try:
if re.match(r"[1-9][0-9]*$", param.name.strip()):
int_keys.add(int(unicode(param.name)))
except ValueError:
pass
expected = min(set(range(1, len(int_keys) + 2)) - int_keys)
if expected == int_name:
showkey = False


+ 6
- 3
mwparserfromhell/parser/builder.py Ver fichero

@@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import re

from . import tokens
from ..nodes import Heading, HTMLEntity, Tag, Template, Text
from ..nodes.extras import Attribute, Parameter
@@ -76,11 +78,12 @@ class Builder(object):
name = self._pop()
default = self._wrap(unicode(min(int_key_range - int_keys)))
param = self._handle_parameter(default)
try:
if re.match(r"[1-9][0-9]*$", param.name.strip()):
# We try a more restrictive test for integers than
# try: int(), because "01" as a key will pass through int()
# correctly but is not a valid integer key in wikicode:
int_keys.add(int(unicode(param.name)))
int_key_range.add(len(int_keys) + 1)
except ValueError:
pass
params.append(param)
elif isinstance(token, tokens.TemplateClose):
if not params:


Cargando…
Cancelar
Guardar