Sfoglia il codice sorgente

Handle integers as MediaWiki does.

tags/v0.1
Ben Kurtovic 12 anni fa
parent
commit
6fefc28cba
2 ha cambiato i file con 8 aggiunte e 7 eliminazioni
  1. +2
    -4
      mwparserfromhell/nodes/template.py
  2. +6
    -3
      mwparserfromhell/parser/builder.py

+ 2
- 4
mwparserfromhell/nodes/template.py Vedi File

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

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


Caricamento…
Annulla
Salva