o
    Qœ_T0  ã                   @   s  d dl Z d dlZd dlmZmZmZmZmZmZm	Z	m
Z
mZmZ d dlmZ d dlmZmZmZmZmZ g di df‘di df‘d	i d
f‘di df‘di df‘di df‘di df‘di df‘di df‘di df‘di df‘di df‘di df‘di d f‘d!i d"f‘d#i d$f‘d%i d&f‘d'd(d)d*gid+f‘d,d(d*gid-f‘d.i d/f‘d0i d1f‘d2i d3f‘d4i d5f‘d6d(d)d7gid8f‘d9i d:f‘d;i d<f‘d=i d>f‘d=d?d@id=f‘dAd@d@dBœdCf‘dDdEd@idFf‘dGi dHf‘dGd(dIgidJf‘dKdLdMidNf‘dOdLdPdQ„ idRf‘dKdLdSdQ„ idNf‘ZG dTdU„ dUe jƒZdS )Vé    N)
Úutf8Úxhtml_escapeÚxhtml_unescapeÚ
url_escapeÚurl_unescapeÚ
to_unicodeÚjson_decodeÚjson_encodeÚsqueezeÚrecursive_unicode)Úunicode_type)ÚListÚTupleÚUnionÚDictÚAnyzhello http://world.com/!z8hello <a href="http://world.com/">http://world.com/</a>!z0hello http://world.com/with?param=true&stuff=yeszqhello <a href="http://world.com/with?param=true&amp;stuff=yes">http://world.com/with?param=true&amp;stuff=yes</a>z>http://url.com/w(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz]<a href="http://url.com/w">http://url.com/w</a>(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz>http://url.com/withmany.......................................zd<a href="http://url.com/withmany">http://url.com/withmany</a>.......................................z;http://url.com/withmany((((((((((((((((((((((((((((((((((a)za<a href="http://url.com/withmany">http://url.com/withmany</a>((((((((((((((((((((((((((((((((((a)zhttp://foo.com/blah_blahz?<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>zhttp://foo.com/blah_blah/zA<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>z)(Something like http://foo.com/blah_blah)zP(Something like <a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>)z$http://foo.com/blah_blah_(wikipedia)zW<a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>z+http://foo.com/blah_(blah)_(wikipedia)_blahze<a href="http://foo.com/blah_(blah)_(wikipedia)_blah">http://foo.com/blah_(blah)_(wikipedia)_blah</a>z5(Something like http://foo.com/blah_blah_(wikipedia))zh(Something like <a href="http://foo.com/blah_blah_(wikipedia)">http://foo.com/blah_blah_(wikipedia)</a>)zhttp://foo.com/blah_blah.z@<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>.zhttp://foo.com/blah_blah/.zB<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>.z<http://foo.com/blah_blah>zG&lt;<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>&gt;z<http://foo.com/blah_blah/>zI&lt;<a href="http://foo.com/blah_blah/">http://foo.com/blah_blah/</a>&gt;zhttp://foo.com/blah_blah,z@<a href="http://foo.com/blah_blah">http://foo.com/blah_blah</a>,z&http://www.example.com/wpstyle/?p=364.zZ<a href="http://www.example.com/wpstyle/?p=364">http://www.example.com/wpstyle/?p=364</a>.zrdar://1234Úpermitted_protocolsÚhttpÚrdarz%<a href="rdar://1234">rdar://1234</a>z
rdar:/1234z#<a href="rdar:/1234">rdar:/1234</a>z'http://userid:password@example.com:8080z]<a href="http://userid:password@example.com:8080">http://userid:password@example.com:8080</a>zhttp://userid@example.comzA<a href="http://userid@example.com">http://userid@example.com</a>zhttp://userid@example.com:8080zK<a href="http://userid@example.com:8080">http://userid@example.com:8080</a>z"http://userid:password@example.comzS<a href="http://userid:password@example.com">http://userid:password@example.com</a>zFmessage://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3eÚmessagez›<a href="message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e">message://%3c330e7f8409726r6a4ba78dkf1fd71420c1bf6ff@mail.gmail.com%3e</a>u   http://âž¡.ws/ä¨¹u1   <a href="http://âž¡.ws/ä¨¹">http://âž¡.ws/ä¨¹</a>z<tag>http://example.com</tag>zJ&lt;tag&gt;<a href="http://example.com">http://example.com</a>&lt;/tag&gt;zJust a www.example.com link.zAJust a <a href="http://www.example.com">www.example.com</a> link.Úrequire_protocolTz:A http://reallylong.com/link/that/exceedsthelenglimit.html)r   Úshortenz§A <a href="http://reallylong.com/link/that/exceedsthelenglimit.html" title="http://reallylong.com/link/that/exceedsthelenglimit.html">http://reallylong.com/link...</a>z6A http://reallylongdomainnamethatwillbetoolong.com/hi!r   z¢A <a href="http://reallylongdomainnamethatwillbetoolong.com/hi" title="http://reallylongdomainnamethatwillbetoolong.com/hi">http://reallylongdomainnametha...</a>!z/A file:///passwords.txt and http://web.com linkzLA file:///passwords.txt and <a href="http://web.com">http://web.com</a> linkÚfilezSA <a href="file:///passwords.txt">file:///passwords.txt</a> and http://web.com linkzwww.external-link.comÚextra_paramsúrel="nofollow" class="external"z`<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a>z;www.external-link.com and www.internal-link.com/blogs extrac                 C   s   |   d¡rdS dS )Nzhttp://www.internal-link.comzclass="internal"r   )Ú
startswith©Úhref© r   ú:/usr/lib/python3/dist-packages/tornado/test/escape_test.pyÚ<lambda>Å   s   ÿr    zÈ<a href="http://www.external-link.com" rel="nofollow" class="external">www.external-link.com</a> and <a href="http://www.internal-link.com/blogs" class="internal">www.internal-link.com/blogs</a> extrac                 C   s   dS )Nz%    rel="nofollow" class="external"  r   r   r   r   r   r    Î   s    c                   @   sd   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d„ Zdd„ Zdd„ ZdS )ÚEscapeTestCasec                 C   s4   t D ]\}}}tjj|fi |¤Ž}|  ||¡ qd S )N)Úlinkify_testsÚtornadoÚescapeÚlinkifyÚassertEqual)ÚselfÚtextÚkwargsÚhtmlÚlinkedr   r   r   Útest_linkifyÕ   s   þzEscapeTestCase.test_linkifyc                 C   sJ   g d¢}|D ]\}}|   tt|ƒƒt|ƒ¡ |   t|ƒtt|ƒƒ¡ qd S )N)©z<foo>z&lt;foo&gt;r-   )s   <foo>s   &lt;foo&gt;)z<>&"'z&lt;&gt;&amp;&quot;&#39;)z&amp;z	&amp;amp;)u   <Ã©>u
   &lt;Ã©&gt;)s   <Ã©>s
   &lt;Ã©&gt;)r&   r   r   r   ©r'   ÚtestsÚ	unescapedÚescapedr   r   r   Útest_xhtml_escapeÚ   s
   	þz EscapeTestCase.test_xhtml_escapec                 C   s*   g d¢}|D ]\}}|   |t|ƒ¡ qd S )N))zfoo&#32;barúfoo bar)zfoo&#x20;barr3   )zfoo&#X20;barr3   )zfoo&#xabc;baru	   fooàª¼bar)úfoo&#xyz;barr4   )ú	foo&#;barr5   )ú
foo&#x;barr6   )r&   r   )r'   r/   r1   r0   r   r   r   Útest_xhtml_unescape_numericè   s   	ÿz*EscapeTestCase.test_xhtml_unescape_numericc                 C   s@   d  d¡dfd  d¡dfdg}|D ]\}}|  t|ƒ|¡ qd S )Nõ   Ã©r   ú%C3%A9Úlatin1z%E9)r8   r9   )Úencoder&   r   r.   r   r   r   Útest_url_escape_unicodeõ   s   ûÿz&EscapeTestCase.test_url_escape_unicodec                 C   sT   dddt dƒd fg}|D ]\}}}|  tt|ƒ|ƒ|¡ |  tt |ƒ|ƒ|¡ qd S )N)r9   r8   r   )r9   u   ÃƒÂ©r:   r9   r8   )r   r&   r   r   )r'   r/   r1   r0   Úencodingr   r   r   Útest_url_unescape_unicode   s   ýûz(EscapeTestCase.test_url_unescape_unicodec                 C   sŠ   d}d}d}|   t|ƒ|¡ |   t|dd�|¡ |   t|ƒ|¡ |   t|dd�|¡ |   t|d d�t|ƒ¡ |   t|d dd�t|ƒ¡ d S )Nz+ #%z
%2B+%23%25z%2B%20%23%25F)Úplus)r=   )r=   r?   )r&   r   r   r   )r'   r0   Úplus_escapedr1   r   r   r   Útest_url_escape_quote_plus  s   ÿz)EscapeTestCase.test_url_escape_quote_plusc                 C   s,   |   ttdƒƒt¡ |   ttdƒƒt¡ d S )NÚfoo)r&   Útyper   Ústrr   ©r'   r   r   r   Útest_escape_return_types  s   z'EscapeTestCase.test_escape_return_typesc                 C   s8   |   tdƒd¡ |   tdƒd¡ |   ttdƒƒd¡ d S )Ns   "foo"rB   z"foo"u   "Ã©"r8   )r&   r   r   rE   r   r   r   Útest_json_decode   s   zEscapeTestCase.test_json_decodec                 C   sJ   |   ttdƒƒd¡ ttu r#|   tttdƒƒƒd¡ |  ttd¡ d S d S )Nr8   ó   é)r&   r   r	   ÚbytesrD   r   ÚassertRaisesÚUnicodeDecodeErrorrE   r   r   r   Útest_json_encode)  s
   þzEscapeTestCase.test_json_encodec                 C   s   |   tdƒd¡ d S )Nz&sequences     of    whitespace   charszsequences of whitespace chars)r&   r
   rE   r   r   r   Útest_squeeze2  s   þzEscapeTestCase.test_squeezec                 C   sr   ddiddgdddœ}|   t|d ƒddi¡ |   t|d ƒddg¡ |   t|d	 ƒd
¡ |   t|d ƒd¡ d S )Nó   fooó   bar)rN   rO   )ÚdictÚlistÚtuplerI   rP   rB   ÚbarrQ   rR   )rB   rS   rI   )r&   r   )r'   r/   r   r   r   Útest_recursive_unicode8  s   üz%EscapeTestCase.test_recursive_unicodeN)Ú__name__Ú
__module__Ú__qualname__r,   r2   r7   r<   r>   rA   rF   rG   rL   rM   rT   r   r   r   r   r!   Ô   s    		r!   )ÚunittestÚtornado.escaper#   r   r   r   r   r   r   r   r	   r
   r   Útornado.utilr   Útypingr   r   r   r   r   r"   ÚTestCaser!   r   r   r   r   Ú<module>   sš   0ýþýùýóýíýè ýá%ýÜ*ý×/ýÒ4ýÍ9ýÈ>ýÃCý¾Hý¹Mý´Rý¯Wýª\
ý¥aý fý›ký–pý‘uýŒz
ý‡ ý� ý �û ý �ö ý �ñ ý �ì ý �æ !ý �à &ý �Û +ý �Ö 0ÿù �Ñ :
ý �Ç A