
    h	                     V    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y)	ztCode for generic / auxiliary parsers.

This module contains some logic to help assemble more sophisticated parsers.
    )IteratorMappingOptional)Document)BaseBlobParser)Blobc                   P    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y)
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                     || _         || _        y)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      r/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/document_loaders/parsers/generic.py__init__zMimeTypeBasedParser.__init__$   s    $ !.    blobc              #   4  K   |j                   }|t        | d      || j                  v r)| j                  |   }|j                  |      E d{    y| j                  $| j                  j                  |      E d{    yt        d|       7 C7 w)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     ==v%?@AAt}}$mmH-G))$///##///::4@@@ #:8*!EFF 0 As$   ABB/B BBB)__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r    r   r   r
   r
      sW    2 59	/#~-./ ".1	/
 
/*Gt 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 I9G. 9Gr   