ruạṛ
3 AL�iW? � @ sX d Z ddlZejd�jZejd�jZejd�Zejd�Zejd�Z[G dd � d e �Z dS ) a Shared support for scanning document type declarations in HTML and XHTML. Backported for python-future from Python 3.3. Reason: ParserBase is an old-style class in the Python 2.7 source of markupbase.py, which I suspect might be the cause of sporadic unit-test failures on travis-ci.org with test_htmlparser.py. The test failures look like this: ====================================================================== ERROR: test_attr_entity_replacement (future.tests.test_htmlparser.AttributesStrictTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 661, in test_attr_entity_replacement [("starttag", "a", [("b", "&><"'")])]) File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 93, in _run_check collector = self.get_collector() File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 617, in get_collector return EventCollector(strict=True) File "/home/travis/build/edschofield/python-future/future/tests/test_htmlparser.py", line 27, in __init__ html.parser.HTMLParser.__init__(self, *args, **kw) File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 135, in __init__ self.reset() File "/home/travis/build/edschofield/python-future/future/backports/html/parser.py", line 143, in reset _markupbase.ParserBase.reset(self) TypeError: unbound method reset() must be called with ParserBase instance as first argument (got EventCollector instance instead) This module is used as a foundation for the html.parser module. It has no documented public API and should not be used directly. � Nz[a-zA-Z][-_.a-zA-Z0-9]*\s*z(\'[^\']*\'|"[^"]*")\s*z--\s*>z ]\s*]\s*>z]\s*>c @ s� e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� ZdZ d d� Z d#dd�Zd$dd�Zdd� Z dd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"S )%� ParserBaseziParser base class which provides some common support methods used by the SGML/HTML and XHTML parsers.c C s | j tkrtd��d S )Nz)_markupbase.ParserBase must be subclassed)� __class__r �RuntimeError)�self� r �C/root/tmp/pip-build-3x0y2zol/future/future/backports/_markupbase.py�__init__6 s zParserBase.__init__c C s t d��d S )Nz.subclasses of ParserBase must override error())�NotImplementedError)r �messager r r �error; s zParserBase.errorc C s d| _ d| _d S )N� r )�lineno�offset)r r r r �reset? s zParserBase.resetc C s | j | jfS )z&Return current line number and offset.)r r )r r r r �getposC s zParserBase.getposc C sb ||kr|S | j }|jd||�}|rN| j| | _|jd||�}||d | _n| j| | | _|S )N� r )�rawdata�countr �rindexr )r �i�jr �nlines�posr r r � updateposK s zParserBase.updatepos� c C s� | j }|d }|||� dks&td��|||d � dkrB|d S |||d � dkrZdS t|�}|||d � dkr�| j|�S || d kr�| j|�S | j||�\}}|d k r�|S |dkr�d| _�x(||k �r�|| }|dk�r||d |� }|dk�r| j|� n | j|� |d S |dk�r@t ||�}|�s6dS |j � }n�|d k�r\| j||�\} }n�|| jk�rr|d }nj|d k�r�|dk�r�| j|d |�}n0|tddddg�k�r�| j d| � n | j d� n| j d|| � |d k r�|S q�W dS )N� z<!z$unexpected call to parse_declarationr �>�-r z--�[r �doctypez"'�4abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ�attlist�linktype�link�elementz&unsupported '[' char in %s declarationz"unexpected '[' char in declarationz!unexpected %r char in declaration)r r ���r% r% )r �AssertionError�len� parse_comment�parse_marked_section� _scan_name�_decl_otherchars�handle_decl�unknown_decl�_declstringlit_match�end�_parse_doctype_subset�setr ) r r r r �n�decltype�c�data�m�namer r r �parse_declaration[ sZ zParserBase.parse_declarationr c C s� | j }|||d � dks"td��| j|d |�\}}|dk rB|S |tddddd g�krjtj||d �}n>|td ddg�kr�tj||d �}n| jd ||d |� � |s�dS |r�|jd�}| j ||d |� � |j d�S )N� z<![z)unexpected call to parse_marked_section()r �temp�cdata�ignore�include�rcdata�if�else�endifz+unknown status keyword %r in marked sectionr r% )r r&