
    QVjiH              	           d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ dgZ ed           G d	 de	eeef                                        Zd
S )    )Iterable)IOBase)Optional)functional_datapipe)IterDataPipe) get_file_binaries_from_pathnamesFileOpenerIterDataPipe
open_filesc            	       `     e Zd ZdZ	 	 	 ddee         dedee         def fd	Zd
 Z	d Z
 xZS )r	   a  
    Given pathnames, opens files and yield pathname and file stream in a tuple (functional name: ``open_files``).

    Args:
        datapipe: Iterable datapipe that provides pathnames
        mode: An optional string that specifies the mode in which
            the file is opened by ``open()``. It defaults to ``r``, other options are
            ``b`` for reading in binary mode and ``t`` for text mode.
        encoding: An optional string that specifies the encoding of the
            underlying file. It defaults to ``None`` to match the default encoding of ``open``.
        length: Nominal length of the datapipe

    Note:
        The opened file handles will be closed by Python's GC periodically. Users can choose
        to close them explicitly.

    Example:
        >>> # xdoctest: +SKIP
        >>> from torchdata.datapipes.iter import (
        ...     FileLister,
        ...     FileOpener,
        ...     StreamReader,
        ... )
        >>> dp = FileLister(root=".").filter(lambda fname: fname.endswith(".txt"))
        >>> dp = FileOpener(dp)
        >>> dp = StreamReader(dp)
        >>> list(dp)
        [('./abc.txt', 'abc')]
    rNdatapipemodeencodinglengthc                     t                                                       || _        || _        || _        | j        dvrt          d|           d|v r|t          d          || _        d S )N)btrbrtr   zInvalid mode r   z-binary mode doesn't take an encoding argument)super__init__r   r   r   
ValueErrorr   )selfr   r   r   r   	__class__s        d/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/utils/data/datapipes/iter/fileopener.pyr   zFileOpenerIterDataPipe.__init__0   s     	"*	'/97773T33444 $;;8/LMMM!    c              #   V   K   t          | j        | j        | j                  E d {V  d S )N)r   r   r   r   r   s    r   __iter__zFileOpenerIterDataPipe.__iter__I   sM      3M49dm
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r   c                 n    | j         dk    r$t          t          |           j         d          | j         S )Nr   z# instance doesn't have valid length)r   	TypeErrortype__name__r   s    r   __len__zFileOpenerIterDataPipe.__len__N   s7    ;"tDzz2WWWXXX{r   )r   Nr   )r$   
__module____qualname____doc__r   strr   intr   r    r%   __classcell__)r   s   @r   r	   r	      s         B "&" "3-" " 3-	"
 " " " " " "2
 
 

      r   N)collections.abcr   ior   typingr   %torch.utils.data.datapipes._decoratorr   #torch.utils.data.datapipes.datapiper   'torch.utils.data.datapipes.utils.commonr   __all__tupler)   r	    r   r   <module>r5      s    $ $ $ $ $ $             E E E E E E < < < < < < T T T T T T 
 \""@ @ @ @ @\%V*<= @ @ #"@ @ @r   