o
    /h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   P/var/www/html/myenv/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_TYPE_XML_TEXT_TYPE_HTML_TEXT_TYPE
_TEXT_UTF8
_TEXT_TYPE_OTHER_TYPElistr   _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.   r3   r4   r   _getTextTyper,   r6   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+   )r4   r   r-   encodingByMediaTyper,   r6   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&   rC   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&   rD   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)r4   r   r-   getMetaInfor,   r6   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_ber;   )	utf_32_ler<   )	utf_16_ber=   )	utf_16_ler>   )rB   r?   )rC   z'<?xml version="1.0" encoding="ascii" ?>)rC   z'<?xml version='1.0' encoding='ascii' ?>)rD   z,<?xml version='1.0' encoding='iso-8859-1' ?>)rB   z<?xml version="1.0" ?>)rB   z*<?xml version="1.0"?><x encoding="ascii"/>r+   N)r-   detectXMLEncodingr,   r   r7   r9   r8   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)rC   s   abczwindows-1252u   €)rC      1rD   u   äöüßN)encodeImportErrorr-   tryEncodingslowerrN   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)#)rB   F)#Content-Type: application/xhtml+xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml"/>
                    </example>)rV   )NrX   )rV   )rW   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-HrX   )rY   )r[   F<?xml version="1.0" encoding="iso-X" ?>
                    <example/>)rZ   F)r[   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)rW   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml;charset=iso_M"/>
                    </example>)r]   )z+Content-Type: application/xml;charset=iso-h1)rV   )Content-Type: application/xmlN)NF)r`   r_   )rC   F)Content-Type: text/xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml"/>
                    </example>)rb   )rc   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)rb   )rc   r_   )rb   )rc   N)r]   )$Content-Type: text/xml;charset=iso-Hrd   )r]   )re   r\   )r]   )re   z<?xml version="1.0"  encoding="iso-h" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)rD   F)Content-Type: text/html;z\<meta http-equiv="Content-Type"
                                        content="text/html">rf   )rg   N)r]   )%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">)rY   )ri   rj   )ra   )Nzb<meta http-equiv="Content-Type"
                                content="text/html;charset=iso-m">)ra   )NzT<meta http-equiv="Content-Type"
                                content="text/html">)ra   )Ntext)ra   )N )rf   )NoContentTypeOnlyTextrh   )rf   )rg   r_   )rV   )Nz<?xml version=)r^   )Nz&<?xml version="1.0" encoding="iso-X"?>)rV   )Nz<?xml version="1.0" ?>
                                    <html><meta http-equiv="Content-Type"
                                    content="text/html;charset=iso-m"></html>)rV   )zContent-Type: text/css;r_   )r]   )z$Content-Type: text/css;charset=iso-hr_   )rV   )zContent-Type: text/cssz@charset "ascii";)rk   N)r-   getEncodingInfor    encodingmismatch)r   r7   r9   r8   headerrk   resr   r   r   test_getEncodingInfo   s    cz%TestAutoEncoding.test_getEncodingInfoN)r   r   r   r    r:   rA   rF   rH   rO   rU   rt   r   r   r   r   r      s    ]r   )__doc__http.clientr   ior   cssutils.encutilsr-   rR   buildlogr,   r   r   r   r   r   <module>   s    