o
    i                     @   sP   d dl Z d dlZd dlZd dlmZ dd Zdd Zdd Zd	d
 Zdd Z	dS )    N)
filestringc                 C   sF   | d }|   |d }|d tt|t|d}|dks!J dS )z/filestring should read files inside allowed_dirallowedzexample.txtzhello worldallowed_dirN)mkdir
write_textr   str)tmp_pathr   foutput r   U/home/ubuntu/.local/lib/python3.10/site-packages/nltk/test/test_filestring_sandbox.pytest_reads_allowed_file	   s   
r   c                 C   sr   | d }|   | d }|d t|d d }tt t|t|d W d   dS 1 s2w   Y  dS )z.filestring should block ../ traversal attemptsr   z
secret.txt	topsecretz..r   N)r   r   r   pytestraisesPermissionErrorr   )r	   r   secrettraversal_pathr   r   r   test_rejects_parent_traversal   s   
"r   c              	   C   s   | d }|   | d }|d |d }z|| W n ttfy,   td Y nw tt t	t
|t
|d W d   dS 1 sHw   Y  dS )z<filestring should block symlink pointing outside allowed_dirr   zoutside.txtzhidden-datazlink.txtz/Symlink creation not supported on this platformr   N)r   r   
symlink_toOSErrorNotImplementedErrorr   skipr   r   r   r   )r	   r   outsidelinkr   r   r   test_rejects_symlink_escape$   s   
"r   c                  C   s   t d} t| dksJ dS )zBfilestring should maintain legacy behavior for stream-like objectszstream-dataN)ioStringIOr   )streamr   r   r    test_preserves_file_like_objects8   s   
r    c                 C   sT   | d }|   |d }|d tt|t|d}t|ts"J d|v s(J dS )z=filestring should tolerate decoding errors when reading filesr   z
latin1.txts   cafr   cafN)r   write_bytesr   r   
isinstance)r	   r   r
   r   r   r   r   test_encoding_fallback>   s   
r$   )
r   osr   	nltk.utilr   r   r   r   r    r$   r   r   r   r   <module>   s    