From 90b18e3abca20ded549fa20aa54d5d55558b22da Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 21 Aug 2012 00:24:23 -0400 Subject: [PATCH] Finish updating all to compat except for the parser. --- mwparserfromhell/__init__.py | 2 ++ mwparserfromhell/nodes/__init__.py | 5 ++++- mwparserfromhell/nodes/extras/attribute.py | 2 +- mwparserfromhell/nodes/extras/parameter.py | 2 +- mwparserfromhell/nodes/heading.py | 5 ++++- mwparserfromhell/nodes/html_entity.py | 4 ++-- mwparserfromhell/nodes/tag.py | 19 +++++++++---------- mwparserfromhell/nodes/template.py | 5 +++-- mwparserfromhell/nodes/text.py | 2 +- mwparserfromhell/smart_list.py | 2 ++ mwparserfromhell/wikicode.py | 5 ++--- 11 files changed, 31 insertions(+), 22 deletions(-) diff --git a/mwparserfromhell/__init__.py b/mwparserfromhell/__init__.py index a765131..27d0931 100644 --- a/mwparserfromhell/__init__.py +++ b/mwparserfromhell/__init__.py @@ -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 `_ (the MediaWiki Parser from Hell) is a Python package that provides an easy-to-use and diff --git a/mwparserfromhell/nodes/__init__.py b/mwparserfromhell/nodes/__init__.py index 99bdc58..9cbb47c 100644 --- a/mwparserfromhell/nodes/__init__.py +++ b/mwparserfromhell/nodes/__init__.py @@ -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 diff --git a/mwparserfromhell/nodes/extras/attribute.py b/mwparserfromhell/nodes/extras/attribute.py index a9bd739..92a7dff 100644 --- a/mwparserfromhell/nodes/extras/attribute.py +++ b/mwparserfromhell/nodes/extras/attribute.py @@ -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"] diff --git a/mwparserfromhell/nodes/extras/parameter.py b/mwparserfromhell/nodes/extras/parameter.py index 43fb067..7038783 100644 --- a/mwparserfromhell/nodes/extras/parameter.py +++ b/mwparserfromhell/nodes/extras/parameter.py @@ -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"] diff --git a/mwparserfromhell/nodes/heading.py b/mwparserfromhell/nodes/heading.py index 7ac8065..dc98c41 100644 --- a/mwparserfromhell/nodes/heading.py +++ b/mwparserfromhell/nodes/heading.py @@ -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 diff --git a/mwparserfromhell/nodes/html_entity.py b/mwparserfromhell/nodes/html_entity.py index f0df4b3..ce66259 100644 --- a/mwparserfromhell/nodes/html_entity.py +++ b/mwparserfromhell/nodes/html_entity.py @@ -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)) diff --git a/mwparserfromhell/nodes/tag.py b/mwparserfromhell/nodes/tag.py index 90cfb58..d8e4353 100644 --- a/mwparserfromhell/nodes/tag.py +++ b/mwparserfromhell/nodes/tag.py @@ -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 += "" + result += " " * self.open_padding + ">" + str(self.contents) + result += "" 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("") + write("") else: write(" 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) diff --git a/mwparserfromhell/nodes/text.py b/mwparserfromhell/nodes/text.py index ce5b513..0213c74 100644 --- a/mwparserfromhell/nodes/text.py +++ b/mwparserfromhell/nodes/text.py @@ -23,7 +23,7 @@ from __future__ import unicode_literals from . import Node -from ..compat import str, bytes, basestring +from ..compat import str __all__ = ["Text"] diff --git a/mwparserfromhell/smart_list.py b/mwparserfromhell/smart_list.py index d510fa0..ab069ee 100644 --- a/mwparserfromhell/smart_list.py +++ b/mwparserfromhell/smart_list.py @@ -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"] diff --git a/mwparserfromhell/wikicode.py b/mwparserfromhell/wikicode.py index c613c40..0154775 100644 --- a/mwparserfromhell/wikicode.py +++ b/mwparserfromhell/wikicode.py @@ -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: