
    ΅iI              	           S SK JrJr  S SKJr  S SKJr  S SKJr  S SK	J
r
  S/r\" S5       " S S\\\\4      5      5       rg	)
    )IterableIterator)IOBase)functional_datapipe)IterDataPipe) get_file_binaries_from_pathnamesFileOpenerIterDataPipe
open_filesc                      ^  \ rS rSrSr   SS\\   S\S\S-  S\SS4
U 4S	 jjjrS\	\
\\4      4S
 jrS\4S jrSrU =r$ )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')]
Ndatapipemodeencodinglengthreturnc                    > [         TU ]  5         Xl        X l        X0l        U R                  S;  a  [        SU 35      eSU;   a  Ub  [        S5      eX@l        g )N)btrbrtrz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/home/james-whalen/.local/lib/python3.13/site-packages/torch/utils/data/datapipes/iter/fileopener.pyr   FileOpenerIterDataPipe.__init__.   s]     	'/	$,9977}TF344 $;8/LMM!    c              #   v   #    [        U R                  U R                  U R                  5       S h  vN   g  N7f)N)r   r   r   r   r   s    r   __iter__FileOpenerIterDataPipe.__iter__G   s*     3MM499dmm
 	
 	
s   /979c                 |    U R                   S:X  a!  [        [        U 5      R                   S35      eU R                   $ )Nz# instance doesn't have valid length)r   	TypeErrortype__name__r!   s    r   __len__FileOpenerIterDataPipe.__len__L   s6    ;;"tDz2233VWXX{{r   )r   r   r   r   )r   Nr%   )r(   
__module____qualname____firstlineno____doc__r   strintr   r   tupler   r"   r)   __static_attributes____classcell__)r   s   @r   r	   r	      s    B #"3-" " *	"
 " 
" "2
(5f#56 

  r   N)collections.abcr   r   ior   %torch.utils.data.datapipes._decoratorr   #torch.utils.data.datapipes.datapiper   'torch.utils.data.datapipes.utils.commonr   __all__r1   r/   r	    r   r   <module>r;      sQ    .  E < T 
 \"@\%V*<= @ #@r   