a
    ¡˜ëjŒC  ã                   @  sÌ   d Z ddlmZ ddlZddlmZmZmZmZm	Z	 ddl
mZ erRddlmZ ndZdddd	d
d	d
dd
d	ddœ
dd„ZG dd„ dejƒZdddddœdddd	ddddœdd„ZedƒZdddœdd„ZdS )zDomain-model for file-types.é    )ÚannotationsN)ÚTYPE_CHECKINGÚCallableÚIterableÚTypeÚcast)Ú	ParamSpec)ÚElementzType['FileType']Ústrú
str | NoneúIterable[str]z
'FileType')
ÚclsÚvalueÚpartitioner_shortnameÚimportable_package_dependenciesÚ
extra_nameÚ
extensionsÚcanonical_mime_typeÚalias_mime_typesÚpartitioner_full_module_pathÚreturnc	           
      C  sJ   t  | ¡}	||	_||	_t|ƒ|	_||	_t|ƒ|	_||	_t|ƒ|	_	||	_
|	S )z·
    Moving here instead of directly in the FileType.__new__ allows us
    to dynamically create new enum properties.

    FileType.__new__ does not work with dynamic properties.
    )ÚobjectÚ__new__Ú_value_Ú_partitioner_shortnameÚtupleÚ _importable_package_dependenciesÚ_extra_nameÚ_extensionsÚ_canonical_mime_typeÚ_alias_mime_typesÚ_partitioner_full_module_path)
r   r   r   r   r   r   r   r   r   Úval© r#   ú\/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/unstructured/file_utils/model.pyÚ_create_file_type_enum   s    



r%   c                
   @  s>  e Zd ZU dZded< ded< ded< ded< ded	< ded
< ded< d›dddddddddœdd„Zd ddœdd„Zedddœdd„ƒZedddœdd„ƒZ	e
ddœdd„ƒZe
ddœdd „ƒZe
ddœd!d"„ƒZe
ddœd#d$„ƒZe
ddœd%d&„ƒZe
ddœd'd(„ƒZe
ddœd)d*„ƒZd+d,d-gd,d.gd/eee g ƒfZd0d0d1gd0d2gd3g d4¢fZd5d5d6gd5d7gd8eee g ƒfZd6d6d6gd6d9gd:eee g ƒfZd;d<eee g ƒdd=d>gd?eee g ƒfZd@d@dAgd@dBgdCdDgfZdEd,d-gd,dFgdGeee g ƒfZdHdHeee g ƒddIdJgdKeee g ƒfZdLd,d-gd,dMdNgdOeee g ƒfZdPdPeee g ƒddQgdReee g ƒfZdSdSdTgdSdUgdVdWgfZdXdXdYgdXdZgd[eee g ƒfZ d\d\eee g ƒdd]gd^eee g ƒfZ!d_d_d6dAgd_d`gdaeee g ƒfZ"dbdbdAgdbdcgddeee g ƒfZ#dedeg df¢dedggdheee g ƒfZ$did,d-gd,djgdkeee g ƒfZ%dldldmgdldngdoeee g ƒfZ&dmdmdmgdmdpgdqeee g ƒfZ'drdrdAgdrdsgdteee g ƒfZ(dududAgdudvgdwdxgfZ)dyd,d-gd,dzgd{eee g ƒfZ*d|d|d1gd|d}d~gdeee g ƒfZ+d€d�eee g ƒdg d‚¢dƒg d„¢fZ,d…deee g ƒdd†gd‡g dˆ¢fZ-d‰dŠd1d‹gdŠdŒgd�eee g ƒfZ.dŠdŠd1d‹gdŠdŽgd�eee g ƒfZ/d�d�eee g ƒdd‘gd’d“gfZ0d”deee g ƒdd•gd–eee g ƒfZ1d—deee g ƒdeee g ƒd˜eee g ƒfZ2d™deee g ƒdeee g ƒdšeee g ƒfZ3dS )œÚFileTypez”The collection of file-types recognized by `unstructured`.

    Note not all of these can be partitioned, e.g. WAV and ZIP have no partitioner.
    r   r   ztuple[str, ...]r   r   r   r
   r   r    r!   Nr   )r   r   r   r   r   r   r   r   c	           	   
   C  s   t | ||||||||ƒ	S )N)r%   )	r   r   r   r   r   r   r   r   r   r#   r#   r$   r   H   s    ÷zFileType.__new__Úbool)Úotherr   c                 C  s   | j |j k S )z½Makes `FileType` members comparable with relational operators, at least with `<`.

        This makes them sortable, in particular it supports sorting for pandas groupby functions.
        )Úname)Úselfr(   r#   r#   r$   Ú__lt___   s    zFileType.__lt__zFileType | None)Ú	extensionr   c                 C  s2   |dv rdS | j  ¡ D ]}||jv r|  S qdS )aP  Select a FileType member based on an extension.

        `extension` must include the leading period, like `".pdf"`. Extension is suitable as a
        secondary file-type identification method but is unreliable for primary identification.

        Returns `None` when `extension` is not registered for any supported file-type.
        )NÚ Ú.N)Ú__members__Úvaluesr   )r   r,   Úmr#   r#   r$   Úfrom_extensionf   s    	

zFileType.from_extension)Ú	mime_typer   c                 C  s<   |du rdS | j  ¡ D ] }||jks.||jv r|  S qdS )zÔSelect a FileType member based on a MIME-type.

        Returns `None` when `mime_type` is `None` or does not map to the canonical MIME-type of a
        `FileType` member or one of its alias MIME-types.
        N)r/   r0   r   r    )r   r3   r1   r#   r#   r$   Úfrom_mime_typex   s    
zFileType.from_mime_type)r   c                 C  s   | j S )a  The `pip` "extra" that must be installed to provide this file-type's dependencies.

        Like "image" for PNG, as in `pip install "unstructured[image]"`.

        `None` when partitioning this file-type requires only the base `unstructured` install.
        )r   ©r*   r#   r#   r$   r   ˆ   s    zFileType.extra_namec                 C  s   | j S )aÜ  Packages that must be importable for this file-type's partitioner to work.

        In general, these are the packages provided by the `pip install` "extra" for this file-type,
        like `pip install "unstructured[docx]"` loads the `python-docx` package.

        Note that these names are the ones used in an `import` statement, which is not necessarily
        the same as the _distribution_ package name used by `pip`. For example, the DOCX
        distribution package name is `"python-docx"` whereas the _importable_ package name is
        `"docx"`. This latter name as it appears like `import docx` is what is provided by this
        property.

        The return value is an empty tuple for file-types that do not require optional dependencies.

        Note this property does not complain when accessed on a non-partitionable file-type, it
        simply returns an empty tuple because file-types that are not partitionable require no
        optional dependencies.
        )r   r5   r#   r#   r$   r   ’   s    z(FileType.importable_package_dependenciesc                 C  s   t | jƒpt | jƒS )a~  True when there is a partitioner for this file-type.

        Note this does not check whether the dependencies for this file-type are installed so
        attempting to partition a file of this type may still fail. This is meant for
        distinguishing file-types like WAV, ZIP, EMPTY, and UNK which are legitimate file-types
        but have no associated partitioner.
        )r'   r   r!   r5   r#   r#   r$   Úis_partitionable§   s    	zFileType.is_partitionablec                 C  s   | j S )aL  The canonical MIME-type for this file-type, suitable for use in metadata.

        This value is used in `.metadata.filetype` for elements partitioned from files of this
        type. In general it is the "offical", "recommended", or "defacto-standard" MIME-type for
        files of this type, in that order, as available.
        )r   r5   r#   r#   r$   r3   ²   s    zFileType.mime_typec                 C  sB   | j  }r| d¡d S | j }du r8td| j› d�ƒ‚d|› �S )zÿName of partitioner function for this file-type. Like "partition_docx".

        Raises when this property is accessed on a file-type that is not partitionable. Use
        `.is_partitionable` to avoid exceptions when partitionability is unknown.
        r.   éÿÿÿÿNz;`.partitioner_function_name` is undefined because FileType.úb is not partitionable. Use `.is_partitionable` to determine whether a `FileType` is partitionable.Z
partition_)r!   Úsplitr   Ú
ValueErrorr)   ©r*   Zfull_module_pathÚ	shortnamer#   r#   r$   Úpartitioner_function_name¼   s    

ÿz"FileType.partitioner_function_namec                 C  sL   | j  }r"d | d¡dd… ¡S | j }du rBtd| j› d�ƒ‚d|› �S )z�Fully-qualified name of module providing partitioner for this file-type.

        e.g. "unstructured.partition.docx" for FileType.DOCX.
        r.   Nr7   z:`.partitioner_module_qname` is undefined because FileType.r8   zunstructured.partition.)r!   Újoinr9   r   r:   r)   r;   r#   r#   r$   Úpartitioner_module_qnameÑ   s    	
ÿz!FileType.partitioner_module_qnamec                 C  s   | j S )az  Familiar name of partitioner, like "image" for file-types that use `partition_image()`.

        One use is to determine whether a file-type is one of the five image types, all of which
        are processed by `partition_image()`.

        `None` for file-types that are not partitionable, although `.is_partitionable` is the
        preferred way of discovering that.
        )r   r5   r#   r#   r$   r   å   s    
zFileType.partitioner_shortnameZbmpÚimageZunstructured_inferencez.bmpz	image/bmpÚcsvZpandasz.csvztext/csv)zapplication/csvzapplication/x-csvztext/comma-separated-valuesztext/x-comma-separated-valuesz
text/x-csvÚdocZdocxz.doczapplication/mswordz.docxzGapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentZemlÚemailz.emlz.p7szmessage/rfc822ZepubZpypandocz.epubzapplication/epubzapplication/epub+zipZheicz.heicz
image/heicÚhtmlz.htmlz.htmz	text/htmlZjpgz.jpegz.jpgz
image/jpegÚjsonz.jsonzapplication/jsonZmdZmarkdownz.mdztext/markdownztext/x-markdownÚmsgZoxmsgz.msgzapplication/vnd.ms-outlookZndjsonz.ndjsonzapplication/x-ndjsonZodtz.odtz'application/vnd.oasis.opendocument.textÚorgz.orgztext/orgZpdf)Z	pdf2imageZpdfminerZPILz.pdfzapplication/pdfZpngz.pngz	image/pngZpptZpptxz.pptzapplication/vnd.ms-powerpointz.pptxzIapplication/vnd.openxmlformats-officedocument.presentationml.presentationZrstz.rstz
text/x-rstZrtfz.rtfztext/rtfzapplication/rtfZtiffz.tiffz
image/tiffZtsvz.tabz.tsvztext/tsvÚtxtÚtext)z.txtz.textz.cz.ccz.cppz.csz.cxxz.goz.javaz.jsz.logz.phpz.pyz.rbz.swiftz.tsz.yamlz.ymlz
text/plain)z	text/yamlzapplication/x-yamlzapplication/yamlztext/x-yamlZwavz.wavz	audio/wav)zaudio/vnd.wavzaudio/vnd.wavez
audio/wavezaudio/x-pn-wavzaudio/x-wavZxlsZxlsxZopenpyxlz.xlszapplication/vnd.ms-excelz.xlsxzAapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetÚxmlz.xmlzapplication/xmlztext/xmlÚzipz.zipzapplication/zipZunkzapplication/octet-streamÚemptyzinode/x-empty)N)4Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r+   Úclassmethodr2   r4   Úpropertyr   r   r6   r3   r=   r?   r   r   Úlistr
   ZBMPZCSVZDOCZDOCXZEMLZEPUBZHEICZHTMLZJPGZJSONZMDZMSGZNDJSONZODTZORGZPDFZPNGZPPTZPPTXZRSTZRTFZTIFFZTSVZTXTZWAVZXLSZXLSXÚXMLZZIPZUNKZEMPTYr#   r#   r#   r$   r&   -   sº  
 ÷	
	ù
ù ù
ù
ù
ù
ù
ù
ù	ù
ù
ù	 ù
ù
ù
ù	 ù	"å%ùù
ù	 (ù
ùr&   )r   r   r   r   zIterable[str] | None)r)   r   r   r   r   r   r   c                C  sV   t t| d|pttt g ƒ||p*ttt g ƒ||p<ttt g ƒdƒ	}| |_|tj| < |S )zRegister a new FileType member.N)r%   r&   r   rT   r
   Ú_name_Ú_member_map_)r)   r   r   r   r   r   Útype_r#   r#   r$   Úcreate_file_typeò  s    
÷
rY   Ú_PzDCallable[[Callable[_P, list[Element]]], Callable[_P, list[Element]]])Ú	file_typer   c                   s   dddœ‡ fdd„}|S )NzCallable[_P, list[Element]])Úfuncr   c                   s   | j d | j ˆ _| S )Nr.   )rN   rM   r!   )r\   ©r[   r#   r$   Ú	decorator  s    z'register_partitioner.<locals>.decoratorr#   )r[   r^   r#   r]   r$   Úregister_partitioner  s    r_   )N)rP   Ú
__future__r   ÚenumÚtypingr   r   r   r   r   Ztyping_extensionsr   Zunstructured.documents.elementsr	   r%   ÚEnumr&   rY   rZ   r_   r#   r#   r#   r$   Ú<module>   s(    ÷"   Lù