Browse Source

Compat for the parser itself.

tags/v0.1
Ben Kurtovic 12 years ago
parent
commit
391a5bd373
3 changed files with 9 additions and 14 deletions
  1. +1
    -1
      mwparserfromhell/parser/builder.py
  2. +2
    -2
      mwparserfromhell/parser/tokenizer.py
  3. +6
    -11
      mwparserfromhell/parser/tokens.py

+ 1
- 1
mwparserfromhell/parser/builder.py View File

@@ -23,11 +23,11 @@
from __future__ import unicode_literals from __future__ import unicode_literals


from . import tokens from . import tokens
from ..compat import str
from ..nodes import Heading, HTMLEntity, Tag, Template, Text from ..nodes import Heading, HTMLEntity, Tag, Template, Text
from ..nodes.extras import Attribute, Parameter from ..nodes.extras import Attribute, Parameter
from ..smart_list import SmartList from ..smart_list import SmartList
from ..wikicode import Wikicode from ..wikicode import Wikicode
from ..compat import str, bytes


__all__ = ["Builder"] __all__ = ["Builder"]




+ 2
- 2
mwparserfromhell/parser/tokenizer.py View File

@@ -27,7 +27,7 @@ import string


from . import contexts from . import contexts
from . import tokens from . import tokens
from ..compat import htmlentitydefs
from ..compat import htmlentities


__all__ = ["Tokenizer"] __all__ = ["Tokenizer"]


@@ -230,7 +230,7 @@ class Tokenizer(object):
if test < 1 or test > 0x10FFFF: if test < 1 or test > 0x10FFFF:
self._fail_route() self._fail_route()
else: else:
if this not in htmlentitydefs.entitydefs:
if this not in htmlentities.entitydefs:
self._fail_route() self._fail_route()


self._write(tokens.Text(text=this)) self._write(tokens.Text(text=this))


+ 6
- 11
mwparserfromhell/parser/tokens.py View File

@@ -21,7 +21,8 @@
# SOFTWARE. # SOFTWARE.


from __future__ import unicode_literals from __future__ import unicode_literals
from ..compat import str, bytes, v

from ..compat import basestring, str


__all__ = ["Token"] __all__ = ["Token"]


@@ -31,7 +32,7 @@ class Token(object):


def __repr__(self): def __repr__(self):
args = [] args = []
for key, value in self._kwargs.iteritems():
for key, value in self._kwargs.items():
if isinstance(value, basestring) and len(value) > 100: if isinstance(value, basestring) and len(value) > 100:
args.append(key + "=" + repr(value[:97] + "...")) args.append(key + "=" + repr(value[:97] + "..."))
else: else:
@@ -52,15 +53,9 @@ class Token(object):
def __delattr__(self, key): def __delattr__(self, key):
del self._kwargs[key] del self._kwargs[key]


if v >= 3:
def make(name):
__all__.append(name)
return type(name, (Token,), {})
else:
def make(name):
name = name.encode("utf-8")
__all__.append(name)
return type(name, (Token,), {})
def make(name):
__all__.append(name)
return type(name, (Token,), {})


Text = make("Text") Text = make("Text")




Loading…
Cancel
Save