
     hE                         d Z ddlZddlmZ 	 ddlmZ  ej                   e             Z	 G d d      Z
y# e$ r ddlZY .w xY w)z
tests for encutils.py
    N)StringIO)streamc                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestAutoEncodingc                 ,     G fdd      } |      S )zbuild a fake HTTP responsec                   $    e Zd Zd Zd Z fdZy)*TestAutoEncoding._fakeRes.<locals>.FakeResc                     t         j                  j                         | _        |j	                  d      }t        |      dkD  r/|d   j                         }| j                  j                  |       y y )N:   )httpclientHTTPMessage_infosplitlenstripset_type)selfcontentitemsts       \/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/cssutils/tests/test_encutils.py__init__z3TestAutoEncoding._fakeRes.<locals>.FakeRes.__init__   sX    ![[446
c*u:> b	)AJJ''*	 "    c                     | j                   S N)r   )r   s    r   infoz/TestAutoEncoding._fakeRes.<locals>.FakeRes.info    s    zz!r   c                     S r    )r   r   s    r   readz/TestAutoEncoding._fakeRes.<locals>.FakeRes.read#   s    r   N)__name__
__module____qualname__r   r   r"   )r   s   r   FakeResr	      s    +"r   r&   r!   )r   r   r&   s    ` r   _fakeReszTestAutoEncoding._fakeRes   s    	 	" wr   c                    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        |j                               D ]%  \  }}|t        j                  |t              k(  r%J  y)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   _getTextTypeByMediaTyper4   r   teststestexps       r   test_getTextTypeByMediaTypez,TestAutoEncoding.test_getTextTypeByMediaType(   s      (==#+#A#A6>6T6T%-%C%C ///7/F/F&55!11 ++"--'' ,,
 ekkm,ID#(::4SIIII -r   c                    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        |j	                               D ]%  \  }}|t        j
                  |t              k(  r%J  y)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   ï»¿anythingr1   r2   r3   N)r5   r6   r;   r<   r   _getTextTyper4   r>   s       r   test_getTextTypez!TestAutoEncoding.test_getTextType;   s     4<3Q3Q3;3Q3Q+3+I+I+3+I+I/7/M/M#+#A#A(0(<(<(0(<(< ( 4 4 ( 4 4$,$8$8'' ,,
 ekkm,ID#(//#>>>> -r   c                     ddddddddddddd}t        |j                               D ]%  \  }}|t        j                  |t              k(  r%J  y)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/   r0   r2   r3   )r<   r   r5   encodingByMediaTyper4   r>   s       r   test_encodingByMediaTypez)TestAutoEncoding.test_encodingByMediaTypeO   se      '#*6=(/#*/6!(%&
 ekkm,ID#(66tEEEE -r   c                     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        |j                               D ]%  \  }}|t        j                  |t              k(  r%J  y)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.   rM   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.   rN   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">r3   N)r<   r   r5   getMetaInfor4   r>   s       r   test_getMetaInfoz!TestAutoEncoding.test_getMetaInfob   s   W
S VW

 U WW
 G IW
 G IW
" U W#W
* V X+W
2 Z \3W
: W Y;W
B Y [CW
J Y [KW
R ] _SW
Z U W[W
b X ZcW
j ] _kW
r j lsW
z U W{W
B U WCW
J +7
XXgW
p ekkm,ID#(..t==== -r   c                 \    d}|D ]%  \  }}|t        j                  |t              k(  r%J  y)zencutils.detectXMLEncoding)
)	utf_32_berD   )	utf_32_lerE   )	utf_16_berF   )	utf_16_lerG   )rL   rH   )rM   z'<?xml version="1.0" encoding="ascii" ?>)rM   z'<?xml version='1.0' encoding='ascii' ?>)rN   z,<?xml version='1.0' encoding='iso-8859-1' ?>)rL   z<?xml version="1.0" ?>)rL   z*<?xml version="1.0"?><x encoding="ascii"/>r3   N)r5   detectXMLEncodingr4   r   r?   rA   r@   s       r   test_detectXMLEncodingz'TestAutoEncoding.test_detectXMLEncoding   s4    
 IC(44TsCCCC r   c                 &   	 dddj                  d      fdg}|D ]-  \  }}|t        j                  |      j	                         k(  r-J  y# t        $ r< dddj                  d      fddj                  d      fddj                  d      fg}Y ww xY w)zencutils.tryEncodings)rM   s   abczwindows-1252u   €)rM      1rN   u   äöüßN)encodeImportErrorr5   tryEncodingslowerrZ   s       r   test_tryEncodingsz"TestAutoEncoding.test_tryEncodings   s    	!n!=>E IC(//5;;====   	!n!=>z00>?z00@A	E	s   A ABBc                     g d}|D ]g  \  }}|\  }}|r&t        j                  | j                  |      |      }nt        j                  |      }|j                  |j                  f}||k(  rgJ  y)zencutils.getEncodingInfo)#)rL   F)#Content-Type: application/xhtml+xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml"/>
                    </example>)rd   )Nrf   )rd   )re   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-Hrf   )rg   )ri   F<?xml version="1.0" encoding="iso-X" ?>
                    <example/>)rh   F)ri   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)re   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="application/xhtml+xml;charset=iso_M"/>
                    </example>)rk   )z+Content-Type: application/xml;charset=iso-h1)rd   )Content-Type: application/xmlN)NF)rn   rm   )rM   F)Content-Type: text/xml<?xml version="1.0" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml"/>
                    </example>)rp   )rq   z<?xml version="1.0" encoding="iso-X" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)rp   )rq   rm   )rp   )rq   N)rk   )$Content-Type: text/xml;charset=iso-Hrr   )rk   )rs   rj   )rk   )rs   z<?xml version="1.0"  encoding="iso-h" ?>
                    <example>
                        <meta http-equiv="Content-Type"
                            content="text/xml;charset=iso_M"/>
                    </example>)rN   F)Content-Type: text/html;z\<meta http-equiv="Content-Type"
                                        content="text/html">rt   )ru   N)rk   )%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">)rg   )rw   rx   )ro   )Nzb<meta http-equiv="Content-Type"
                                content="text/html;charset=iso-m">)ro   )NzT<meta http-equiv="Content-Type"
                                content="text/html">)ro   )Ntext)ro   )N )rt   )NoContentTypeOnlyTextrv   )rt   )ru   rm   )rd   )Nz<?xml version=)rl   )Nz&<?xml version="1.0" encoding="iso-X"?>)rd   )Nz<?xml version="1.0" ?>
                                    <html><meta http-equiv="Content-Type"
                                    content="text/html;charset=iso-m"></html>)rd   )zContent-Type: text/css;rm   )rk   )z$Content-Type: text/css;charset=iso-hrm   )rd   )zContent-Type: text/cssz@charset "ascii";)ry   N)r5   getEncodingInfor'   encodingmismatch)r   r?   rA   r@   headerry   ress          r   test_getEncodingInfoz%TestAutoEncoding.test_getEncodingInfo   sp    a
D ICLFD..t}}V/DdK..D9<<.C#:: r   N)r#   r$   r%   r'   rB   rJ   rP   rS   r[   rb   r   r!   r   r   r   r      s0     ,J&?(F&[>zD(>&mr   r   )__doc__http.clientr   ior   cssutils.encutilsr5   r_   buildlogr4   r   r!   r   r   <module>r      sP     (
 hxz*B B  s   7 	AA