o
    lqiE                     @   sd   d Z ddlZddlmZ zddlmZ W n ey!   ddlZY nw eje dZ	G dd dZ
dS )z
tests for encutils.py
    N)StringIO)streamc                   @   sL   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dS )TestAutoEncodingc                    s   G  fddd}| S )zbuild a fake HTTP responsec                       s(   e Zd Zdd Zdd Z fddZdS )z*TestAutoEncoding._fakeRes.<locals>.FakeResc                 S   sB   t j | _|d}t|dkr|d  }| j| d S d S )N:   )httpclientHTTPMessage_infosplitlenstripset_type)selfcontentitemst r   c/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/cssutils/tests/test_encutils.py__init__   s   
z3TestAutoEncoding._fakeRes.<locals>.FakeRes.__init__c                 S   s   | j S N)r   r   r   r   r   info    s   z/TestAutoEncoding._fakeRes.<locals>.FakeRes.infoc                    s    S r   r   r   r   r   r   read#   s   z/TestAutoEncoding._fakeRes.<locals>.FakeRes.readN)__name__
__module____qualname__r   r   r   r   r   r   r   FakeRes   s    
r   r   )r   r   r   r   r   r   _fakeRes   s   zTestAutoEncoding._fakeResc                 C   sf   t jt jt jt jt jt jt jt jt jt jt jt jd}t| D ]\}}|t j	|t
dks0J q!dS )z encutils._getTextTypeByMediaType)application/xmlapplication/xml-dtd&application/xml-external-parsed-entityzapplication/xhtml+xmltext/xmltext/xml-external-parsed-entityztext/xhtml+xml	text/htmltext/css
text/plainx/xANYTHINGlogN)encutils_XML_APPLICATION_TYPEZ_XML_TEXT_TYPEZ_HTML_TEXT_TYPEZ
_TEXT_UTF8Z
_TEXT_TYPE_OTHER_TYPElistr   Z_getTextTypeByMediaTyper,   r   teststestexpr   r   r   test_getTextTypeByMediaType(   s    z,TestAutoEncoding.test_getTextTypeByMediaTypec                 C   sj   t jt jt jt jt jt jt jt jt jt jt jt jt jd}t| D ]\}}|t j|tdks2J q#dS )zencutils._getTextType)u     þÿ<?xml version="1.0"u   ÿþ  <?xml version="1.0"u   þÿ<?xml version="1.0"u   ÿþ<?xml version="1.0"u   ï»¿<?xml version="1.0"z<?xml version="1.0"     þÿanything   ÿþ  anything   þÿanything   ÿþanything   ï»¿anythingr)   r*   r+   N)r-   r.   r/   r0   r   Z_getTextTyper,   r1   r   r   r   test_getTextType;   s"   z!TestAutoEncoding.test_getTextTypec                 C   sN   ddddddddddddd}t | D ]\}}|tj|tdks$J qdS )zencutils.encodingByMediaTypeutf-8ascii
iso-8859-1N)r!   r"   r#   zapplication/ANYTHING+xmlz  application/xml  r$   r%   ztext/ANYTHING+xmlr&   r'   r(   r*   r+   )r0   r   r-   ZencodingByMediaTyper,   r1   r   r   r   test_encodingByMediaTypeO   s    z)TestAutoEncoding.test_encodingByMediaTypec                 C   s   i ddddddddddd	dd
dddddddddddddddddddddddddd}t | D ]\}}|tj|tdksQJ qBdS )zencutils.getMetaInfozA<meta tp-equiv='Content-Type' content='text/html; charset=ascii'>)NNzB<meta http-equiv='ontent-Type' content='text/html; charset=ascii'>z4<meta http-equiv='Content-Type' content='text/html'>)r&   Nz4<meta content='text/html' http-equiv='Content-Type'>zB<meta content='text/html;charset=ascii' http-equiv='Content-Type'>)r&   r=   zC<meta http-equiv='Content-Type' content='text/html ;charset=ascii'>zG<meta content='text/html;charset=iso-8859-1' http-equiv='Content-Type'>)r&   r>   zD<meta http-equiv="Content-Type" content="text/html;charset = ascii">zF<meta http-equiv="Content-Type" content="text/html;charset=ascii;x=2">zF<meta http-equiv="Content-Type" content="text/html;x=2;charset=ascii">zJ<meta http-equiv="Content-Type" content="text/html;x=2;charset=ascii;y=2">zB<meta http-equiv='Content-Type' content="text/html;charset=ascii">zE<meta http-equiv='Content-Type' content='text/html;charset=ascii'  />zJ<meta http-equiv = " Content-Type" content = " text/html;charset=ascii " >zU<meta http-equiv = " 
 Content-Type " content = "  	 text/html   ;  charset=ascii " >zB<meta content="text/html;charset=ascii" http-equiv="Content-Type">zB<meta content="text/html;charset=ascii" http-equiv="cONTENT-type">)zraises exception: </ >zW<meta content="text/html;charset=ascii" http-equiv="cONTENT-type">
                </ >zW</ >
                <meta content="text/html;charset=ascii" http-equiv="cONTENT-type">z<meta content="text/html" http-equiv="cONTENT-type">
                </ >
                <meta content="text/html;charset=ascii" http-equiv="cONTENT-type">r+   N)r0   r   r-   ZgetMetaInfor,   r1   r   r   r   test_getMetaInfob   sV   	!%)-159=AEXz!TestAutoEncoding.test_getMetaInfoc                 C   s,   d}|D ]\}}|t j|tdksJ qdS )zencutils.detectXMLEncoding)
)	utf_32_ber6   )	utf_32_ler7   )	utf_16_ber8   )	utf_16_ler9   )r<   r:   )r=   z'<?xml version="1.0" encoding="ascii" ?>)r=   z'<?xml version='1.0' encoding='ascii' ?>)r>   z,<?xml version='1.0' encoding='iso-8859-1' ?>)r<   z<?xml version="1.0" ?>)r<   z*<?xml version="1.0"?><x encoding="ascii"/>r+   N)r-   ZdetectXMLEncodingr,   r   r2   r4   r3   r   r   r   test_detectXMLEncoding   s   z'TestAutoEncoding.test_detectXMLEncodingc              
   C   s~   zddd dfdg}W n ty*   ddd dfdd dfdd dfg}Y nw |D ]\}}|t| ks<J q-dS )zencutils.tryEncodings)r=   s   abczwindows-1252u   €)r=      1r>   u   äöüßN)encodeImportErrorr-   ZtryEncodingslowerrE   r   r   r   test_tryEncodings   s   z"TestAutoEncoding.test_tryEncodingsc                 C   s^   g d}|D ]&\}}|\}}|rt | ||}nt j|d}|j|jf}||ks,J qdS )zencutils.getEncodingInfo)#)r<   F)#Content-Type: application/xhtml+xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml"/>
                    </example>)rL   )NrN   )rL   )rM   z<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml;charset=iso_M"/>
                    </example>)iso-hT)1Content-Type: application/xhtml+xml;charset=iso-HrN   )rO   )rQ   F<?xml version="1.0" encoding="iso-X" ?>
                    <example/>)rP   F)rQ   z<?xml version="1.0" encoding="iso-h" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml;charset=iso_M"/>
                    </example>)ziso-xF)rM   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml;charset=iso_M"/>
                    </example>)rS   )z+Content-Type: application/xml;charset=iso-h1)rL   )Content-Type: application/xmlN)NF)rV   rU   )r=   F)Content-Type: text/xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml"/>
                    </example>)rX   )rY   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)rX   )rY   rU   )rX   )rY   N)rS   )$Content-Type: text/xml;charset=iso-HrZ   )rS   )r[   rR   )rS   )r[   z<?xml version="1.0"  encoding="iso-h" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)r>   F)Content-Type: text/html;z\<meta http-equiv="Content-Type"
                                        content="text/html">r\   )r]   N)rS   )%Content-Type: text/html;charset=iso-HzX<meta http-equiv="Content-Type"
                                    content="text/html">))ziso-mF)zContent-Type: text/htmlf<meta http-equiv="Content-Type"
                                    content="text/html;charset=iso-m">)rO   )r_   r`   )rW   )Nzb<meta http-equiv="Content-Type"
                                content="text/html;charset=iso-m">)rW   )NzT<meta http-equiv="Content-Type"
                                content="text/html">)rW   )Ntext)rW   )N )r\   )ZNoContentTypeZOnlyTextr^   )r\   )r]   rU   )rL   )Nz<?xml version=)rT   )Nz&<?xml version="1.0" encoding="iso-X"?>)rL   )Nz<?xml version="1.0" ?>
                                    <html><meta http-equiv="Content-Type"
                                    content="text/html;charset=iso-m"></html>)rL   )zContent-Type: text/css;rU   )rS   )z$Content-Type: text/css;charset=iso-hrU   )rL   )zContent-Type: text/cssz@charset "ascii";)ra   N)r-   ZgetEncodingInfor    encodingZmismatch)r   r2   r4   r3   headerra   resr   r   r   test_getEncodingInfo   s    cz%TestAutoEncoding.test_getEncodingInfoN)r   r   r   r    r5   r;   r?   r@   rF   rK   rf   r   r   r   r   r      s    ]r   )__doc__http.clientr   ior   Zcssutils.encutilsr-   rI   Zbuildlogr,   r   r   r   r   r   <module>   s    