OpenQuizz
Une application de gestion des contenus pédagogiques
TreeWalker Class Reference
Inheritance diagram for TreeWalker:
Collaboration diagram for TreeWalker:

Public Member Functions

def __init__ (self, tree)
 
def __iter__ (self)
 
def error (self, msg)
 
def emptyTag (self, namespace, name, attrs, hasChildren=False)
 
def startTag (self, namespace, name, attrs)
 
def endTag (self, namespace, name)
 
def text (self, data)
 
def comment (self, data)
 
def doctype (self, name, publicId=None, systemId=None)
 
def entity (self, name)
 
def unknown (self, nodeType)
 

Data Fields

 tree
 

Detailed Description

Walks a tree yielding tokens

Tokens are dicts that all have a ``type`` field specifying the type of the
token.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  tree 
)
Creates a TreeWalker

:arg tree: the tree to walk

Reimplemented in TreeWalker.

Member Function Documentation

◆ __iter__()

def __iter__ (   self)

Reimplemented in NonRecursiveTreeWalker, and TreeWalker.

◆ comment()

def comment (   self,
  data 
)
Generates a Comment token

:arg data: the comment

:returns: Comment token

◆ doctype()

def doctype (   self,
  name,
  publicId = None,
  systemId = None 
)
Generates a Doctype token

:arg name:

:arg publicId:

:arg systemId:

:returns: the Doctype token

◆ emptyTag()

def emptyTag (   self,
  namespace,
  name,
  attrs,
  hasChildren = False 
)
Generates an EmptyTag token

:arg namespace: the namespace of the token--can be ``None``

:arg name: the name of the element

:arg attrs: the attributes of the element as a dict

:arg hasChildren: whether or not to yield a SerializationError because
    this tag shouldn't have children

:returns: EmptyTag token

◆ endTag()

def endTag (   self,
  namespace,
  name 
)
Generates an EndTag token

:arg namespace: the namespace of the token--can be ``None``

:arg name: the name of the element

:returns: EndTag token

◆ entity()

def entity (   self,
  name 
)
Generates an Entity token

:arg name: the entity name

:returns: an Entity token

◆ error()

def error (   self,
  msg 
)
Generates an error token with the given message

:arg msg: the error message

:returns: SerializeError token

◆ startTag()

def startTag (   self,
  namespace,
  name,
  attrs 
)
Generates a StartTag token

:arg namespace: the namespace of the token--can be ``None``

:arg name: the name of the element

:arg attrs: the attributes of the element as a dict

:returns: StartTag token

◆ text()

def text (   self,
  data 
)
Generates SpaceCharacters and Characters tokens

Depending on what's in the data, this generates one or more
``SpaceCharacters`` and ``Characters`` tokens.

For example:

    >>> from html5lib.treewalkers.base import TreeWalker
    >>> # Give it an empty tree just so it instantiates
    >>> walker = TreeWalker([])
    >>> list(walker.text(''))
    []
    >>> list(walker.text('  '))
    [{u'data': '  ', u'type': u'SpaceCharacters'}]
    >>> list(walker.text(' abc '))  # doctest: +NORMALIZE_WHITESPACE
    [{u'data': ' ', u'type': u'SpaceCharacters'},
    {u'data': u'abc', u'type': u'Characters'},
    {u'data': u' ', u'type': u'SpaceCharacters'}]

:arg data: the text data

:returns: one or more ``SpaceCharacters`` and ``Characters`` tokens

◆ unknown()

def unknown (   self,
  nodeType 
)
Handles unknown node types

Field Documentation

◆ tree

tree

The documentation for this class was generated from the following file: