
    %j7                         d dl Z d dlZd dlZd dlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZmZ erddlmZ dgZd	gZ G d
 de          ZdS )    N)BinaryIOAnyTYPE_CHECKING   )DocumentConverterDocumentConverterResult)
StreamInfo)UnsupportedFormatExceptionFileConversionException)
MarkItDownzapplication/zipz.zipc                   X     e Zd ZdZ	 	 d fdZdedededefd	Z	dededede
fd
Z xZS )ZipConvertera  Converts ZIP files to markdown by extracting and converting all contained files.

    The converter extracts the ZIP contents to a temporary directory, processes each file
    using appropriate converters based on file extensions, and then combines the results
    into a single markdown document. The temporary directory is cleaned up after processing.

    Example output format:
    ```markdown
    Content from the zip file `example.zip`:

    ## File: docs/readme.txt

    This is the content of readme.txt
    Multiple lines are preserved

    ## File: images/example.jpg

    ImageSize: 1920x1080
    DateTimeOriginal: 2024-02-15 14:30:00
    Description: A beautiful landscape photo

    ## File: data/report.xlsx

    ## Sheet1
    | Column1 | Column2 | Column3 |
    |---------|---------|---------|
    | data1   | data2   | data3   |
    | data4   | data5   | data6   |
    ```

    Key features:
    - Maintains original file structure in headings
    - Processes nested files recursively
    - Uses appropriate converters for each file type
    - Preserves formatting of converted content
    - Cleans up temporary files after processing
    
markitdownr   c                V    t                                                       || _        d S )N)super__init___markitdown)selfr   	__class__s     l/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/markitdown/converters/_zip_converter.pyr   zZipConverter.__init__=   s)    
 	%    file_streamstream_infokwargsreturnc                     |j         pd                                }|j        pd                                }|t          v rdS t          D ]}|                    |          r dS dS )N TF)mimetypelower	extensionACCEPTED_FILE_EXTENSIONSACCEPTED_MIME_TYPE_PREFIXES
startswith)r   r   r   r   r   r    prefixs          r   acceptszZipConverter.acceptsE   s      (.B5577 *0b7799	00041 	 	F""6** tt ur   c                    |j         p|j        p|j        }d| d}t          j        |d          5 }|                                D ]}	 t          j        |                    |                    }t          t          j                            |          d         t          j                            |                    }	| j                            ||	          }
|
|d| dz  }||
j        dz   z  }# t"          $ r Y t$          $ r Y w xY w	 d d d            n# 1 swxY w Y   t'          |                                	          S )
NzContent from the zip file `z`:

r   )r    filename)streamr   z	## File: z

)markdown)url
local_pathr)   zipfileZipFilenamelistioBytesIOreadr	   ospathsplitextbasenamer   convert_streamr+   r
   r   r   strip)r   r   r   r   	file_path
md_contentzipObjnamez_file_streamz_file_stream_inforesults              r   convertzZipConverter.convertW   s     OU{'=UAU	D9DDD
_[#.. 	&))  $&Jv{{4/@/@$A$AM)3"$'"2"24"8"8";!#!1!1$!7!7* * *& "-<<,$6 =  F )"&<$&<&<&<<
"fo&>>
1   D.   D!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	( '
0@0@0B0BCCCCsB   D	B,C65D6
D D	DDDDD"%D")r   r   )__name__
__module____qualname____doc__r   r   r	   r   boolr%   r   rA   __classcell__)r   s   @r   r   r      s        $ $L& !& & & & & &   	
 
   $DD  D 	D
 
!D D D D D D D Dr   r   )r.   r1   r4   typingr   r   r   _base_converterr   r   _stream_infor	   _exceptionsr
   r   r   r   r"   r!   r    r   r   <module>rM      s     				 				 / / / / / / / / / / H H H H H H H H % % % % % % M M M M M M M M  )((((((   #8 ^D ^D ^D ^D ^D$ ^D ^D ^D ^D ^Dr   