
    %j                     Z    d dl mZmZmZ ddlmZ  G d d          Z G d d          ZdS )	    )AnyBinaryIOOptional   )
StreamInfoc                       e Zd ZdZdddedee         fdZedefd            Zej	        defd	            Zdefd
Z
dS )DocumentConverterResultz0The result of converting a document to Markdown.N)titlemarkdownr
   c                "    || _         || _        dS )aN  
        Initialize the DocumentConverterResult.

        The only required parameter is the converted Markdown text.
        The title, and any other metadata that may be added in the future, are optional.

        Parameters:
        - markdown: The converted Markdown text.
        - title: Optional title of the document.
        N)r   r
   )selfr   r
   s      b/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/markitdown/_base_converter.py__init__z DocumentConverterResult.__init__   s      !


    returnc                     | j         S )]Soft-deprecated alias for `markdown`. New code should migrate to using `markdown` or __str__.r   r   s    r   text_contentz$DocumentConverterResult.text_content   s     }r   c                     || _         dS )r   Nr   )r   r   s     r   r   z$DocumentConverterResult.text_content    s     !r   c                     | j         S )z#Return the converted Markdown text.r   r   s    r   __str__zDocumentConverterResult.__str__%   s
    }r   )__name__
__module____qualname____doc__strr   r   propertyr   setterr    r   r   r	   r	      s        ::  $	   }	   & c    X !S ! ! ! !      r   r	   c                   B    e Zd ZdZdedededefdZdededede	fdZ
dS )	DocumentConverterz.Abstract superclass of all DocumentConverters.file_streamstream_infokwargsr   c                 L    t          dt          |           j         d          )aY  
        Return a quick determination on if the converter should attempt converting the document.
        This is primarily based `stream_info` (typically, `stream_info.mimetype`, `stream_info.extension`).
        In cases where the data is retrieved via HTTP, the `steam_info.url` might also be referenced to
        make a determination (e.g., special converters for Wikipedia, YouTube etc).
        Finally, it is conceivable that the `stream_info.filename` might be used to in cases
        where the filename is well-known (e.g., `Dockerfile`, `Makefile`, etc)

        NOTE: The method signature is designed to match that of the convert() method. This provides some
        assurance that, if accepts() returns True, the convert() method will also be able to handle the document.

        IMPORTANT: In rare cases, (e.g., OutlookMsgConverter) we need to read more from the stream to make a final
        determination. Read operations inevitably advances the position in file_stream. In these case, the position
        MUST be reset it MUST be reset before returning. This is because the convert() method may be called immediately
        after accepts(), and will expect the file_stream to be at the original position.

        E.g.,
        cur_pos = file_stream.tell() # Save the current position
        data = file_stream.read(100) # ... peek at the first 100 bytes, etc.
        file_stream.seek(cur_pos)    # Reset the position to the original position

        Parameters:
        - file_stream: The file-like object to convert. Must support seek(), tell(), and read() methods.
        - stream_info: The StreamInfo object containing metadata about the file (mimetype, extension, charset, set)
        - kwargs: Additional keyword arguments for the converter.

        Returns:
        - bool: True if the converter can handle the document, False otherwise.
        zThe subclass, zS, must implement the accepts() method to determine if they can handle the document.)NotImplementedErrortyper   r   r$   r%   r&   s       r   acceptszDocumentConverter.accepts-   s:    F " FT$ZZ0  F  F  F
 
 	
r   c                      t          d          )a  
        Convert a document to Markdown text.

        Parameters:
        - file_stream: The file-like object to convert. Must support seek(), tell(), and read() methods.
        - stream_info: The StreamInfo object containing metadata about the file (mimetype, extension, charset, set)
        - kwargs: Additional keyword arguments for the converter.

        Returns:
        - DocumentConverterResult: The result of the conversion, which includes the title and markdown content.

        Raises:
        - FileConversionException: If the mimetype is recognized, but the conversion fails for some other reason.
        - MissingDependencyException: If the converter requires a dependency that is not installed.
        z%Subclasses must implement this method)r(   r*   s       r   convertzDocumentConverter.convertT   s    * ""IJJJr   N)r   r   r   r   r   r   r   boolr+   r	   r-   r!   r   r   r#   r#   *   s        88%
%
  %
 	%

 
%
 %
 %
 %
NKK  K 	K
 
!K K K K K Kr   r#   N)typingr   r   r   _stream_infor   r	   r#   r!   r   r   <module>r1      s    * * * * * * * * * * $ $ $ $ $ $" " " " " " " "J?K ?K ?K ?K ?K ?K ?K ?K ?K ?Kr   