a
    bg	                     @   sP   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 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                   @   sH   e Zd ZdZddeeef ee ddddZe	e
e dd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                C   s   || _ || _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	    r   /var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/document_loaders/parsers/generic.py__init__$   s    zMimeTypeBasedParser.__init__)blobr   c                 c   sr   |j }|du rt| d|| jv rB| j| }||E dH  n,| jdur`| j|E dH  ntd| dS )zLoad documents from a blob.Nz does not have a mimetype.zUnsupported mime type: )mimetype
ValueErrorr
   
lazy_parser	   )r   r   r   handlerr   r   r   r   9   s    


zMimeTypeBasedParser.lazy_parse)__name__
__module____qualname____doc__r   strr   r   r   r   r   r   r   r   r   r   r   r      s   
r   N)r   typingr   r   r   Zlangchain_core.documentsr   Z)langchain_community.document_loaders.baser   Z8langchain_community.document_loaders.blob_loaders.schemar   r   r   r   r   r   <module>   s
   