Skip to content

Commit

Permalink
Rename treewalkers._base to .base to reflect public status
Browse files Browse the repository at this point in the history
  • Loading branch information
gsnedders committed Jul 13, 2016
1 parent 7bb34c7 commit 19891c5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion html5lib/tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from html5lib import constants
from html5lib.filters.lint import Filter as Lint
from html5lib.serializer import HTMLSerializer, serialize
from html5lib.treewalkers._base import TreeWalker
from html5lib.treewalkers.base import TreeWalker

# pylint:disable=wrong-import-position
optionals_loaded = []
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions html5lib/treewalkers/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

from xml.dom import Node

from . import _base
from . import base


class TreeWalker(_base.NonRecursiveTreeWalker):
class TreeWalker(base.NonRecursiveTreeWalker):
def getNodeDetails(self, node):
if node.nodeType == Node.DOCUMENT_TYPE_NODE:
return _base.DOCTYPE, node.name, node.publicId, node.systemId
return base.DOCTYPE, node.name, node.publicId, node.systemId

elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
return _base.TEXT, node.nodeValue
return base.TEXT, node.nodeValue

elif node.nodeType == Node.ELEMENT_NODE:
attrs = {}
Expand All @@ -21,17 +21,17 @@ def getNodeDetails(self, node):
attrs[(attr.namespaceURI, attr.localName)] = attr.value
else:
attrs[(None, attr.name)] = attr.value
return (_base.ELEMENT, node.namespaceURI, node.nodeName,
return (base.ELEMENT, node.namespaceURI, node.nodeName,
attrs, node.hasChildNodes())

elif node.nodeType == Node.COMMENT_NODE:
return _base.COMMENT, node.nodeValue
return base.COMMENT, node.nodeValue

elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
return (_base.DOCUMENT,)
return (base.DOCUMENT,)

else:
return _base.UNKNOWN, node.nodeType
return base.UNKNOWN, node.nodeType

def getFirstChild(self, node):
return node.firstChild
Expand Down
14 changes: 7 additions & 7 deletions html5lib/treewalkers/etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from six import string_types

from . import _base
from . import base
from ..utils import moduleFactoryFactory

tag_regexp = re.compile("{([^}]*)}(.*)")
Expand All @@ -22,7 +22,7 @@ def getETreeBuilder(ElementTreeImplementation):
ElementTree = ElementTreeImplementation
ElementTreeCommentType = ElementTree.Comment("asd").tag

class TreeWalker(_base.NonRecursiveTreeWalker): # pylint:disable=unused-variable
class TreeWalker(base.NonRecursiveTreeWalker): # pylint:disable=unused-variable
"""Given the particular ElementTree representation, this implementation,
to avoid using recursion, returns "nodes" as tuples with the following
content:
Expand All @@ -40,22 +40,22 @@ def getNodeDetails(self, node):
if isinstance(node, tuple): # It might be the root Element
elt, _, _, flag = node
if flag in ("text", "tail"):
return _base.TEXT, getattr(elt, flag)
return base.TEXT, getattr(elt, flag)
else:
node = elt

if not(hasattr(node, "tag")):
node = node.getroot()

if node.tag in ("DOCUMENT_ROOT", "DOCUMENT_FRAGMENT"):
return (_base.DOCUMENT,)
return (base.DOCUMENT,)

elif node.tag == "<!DOCTYPE>":
return (_base.DOCTYPE, node.text,
return (base.DOCTYPE, node.text,
node.get("publicId"), node.get("systemId"))

elif node.tag == ElementTreeCommentType:
return _base.COMMENT, node.text
return base.COMMENT, node.text

else:
assert isinstance(node.tag, string_types), type(node.tag)
Expand All @@ -73,7 +73,7 @@ def getNodeDetails(self, node):
attrs[(match.group(1), match.group(2))] = value
else:
attrs[(None, name)] = value
return (_base.ELEMENT, namespace, tag,
return (base.ELEMENT, namespace, tag,
attrs, len(node) or node.text)

def getFirstChild(self, node):
Expand Down
4 changes: 2 additions & 2 deletions html5lib/treewalkers/genshistream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from genshi.core import START, END, XML_NAMESPACE, DOCTYPE, TEXT
from genshi.core import START_NS, END_NS, START_CDATA, END_CDATA, PI, COMMENT

from . import _base
from . import base

from ..constants import voidElements, namespaces


class TreeWalker(_base.TreeWalker):
class TreeWalker(base.TreeWalker):
def __iter__(self):
# Buffer the events so we can pass in the following one
previous = None
Expand Down
20 changes: 10 additions & 10 deletions html5lib/treewalkers/lxmletree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from lxml import etree
from ..treebuilders.etree import tag_regexp

from . import _base
from . import base

from .. import ihatexml

Expand Down Expand Up @@ -122,7 +122,7 @@ def __len__(self):
return len(self.obj)


class TreeWalker(_base.NonRecursiveTreeWalker):
class TreeWalker(base.NonRecursiveTreeWalker):
def __init__(self, tree):
# pylint:disable=redefined-variable-type
if isinstance(tree, list):
Expand All @@ -131,29 +131,29 @@ def __init__(self, tree):
else:
self.fragmentChildren = set()
tree = Root(tree)
_base.NonRecursiveTreeWalker.__init__(self, tree)
base.NonRecursiveTreeWalker.__init__(self, tree)
self.filter = ihatexml.InfosetFilter()

def getNodeDetails(self, node):
if isinstance(node, tuple): # Text node
node, key = node
assert key in ("text", "tail"), "Text nodes are text or tail, found %s" % key
return _base.TEXT, ensure_str(getattr(node, key))
return base.TEXT, ensure_str(getattr(node, key))

elif isinstance(node, Root):
return (_base.DOCUMENT,)
return (base.DOCUMENT,)

elif isinstance(node, Doctype):
return _base.DOCTYPE, node.name, node.public_id, node.system_id
return base.DOCTYPE, node.name, node.public_id, node.system_id

elif isinstance(node, FragmentWrapper) and not hasattr(node, "tag"):
return _base.TEXT, ensure_str(node.obj)
return base.TEXT, ensure_str(node.obj)

elif node.tag == etree.Comment:
return _base.COMMENT, ensure_str(node.text)
return base.COMMENT, ensure_str(node.text)

elif node.tag == etree.Entity:
return _base.ENTITY, ensure_str(node.text)[1:-1] # strip &;
return base.ENTITY, ensure_str(node.text)[1:-1] # strip &;

else:
# This is assumed to be an ordinary element
Expand All @@ -172,7 +172,7 @@ def getNodeDetails(self, node):
attrs[(match.group(1), match.group(2))] = value
else:
attrs[(None, name)] = value
return (_base.ELEMENT, namespace, self.filter.fromXmlName(tag),
return (base.ELEMENT, namespace, self.filter.fromXmlName(tag),
attrs, len(node) > 0 or node.text)

def getFirstChild(self, node):
Expand Down

0 comments on commit 19891c5

Please sign in to comment.