
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
kS                 @   s|   d dl Z d dlZd dlZd dlmZmZmZ d dlmZ G dd dej	Z
G dd dej	Zdd	 Zed
krxejd	d dS )    N)Markupescapeescape_silent)	text_typec               @   s   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
ejd"krZdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!S )#MarkupTestCasec             C   s   d}t d}d S )Nz?<script type="application/x-some-script">alert("foo");</script>z<em>username</em>)r   )selfZunsafeZsafe r   /usr/lib64/python3.6/tests.pytest_adding   s    zMarkupTestCase.test_addingc             C   s   d S )Nr   )r   r   r   r	   test_string_interpolation   s    	z(MarkupTestCase.test_string_interpolationc             C   s   t d}d S )Nfoo)r   )r   xr   r   r	   test_type_behavior   s    z!MarkupTestCase.test_type_behaviorc             C   s   G dd dt }d S )Nc               @   s    e Zd Zdd Zdd ZeZdS )z-MarkupTestCase.test_html_interop.<locals>.Fooc             S   s   dS )Nz<em>awesome</em>r   )r   r   r   r	   __html__'   s    z6MarkupTestCase.test_html_interop.<locals>.Foo.__html__c             S   s   dS )Nawesomer   )r   r   r   r	   __unicode__)   s    z9MarkupTestCase.test_html_interop.<locals>.Foo.__unicode__N)__name__
__module____qualname__r   r   __str__r   r   r   r	   Foo&   s   r   )object)r   r   r   r   r	   test_html_interop$   s    z MarkupTestCase.test_html_interopc             C   s   | j tdd td d S )Nz<em>%s:%s</em><foo><bar>z <em>&lt;foo&gt;:&lt;bar&gt;</em>)r   r   )assertEqualr   )r   r   r   r	   test_tuple_interpol0   s    
 z"MarkupTestCase.test_tuple_interpolc             C   s>   | j tdddi td | j tdddd td d S )	Nz<em>%(foo)s</em>r   z<foo>z<em>&lt;foo&gt;</em>z<em>%(foo)s:%(bar)s</em>z<bar>)r   barz <em>&lt;foo&gt;:&lt;bar&gt;</em>)r   r   )r   r   r   r	   test_dict_interpol6   s    


z!MarkupTestCase.test_dict_interpolc             C   s   d S )Nr   )r   r   r   r	   test_escaping?   s    zMarkupTestCase.test_escapingc          
   C   s   xt dd dft dd dft dd dft djdddft djdddigdft djddt digdffD ]\}}qvW d S )Nz%igQ	@3z%.2fgn!	@z3.14z%s %s %s<{   >z&lt; 123 &gt;z<em>{awesome}</em>z	<awesome>)r   z<em>&lt;awesome&gt;</em>z{0[1][bar]}r   r   z<bar/>z&lt;bar/&gt;)r!   r"   r#   )r   format)r   actualZexpectedr   r   r	   test_formattingE   s    zMarkupTestCase.test_formatting      c             C   s   t djd}d S )Nz{}r   )r   r$   )r   Z	formattedr   r   r	   test_formatting_emptyT   s    z$MarkupTestCase.test_formatting_emptyc             C   s$   G dd dt }G dd dt }d S )Nc               @   s   e Zd Zdd ZdS )z:MarkupTestCase.test_custom_formatting.<locals>.HasHTMLOnlyc             S   s   t dS )Nz<foo>)r   )r   r   r   r	   r   Z   s    zCMarkupTestCase.test_custom_formatting.<locals>.HasHTMLOnly.__html__N)r   r   r   r   r   r   r   r	   HasHTMLOnlyY   s   r*   c               @   s   e Zd Zdd Zdd ZdS )z?MarkupTestCase.test_custom_formatting.<locals>.HasHTMLAndFormatc             S   s   t dS )Nz<foo>)r   )r   r   r   r	   r   ^   s    zHMarkupTestCase.test_custom_formatting.<locals>.HasHTMLAndFormat.__html__c             S   s   t dS )Nz<FORMAT>)r   )r   specr   r   r	   __html_format__`   s    zOMarkupTestCase.test_custom_formatting.<locals>.HasHTMLAndFormat.__html_format__N)r   r   r   r   r,   r   r   r   r	   HasHTMLAndFormat]   s   r-   )r   )r   r*   r-   r   r   r	   test_custom_formattingX   s    z%MarkupTestCase.test_custom_formattingc             C   s   G dd dt }|dd}d S )Nc               @   s$   e Zd Zdd Zdd Zdd ZdS )z;MarkupTestCase.test_complex_custom_formatting.<locals>.Userc             S   s   || _ || _d S )N)idusername)r   r/   r0   r   r   r	   __init__h   s    zDMarkupTestCase.test_complex_custom_formatting.<locals>.User.__init__c             S   s2   |dkrt dj| j| j S |r*td| j S )Nlinkz<a href="/user/{0}">{1}</a>zInvalid format spec)r   r$   r/   r   
ValueError)r   format_specr   r   r	   r,   k   s    
zKMarkupTestCase.test_complex_custom_formatting.<locals>.User.__html_format__c             S   s   t dj| jS )Nz<span class=user>{0}</span>)r   r$   r0   )r   r   r   r	   r   t   s    zDMarkupTestCase.test_complex_custom_formatting.<locals>.User.__html__N)r   r   r   r1   r,   r   r   r   r   r	   Userg   s   	r5      r   )r   )r   r5   userr   r   r	   test_complex_custom_formattingf   s    
z-MarkupTestCase.test_complex_custom_formattingc             C   s&   dd l }x|jD ]}t|| qW d S )Nr   )
markupsafe__all__getattr)r   Zmarkupitemr   r   r	   test_all_set{   s    zMarkupTestCase.test_all_setc             C   s   d S )Nr   )r   r   r   r	   test_escape_silent   s    z!MarkupTestCase.test_escape_silentc             C   sd   | j tdj tdtdg | j tdj tdtdg | j tdj tdtdg d S )Nza babza
b)r   r   splitrsplit
splitlines)r   r   r   r	   test_splitting   s    zMarkupTestCase.test_splittingc             C   s   | j tdd td d S )Nr?      Zaaa)r   r   )r   r   r   r	   test_mul   s    zMarkupTestCase.test_mulN)r'   r(   )r   r   r   r
   r   r   r   r   r   r   r&   sysversion_infor)   r.   r8   r=   r>   rD   rF   r   r   r   r	   r   	   s    	
r   c               @   s   e Zd Zdd ZdS )MarkupLeakTestCasec             C   s`   t  }xTtdD ]H}x0tdD ]$}td td td td qW |jttj  qW d S )N   i  r   z<foo>)setranger   addlengcZget_objects)r   Zcountscountr<   r   r   r	   test_markup_leaks   s    z$MarkupLeakTestCase.test_markup_leaksN)r   r   r   rQ   r   r   r   r	   rI      s   rI   c              C   s6   t j } | jt jt ttds2| jt jt | S )NZ	func_code)unittestZ	TestSuiteZaddTestZ	makeSuiter   hasattrr   rI   )suiter   r   r	   rT      s
    
rT   __main__)ZdefaultTest)rO   rG   rR   r9   r   r   r   Zmarkupsafe._compatr   ZTestCaser   rI   rT   r   mainr   r   r   r	   <module>   s    