
    V=^4                     "   d dl mZmZmZ d dlmZ ddlmZmZm	Z	 g dZ
ej                  Zej                  Zej                  Zej"                  Zej&                  Zej*                  ZdZdj1                  e	      Z	 G d d	e      Z G d
 de      Zy)    )absolute_importdivisionunicode_literals)Node   )
namespacesvoidElementsspaceCharacters)	DOCUMENTDOCTYPETEXTELEMENTCOMMENTENTITYUNKNOWN
TreeWalkerNonRecursiveTreeWalkerz<#UNKNOWN#> c                   V    e Zd ZdZd Zd Zd ZddZd Zd Z	d Z
d	 ZddZd Zd Zy
)r   z}Walks a tree yielding tokens

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

    c                     || _         y)zCCreates a TreeWalker

        :arg tree: the tree to walk

        N)tree)selfr   s     ;/usr/lib/python3/dist-packages/html5lib/treewalkers/base.py__init__zTreeWalker.__init__   s     	    c                     t         NNotImplementedError)r   s    r   __iter__zTreeWalker.__iter__#       !!r   c                     d|dS )zGenerates an error token with the given message

        :arg msg: the error message

        :returns: SerializeError token

        SerializeErrortypedata )r   msgs     r   errorzTreeWalker.error&   s     )#66r   c              #   J   K   d|||d |r| j                  d       yyw)ar  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

        EmptyTagr%   name	namespacer&   zVoid element has childrenNr)   )r   r.   r-   attrshasChildrens        r   emptyTagzTreeWalker.emptyTag0   s7      "4% 	 **899 s   !#c                     d|||dS )zGenerates 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

        StartTagr,   r'   )r   r.   r-   r0   s       r   startTagzTreeWalker.startTagE   s     #& 	r   c                     d||dS )zGenerates an EndTag token

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

        :arg name: the name of the element

        :returns: EndTag token

        EndTag)r%   r-   r.   r'   )r   r.   r-   s      r   endTagzTreeWalker.endTagV   s     !&( 	(r   c              #      K   |}|j                  t              }|dt        |      t        |      z
   }|rd|d |}|j                  t              }|t        |      d }|rd|d |rd|d yyw)at  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

        NSpaceCharactersr$   
Characters)lstripr
   lenrstrip)r   r&   middleleftrights        r   textzTreeWalker.textd   s     2 _-,SYV,-,d;;_-S[\"'88,e<< s   A4A6c                     d|dS )zdGenerates a Comment token

        :arg data: the comment

        :returns: Comment token

        Commentr$   r'   )r   r&   s     r   commentzTreeWalker.comment   s     "400r   Nc                     d|||dS )zGenerates a Doctype token

        :arg name:

        :arg publicId:

        :arg systemId:

        :returns: the Doctype token

        Doctype)r%   r-   publicIdsystemIdr'   )r   r-   rH   rI   s       r   doctypezTreeWalker.doctype   s     "$$& 	&r   c                     d|dS )zjGenerates an Entity token

        :arg name: the entity name

        :returns: an Entity token

        Entity)r%   r-   r'   )r   r-   s     r   entityzTreeWalker.entity   s     !$//r   c                 *    | j                  d|z         S )zHandles unknown node typeszUnknown node type: r/   )r   nodeTypes     r   unknownzTreeWalker.unknown   s    zz/(:;;r   )F)NN)__name__
__module____qualname____doc__r   r    r)   r2   r5   r8   rB   rE   rJ   rM   rP   r'   r   r   r   r      s?    "7:*"($=L1&"0<r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)r   c                     t         r   r   r   nodes     r   getNodeDetailsz%NonRecursiveTreeWalker.getNodeDetails   r!   r   c                     t         r   r   rW   s     r   getFirstChildz$NonRecursiveTreeWalker.getFirstChild   r!   r   c                     t         r   r   rW   s     r   getNextSiblingz%NonRecursiveTreeWalker.getNextSibling   r!   r   c                     t         r   r   rW   s     r   getParentNodez$NonRecursiveTreeWalker.getParentNode   r!   r   c              #     K   | j                   }|| j                  |      }|d   |dd  }}d}|t        k(  r | j                  |  n|t        k(  r | j
                  | D ]  }|  n|t        k(  rS|\  }}}}|r|t        d   k(  r(|t        v r | j                  ||||      D ]  }|  d}nx| j                  |||       nb|t        k(  r| j                  |d          nB|t        k(  r| j                  |d          n"|t        k(  rd}n| j!                  |d          |r| j#                  |      }	nd }	|	|	}n|| j                  |      }|d   |dd  }}|t        k(  r1|\  }}}}|r|t        d   k7  s|t        vr| j%                  ||       | j                   |u rd }n*| j'                  |      }
|
|
}n| j)                  |      }||y y w)Nr      FhtmlT)r   rY   r   rJ   r   rB   r   r   r	   r2   r5   r   rE   r   rM   r   rP   r[   r8   r]   r_   )r   currentNodedetailsr%   r1   tokenr.   r-   
attributes
firstChildnextSiblings              r   r    zNonRecursiveTreeWalker.__iter__   s    ii%))+6G#AJ'DKw"dllG,,&TYY0  EK  ;B8	4[!Y*V2D%D$R^J^!%y$
/:"< $#$ #(K--	4DDll71:..kk'!*--!" ll71:..!//<
!
%(!-"11+>G$+AJ'DwCJ@	4[%)z&7I*IdZfNf"&++i">>yyK/&*"&"5"5k"BK".&1&*&8&8&E "-U %s   GGGGN)rQ   rR   rS   rY   r[   r]   r_   r    r'   r   r   r   r      s    """";Fr   r   N)
__future__r   r   r   xml.domr   	constantsr   r	   r
   __all__DOCUMENT_NODEr   DOCUMENT_TYPE_NODEr   	TEXT_NODEr   ELEMENT_NODEr   COMMENT_NODEr   ENTITY_NODEr   r   joinobjectr   r   r'   r   r   <module>ru      s    B B  A A3 

!
!~~





			
''/*]< ]<@HFZ HFr   