
    Ǆg
              	           d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZmZmZmZ dgZ e
d       G d	 deeeef                   Zy
)    )BufferedIOBase)AnyCallableIterableIteratorSizedTuple)functional_datapipe)IterDataPipe)_deprecation_warning)basichandlersDecoderextension_extract_fnimagehandlerRoutedDecoderIterDataPiperouted_decodec            	            e Zd ZdZeddeeeef      de	de	ddf fdZ
d	e	ddfd
Zdeeeef      fdZdefdZ xZS )r   a  
    Decodes binary streams from input DataPipe, yields pathname and decoded data in a tuple.

    (functional name: ``routed_decode``)

    Args:
        datapipe: Iterable datapipe that provides pathname and binary stream in tuples
        handlers: Optional user defined decoder handlers. If ``None``, basic and image decoder
            handlers will be set as default. If multiple handles are provided, the priority
            order follows the order of handlers (the first handler has the top priority)
        key_fn: Function for decoder to extract key from pathname to dispatch handlers.
            Default is set to extract file extension from pathname

    Note:
        When ``key_fn`` is specified returning anything other than extension, the default
        handler will not work and users need to specify custom handler. Custom handler
        could use regex to determine the eligibility to handle data.
    )key_fndatapipehandlersr   returnNc                    t         |           || _        |st        t	        d      f}t        |d|i| _        t        t        |       j                  ddd       y )Ntorchr   z1.12z1.13r   )deprecation_versionremoval_versionold_functional_name)
super__init__r   decoder_basichandlersdecoder_imagehandlerr   decoderr   type__name__)selfr   r   r   	__class__s       u/home/mcse/projects/flask_80/flask-venv/lib/python3.12/site-packages/torch/utils/data/datapipes/iter/routeddecoder.pyr   z"RoutedDecoderIterDataPipe.__init__'   sY     	>F-/CG/LMH88J &" /		
    handlerc                 6     | j                   j                  |  y )N)r!   add_handler)r$   r(   s     r&   r*   z%RoutedDecoderIterDataPipe.add_handler9   s       '*r'   c              #   l   K   | j                   D ]!  }|d   }| j                  |      }|||   f # y w)Nr   )r   r!   )r$   datapathnameresults       r&   __iter__z"RoutedDecoderIterDataPipe.__iter__<   s@     MM 	/DAwH\\$'FVH-..	/s   24c                     t        | j                  t              rt        | j                        S t	        t        |       j                   d      )Nz# instance doesn't have valid length)
isinstancer   r   len	TypeErrorr"   r#   )r$   s    r&   __len__z!RoutedDecoderIterDataPipe.__len__B   s=    dmmU+t}}%%4:..//RSTTr'   )r#   
__module____qualname____doc__r   r   r	   strr   r   r   r*   r   r   r/   intr4   __classcell__)r%   s   @r&   r   r      s    . 0	
5n!456
 
 	

 

$+H + +/(5c?3 /U Ur'   N)ior   typingr   r   r   r   r   r	   %torch.utils.data.datapipes._decoratorr
   #torch.utils.data.datapipes.datapiper   'torch.utils.data.datapipes.utils.commonr   (torch.utils.data.datapipes.utils.decoderr   r   r   r   r   r    __all__r8   r    r'   r&   <module>rC      s[     B B E < H  '
' _%2UU38_ = 2U &2Ur'   