
    Mh*0                     0   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dOdLdP idQfdKdLdR idNfZ G dS dTe j                  ZdS )U    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   shortenzA <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   zA <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                 4    |                      d          rdndS )Nzhttp://www.internal-link.comzclass="internal"r   )
startswithhrefs    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/tornado/test/escape_test.py<lambda>r!      s%    ??#ABB7""6     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                     dS )Nz%    rel="nofollow" class="external"   r   s    r    r!   r!      s    &M r"   c                   P    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZdS )EscapeTestCasec                 |    t           D ]3\  }}}t          j        j        |fi |}|                     ||           4d S )N)linkify_teststornadoescapelinkifyassertEqual)selftextkwargshtmllinkeds        r    test_linkifyzEscapeTestCase.test_linkify   sU    "/ 	+ 	+D&$^+D;;F;;FVT****	+ 	+r"   c           	         g d}|D ]\  }}|                      t          t          |                    t          |                     |                      t          |          t          t          |                               d S )N)z<foo>z&lt;foo&gt;r4   )s   <foo>s   &lt;foo&gt;)z<>&"'z&lt;&gt;&amp;&quot;&#x27;)z&amp;z	&amp;amp;)u   <é>u
   &lt;é&gt;)s   <é>s
   &lt;é&gt;)r,   r   r   r   r-   tests	unescapedescapeds       r    test_xhtml_escapez EscapeTestCase.test_xhtml_escape   s    
 
 
 #( 	M 	MIwT,y"9"9::DMMJJJT)__d>'3J3J.K.KLLLL	M 	Mr"   c                 d    g d}|D ](\  }}|                      |t          |                     )d S )N))zfoo&#32;barfoo bar)zfoo&#x20;barr;   )zfoo&#X20;barr;   )zfoo&#xabc;baru	   foo઼bar)foo&#xyz;barr<   )	foo&#;barr=   )
foo&#x;barr>   )r,   r   )r-   r6   r8   r7   s       r    test_xhtml_unescape_numericz*EscapeTestCase.test_xhtml_unescape_numeric   sX    
 
 
 #( 	A 	AGYYw(?(?@@@@	A 	Ar"   c                     d                                 dfd                     d          dfdg}|D ](\  }}|                     t          |          |           )d S )N   é%C3%A9latin1z%E9)rA   rB   )encoder,   r   r5   s       r    test_url_escape_unicodez&EscapeTestCase.test_url_escape_unicode   su     __)__X&&. 
 #( 	= 	=IwZ	22G<<<<	= 	=r"   c                    dddt          d          d fg}|D ]h\  }}}|                     t          t          |          |          |           |                     t          t          |          |          |           id S )N)rB   rA   r   )rB   u   Ã©rC   rB   rA   )r   r,   r   r   )r-   r6   r8   r7   encodings        r    test_url_unescape_unicodez(EscapeTestCase.test_url_unescape_unicode  s    (0tH~~t,

 -2 	O 	O(GY \*W*=*=xHH)TTT\$w--BBINNNN	O 	Or"   c                    d}d}d}|                      t          |          |           |                      t          |d          |           |                      t          |          |           |                      t          |d          |           |                      t          |d           t          |                     |                      t          |d d          t          |                     d S )Nz+ #%z
%2B+%23%25z%2B%20%23%25F)plus)rG   )rG   rJ   )r,   r   r   r   )r-   r7   plus_escapedr8   s       r    test_url_escape_quote_plusz)EscapeTestCase.test_url_escape_quote_plus  s    	# I..===IE:::GDDDl33Y???gE:::IFFFlTBBBDOOTTT4e<<<d9oo	
 	
 	
 	
 	
r"   c                     |                      t          t          d                    t                     |                      t          t          d                    t                     d S )Nfoo)r,   typer   strr   r-   s    r    test_escape_return_typesz'EscapeTestCase.test_escape_return_types  sV     	l51122C888l51122LAAAAAr"   c                     |                      t          d          d           |                      t          d          d           |                      t          t          d                    d           d S )Ns   "foo"rN   z"foo"u   "é"rA   )r,   r	   r   rQ   s    r    test_json_decodezEscapeTestCase.test_json_decode"  sn     	X..666W--u555 	T*%5%566AAAAAr"   c           	      B   |                      t          t          d                    d           t          t          u r`|                      t          t          t          d                              d           |                     t          t          d           d S d S )NrA      )r,   r	   r
   bytesrP   r   assertRaisesUnicodeDecodeErrorrQ   s    r    test_json_encodezEscapeTestCase.test_json_encode+  s     	[%:%:;;XFFFC<<[T(^^)D)DEExPPP0+wGGGGG <r"   c                 L    |                      t          d          d           d S )Nz&sequences     of    whitespace   charszsequences of whitespace chars)r,   r   rQ   s    r    test_squeezezEscapeTestCase.test_squeeze4  s3    <==+	
 	
 	
 	
 	
r"   c                 l   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)r^   r_   )dictlisttuplerW   r`   rN   barra   rb   )rN   rc   rW   )r,   r   )r-   r6   s     r    test_recursive_unicodez%EscapeTestCase.test_recursive_unicode:  s    V$V$%	
 
 	*5=99E5>JJJ*5=99E5>JJJ*5>::NKKK*5>::EBBBBBr"   N)__name__
__module____qualname__r2   r9   r?   rE   rH   rL   rR   rT   rZ   r\   rd   r$   r"   r    r&   r&      s        + + +
M M MA A A	= 	= 	=O O O
 
 
B B BB B BH H H
 
 

C 
C 
C 
C 
Cr"   r&   )unittestr)   tornado.escaper   r   r   r   r   r   r	   r
   r   r   tornado.utilr   typingr   r   r   r   r   r(   TestCaser&   r$   r"   r    <module>rm      s                            & % % % % % 0 0 0 0 0 0 0 0 0 0 0 0 0 0 	#
B 	;
{ 	I
g( 	I
n'2 	F
k1@ 	#
I?J 	$
KIT 	4
ZS^ 	/
a]h 	6
ogr 	@
rq| 	$
J{F 	%
LEP 	%
QOZ 	&
SYd 	$
Jcn 	1
dmx 		 01/wB 		)-AL 	2
gKV 	$
KU` 	)
U_j 	-
]it 	Q	 34	Us@ 	"
GJ 	(
TIT 	'
KS^ 	'	T"&]h 	E!d33	ngt 	A	D	ns@ 	:
VJ 	:	)]IT 	 	:;jS^ 	F  	
	s]v 	 	MMNjuDnC nC nC nC nCX& nC nC nC nC nCr"   