
    Ng	                     ^    d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
  G d de          ZdS )	ztCode for generic / auxiliary parsers.

This module contains some logic to help assemble more sophisticated parsers.
    )IteratorMappingOptional)Document)BaseBlobParser)Blobc                   d    e Zd ZdZdddeeef         dee         ddfdZde	de
e         fd	ZdS )
MimeTypeBasedParseraI  Parser that uses `mime`-types to parse a blob.

    This parser is useful for simple pipelines where the mime-type is sufficient
    to determine how to parse a blob.

    To use, configure handlers based on mime-types and pass them to the initializer.

    Example:

        .. code-block:: python

            from langchain_community.document_loaders.parsers.generic import MimeTypeBasedParser

            parser = MimeTypeBasedParser(
                handlers={
                    "application/pdf": ...,
                },
                fallback_parser=...,
            )
    N)fallback_parserhandlersr   returnc                "    || _         || _        dS )a  Define a parser that uses mime-types to determine how to parse a blob.

        Args:
            handlers: A mapping from mime-types to functions that take a blob, parse it
                      and return a document.
            fallback_parser: A fallback_parser parser to use if the mime-type is not
                             found in the handlers. If provided, this parser will be
                             used to parse blobs with all mime-types not found in
                             the handlers.
                             If not provided, a ValueError will be raised if the
                             mime-type is not found in the handlers.
        N)r   r   )selfr   r   s      p/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/document_loaders/parsers/generic.py__init__zMimeTypeBasedParser.__init__$   s    $ !.    blobc              #     K   |j         }|t          | d          || j        v r*| j        |         }|                    |          E d{V  dS | j        "| j                            |          E d{V  dS t          d|           )zLoad documents from a blob.Nz does not have a mimetype.zUnsupported mime type: )mimetype
ValueErrorr   
lazy_parser   )r   r   r   handlers       r   r   zMimeTypeBasedParser.lazy_parse9   s      =@@@AAAt}$$mH-G))$///////////#//::4@@@@@@@@@@@ !E8!E!EFFFr   )__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r    r   r   r
   r
      s         2 59	/ / /#~-./ ".1	/
 
/ / / /*Gt G(: G G G G G Gr   r
   N)r   typingr   r   r   langchain_core.documentsr   )langchain_community.document_loaders.baser   8langchain_community.document_loaders.blob_loaders.schemar   r
   r   r   r   <module>r#      s    
 / . . . . . . . . . - - - - - - D D D D D D I I I I I I9G 9G 9G 9G 9G. 9G 9G 9G 9G 9Gr   