Browse Source

Finish updating all to compat except for the parser.

tags/v0.1
Ben Kurtovic 11 years ago
parent
commit
90b18e3abc
11 changed files with 31 additions and 22 deletions
  1. +2
    -0
      mwparserfromhell/__init__.py
  2. +4
    -1
      mwparserfromhell/nodes/__init__.py
  3. +1
    -1
      mwparserfromhell/nodes/extras/attribute.py
  4. +1
    -1
      mwparserfromhell/nodes/extras/parameter.py
  5. +4
    -1
      mwparserfromhell/nodes/heading.py
  6. +2
    -2
      mwparserfromhell/nodes/html_entity.py
  7. +9
    -10
      mwparserfromhell/nodes/tag.py
  8. +3
    -2
      mwparserfromhell/nodes/template.py
  9. +1
    -1
      mwparserfromhell/nodes/text.py
  10. +2
    -0
      mwparserfromhell/smart_list.py
  11. +2
    -3
      mwparserfromhell/wikicode.py

+ 2
- 0
mwparserfromhell/__init__.py View File

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

from __future__ import unicode_literals

"""
`mwparserfromhell <https://github.com/earwig/mwparserfromhell>`_ (the MediaWiki
Parser from Hell) is a Python package that provides an easy-to-use and


+ 4
- 1
mwparserfromhell/nodes/__init__.py View File

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

from __future__ import unicode_literals

from ..compat import str
from ..string_mixin import StringMixIn

__all__ = ["Node", "Text", "Heading", "HTMLEntity", "Tag", "Template"]
@@ -35,7 +38,7 @@ class Node(StringMixIn):
return None

def __showtree__(self, write, get, mark):
write(unicode(self))
write(str(self))


from . import extras


+ 1
- 1
mwparserfromhell/nodes/extras/attribute.py View File

@@ -22,8 +22,8 @@

from __future__ import unicode_literals

from ...compat import str
from ...string_mixin import StringMixIn
from ...compat import str, bytes

__all__ = ["Attribute"]



+ 1
- 1
mwparserfromhell/nodes/extras/parameter.py View File

@@ -22,9 +22,9 @@

from __future__ import unicode_literals

from ...compat import str
from ...string_mixin import StringMixIn
from ...utils import parse_anything
from ...compat import str, bytes

__all__ = ["Parameter"]



+ 4
- 1
mwparserfromhell/nodes/heading.py View File

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

from __future__ import unicode_literals

from . import Node
from ..compat import str

__all__ = ["Heading"]

@@ -31,7 +34,7 @@ class Heading(Node):
self._level = level

def __unicode__(self):
return ("=" * self.level) + unicode(self.title) + ("=" * self.level)
return ("=" * self.level) + str(self.title) + ("=" * self.level)

def __iternodes__(self, getter):
yield None, self


+ 2
- 2
mwparserfromhell/nodes/html_entity.py View File

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

from . import Node
from ..compat import str, bytes, htmlentitydefs
from ..compat import htmlentities

__all__ = ["HTMLEntity"]

@@ -102,7 +102,7 @@ class HTMLEntity(Node):

def normalize(self):
if self.named:
return unichr(htmlentitydefs.name2codepoint[self.value])
return unichr(htmlentities.name2codepoint[self.value])
if self.hexadecimal:
return self._unichr(int(self.value, 16))
return self._unichr(int(self.value))

+ 9
- 10
mwparserfromhell/nodes/tag.py View File

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

from . import Node, Text
from ..compat import str, bytes
from ..compat import str

__all__ = ["Tag"]

@@ -91,16 +91,16 @@ class Tag(Node):
if self.self_closing:
return open_
else:
return open_ + unicode(self.contents) + close
return open_ + str(self.contents) + close

result = "<" + unicode(self.tag)
result = "<" + str(self.tag)
if self.attrs:
result += " " + " ".join([unicode(attr) for attr in self.attrs])
result += " " + " ".join([str(attr) for attr in self.attrs])
if self.self_closing:
result += " " * self.open_padding + "/>"
else:
result += " " * self.open_padding + ">" + unicode(self.contents)
result += "</" + unicode(self.tag) + " " * self.close_padding + ">"
result += " " * self.open_padding + ">" + str(self.contents)
result += "</" + str(self.tag) + " " * self.close_padding + ">"
return result

def __iternodes__(self, getter):
@@ -124,9 +124,8 @@ class Tag(Node):

def __showtree__(self, write, get, mark):
tagnodes = self.tag.nodes
if (not self.attrs and len(tagnodes) == 1 and
isinstance(tagnodes[0], Text)):
write("<" + unicode(tagnodes[0]) + ">")
if (not self.attrs and len(tagnodes) == 1 and isinstance(tagnodes[0], Text)):
write("<" + str(tagnodes[0]) + ">")
else:
write("<")
get(self.tag)
@@ -140,7 +139,7 @@ class Tag(Node):
write(">")
get(self.contents)
if len(tagnodes) == 1 and isinstance(tagnodes[0], Text):
write("</" + unicode(tagnodes[0]) + ">")
write("</" + str(tagnodes[0]) + ">")
else:
write("</")
get(self.tag)


+ 3
- 2
mwparserfromhell/nodes/template.py View File

@@ -26,8 +26,8 @@ import re

from . import HTMLEntity, Node, Text
from .extras import Parameter
from ..compat import basestring, str
from ..utils import parse_anything
from ..compat import str, bytes, basestring

__all__ = ["Template"]

@@ -87,7 +87,8 @@ class Template(Node):
best = max(theories.values())
confidence = float(best) / sum(theories.values())
if confidence > 0.75:
return tuple(theories.keys())[tuple(theories.values()).index(best)]
keys = tuple(theories.keys())
return keys[tuple(theories.values()).index(best)]

def _get_spacing_conventions(self):
before_theories = defaultdict(lambda: 0)


+ 1
- 1
mwparserfromhell/nodes/text.py View File

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

from . import Node
from ..compat import str, bytes, basestring
from ..compat import str

__all__ = ["Text"]



+ 2
- 0
mwparserfromhell/smart_list.py View File

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

from __future__ import unicode_literals

from .compat import maxsize, py3k

__all__ = ["SmartList"]


+ 2
- 3
mwparserfromhell/wikicode.py View File

@@ -22,12 +22,11 @@

from __future__ import unicode_literals
import re
import sys

from .compat import maxsize, str
from .nodes import Heading, Node, Tag, Template, Text
from .string_mixin import StringMixIn
from .utils import parse_anything
from .compat import str, bytes

__all__ = ["Wikicode"]

@@ -230,7 +229,7 @@ class Wikicode(StringMixIn):
headings = [head for head in headings if head.level in levels]

sections = []
buffers = [[sys.maxint, 0]]
buffers = [[maxsize, 0]]
i = 0
while i < len(self.nodes):
if self.nodes[i] in headings:


Loading…
Cancel
Save