
    qi                     N    d dl Z d dlZd dlmZ d dlmZmZ defdZd Z	d Z
d Zy)	    N)TemporaryDirectory)ZipFilePathPointeropen_datafilecontentsc                 Z   t         j                  j                  | d      }t         j                  j                  ||      j                  t         j                  j                  d      }t        j                  |d      5 }|j                  ||       ddd       ||fS # 1 sw Y   ||fS xY w)z
    Create a zip file under root_dir with a single file at rel_dir/file_name
    containing 'contents'. Return the full path to the zip file and the
    relative path inside the zip.
    ztestdata.zip/wN)ospathjoinreplacesepzipfileZipFilewritestr)root_dirrel_dir	file_namer   zip_patharcnamezfs          S/opt/pipecat/venv/lib/python3.12/site-packages/nltk/test/unit/test_open_datafile.py_create_test_zipr      s     ww||Hn5Hggll7I.66rww{{CHG	3	' '2
GX&' W' Ws   ?BB*c                     t               5 } t        j                  j                  dd      }d}d}|j	                  d      }t        | |||      \  }}|j                  t        j                  j                  d      dz   }t        ||      }t        ||d      5 }	|	j                         }
ddd       
|k(  sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	zIopen_datafile should open a file inside a zip when given dir + file_name.corporatestpkg
sample.txtzHello from zipped data
utf-8r   r   encodingNr   r
   r   r   encoder   r   r   r   r   read)tmpdirr   r   textdatar   r   	dir_entryr   fresults              r   2test_open_datafile_directory_and_filename_from_zipr*      s    		 '',,y)4 	){{7#,VWiN' OOBGGKK5;	 "(I649wG 	1VVXF	 ~~# 	 	 s$   BCC*CC	CCc                     t               5 } t        j                  j                  dd      }d}d}|j	                  d      }t        | |||      \  }}|j                  t        j                  j                  d      dz   }t        ||      }|j                  |      }	t        |	d      5 }
|
j                         }ddd       |k(  sJ 	 ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	zJopen_datafile should open a file pointer directly when file_name is empty.r   r   r   z%Direct file pointer from zipped data
r   r   )r    Nr!   )r$   r   r   r%   r&   r   r   r'   dir_pointerfile_pointerr(   r)   s               r   (test_open_datafile_file_pointer_from_zipr.   -   s    		 '',,y)4 	7{{7#,VWiN' OOBGGKK5;	(9="''	2<': 	aVVXF	 ~~! 	 	 s$   BC)C:CC	CC(c                     t               5 } t        j                  j                  dd      }d}d}t	        | |||      \  }}|j                  t        j                  j                  d      dz   }t        ||      }t        ||d      5 }|j                         }	ddd       t        	t        t        f      sJ |	|k(  sJ 	 ddd       y# 1 sw Y   2xY w# 1 sw Y   yxY w)z?open_datafile should return a binary stream when encoding=None.r   r   z
binary.bins    r   Nr   )r   r
   r   r   r   r   r   r   r   r#   
isinstancebytes	bytearray)
r$   r   r   binary_datar   r   r'   r,   r(   r)   s
             r   'test_open_datafile_binary_mode_from_zipr4   B   s    		 %'',,y)4 	),VWiU'OOBGGKK5;	(9=;)dK 	qVVXF	 &5)"4555$$$% %	 	% %s$   A=CC
'C
C	CC)r
   r   tempfiler   	nltk.datar   r   r1   r   r*   r.   r4        r   <module>r9      s,    	  ' 7U ,*%r8   