
    Mi)                       % S r SSKJr  SSKrSSKrSSKrSSKJr  SSK	J
r
  SSKJr  SSKJr  SSKJr  SS	KJr  \S
   r\" \R*                  \R,                  15      rS\S'   \" SS9 " S S5      5       rS!S jrS"S jrS#S jrS$S jrS%S jrS&S jrS'S jr S(S jr!S)S jr"S*S jr#S+S jr$S,S jr%S-S jr&S.S jr'S/S jr(S0S  jr)g)1zREnvironment and capability diagnostics for optional dependencies and system tools.    )annotationsN)	dataclass)Path)Literal)__version__)FileType)dependency_exists)okmissingwarnzfrozenset[FileType]_FILE_TYPES_NEEDING_SOFFICET)frozenc                  0    \ rS rSr% SrS\S'    S\S'   Srg)	CapabilityResult   zIResult of checking whether partitioning is viable for a target file type.boolreadytuple[str, ...]messages N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       m/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/doctor.pyr   r      s    SKX<r   r   c                6    U R                   nU(       a  SU S3$ g)Nzpip install "unstructured[z]"zpip install unstructured
extra_name)	file_typeextras     r   _pip_hint_for_file_typer%       s"      E+E7"55%r   c                     SU R                   ;   $ )Npypandoc)importable_package_dependencies)r#   s    r   _needs_pandoc_runtimer)   '   s    BBBBr   c                 D    [         R                  R                  S5      S L$ )Nwhisper)	importlibutil	find_specr   r   r   _audio_extra_import_okr/   +   s    >>##I.d::r   c                      SS K n U R                  SSS9ng! [         a     g[         a  nSSU< 3S S	 4s S nA$ S nAff = f)
Nr   s	   %PDF-1.4
T)mime)r
   zlibmagic (python-magic) OK)r   zCpython `magic` module not available (filetype fallback still works)r   zlibmagic not usable:    )magicfrom_bufferImportError	Exception)r3   _excs      r   _libmagic_statusr9   /   s\    	2m$7 2  ]\ =.sg6t<<<=s    
A	A
<AAc                ,    U(       a  SU  S34$ SU  S34$ )Nr
   z found on PATHr   z not found on PATHr   )nameon_paths     r   _tool_statusr=   <   s*    v^,,,0111r   c                    / nU R                    H&  n[        U5      (       a  M  UR                  U5        M(     [        U5      S:H  U4$ )zOReturn whether declared importable dependencies for `file_type` are importable.r   )r(   r	   appendlen)r#   r   mods      r   python_import_deps_okrB   B   sD    G88 %%NN3 9 w<1g%%r   c                   U R                   (       d  [        SU R                   S34S9$ [        U 5      u  p/ nU(       d/  UR	                  SSR                  U5       S[        U 5       35        [        U 5      (       a1  U(       a*  [        R                  " S5      c  SnUR	                  S5        U [        ;   a%  U(       a  [        5       c  SnUR	                  S	5        U R                  S
:X  aL  [        5       (       d  SnUR	                  S5        [        R                  " S5      c  SnUR	                  S5        [        U[        U5      S9$ )z<Check partitioning readiness for a single :class:`FileType`.F is not partitionable.r   r   zMissing Python module(s): , z. Install with: pandoczrPandoc executable not found on PATH (required by pypandoc). Install pandoc from https://pandoc.org/installing.htmlzhsoffice (LibreOffice CLI) not found on PATH. Required to convert legacy .doc / .ppt to Open XML formats.audiozSMissing audio extra (e.g. Whisper). Install with: pip install "unstructured[audio]"ffmpegz\ffmpeg not on PATH - required for Whisper audio decoding (https://ffmpeg.org/download.html).)is_partitionabler   r;   rB   r?   joinr%   r)   shutilwhichr   _libreoffice_on_pathr"   r/   tuple)r#   r
   r   r   s       r   evaluate_file_type_capabilityrP   K   sB   %%"((>?A
 	

 (	2KBH(7);(< =4Y?@B	

 Y''B6<<3I3QE	

 //B;O;Q;YJ	
 w&%''BOOB <<!)BOO6
 "uX??r   c                 .    [         R                  " S5      $ )zWReturn ``soffice`` on PATH; matches :func:`convert_office_doc` in ``partition.common``.soffice)rL   rM   r   r   r   rN   rN   {   s    <<	""r   c                   U R                  5       nU(       d  [        S5      eUR                  5       nUS:X  a;  [         Vs/ s H)  o3R                  (       d  M  UR
                  S:X  d  M'  UPM+     sn$ US:X  a;  [         Vs/ s H)  o3R                  (       d  M  UR
                  S:X  d  M'  UPM+     sn$ / n[         H  nUR                  (       d  M  UR                  R                  5       U:X  d  UR                  U:X  a  UR                  U5        MW  UR                  (       d  Mj  UR                  R                  5       U:X  d  M  UR                  U5        M     U(       d  [        [         Vs1 s H!  o3R                  (       d  M  UR                  iM#     sn[         Vs1 s H/  o3R                  (       d  M  UR                  R                  5       iM1     sn-  SS1-  5      nSR                  USS 5      n[        SU < SU S	35      eU Vs/ s H4  o3R                  U:X  d   UR                  R                  5       U:X  d  M2  UPM6     nnU=(       d    U$ s  snf s  snf s  snf s  snf s  snf )
zRMap a user string (e.g. ``pdf``, ``png``, ``image``) to :class:`FileType` members.zEmpty specifierimagerH   rF   N   zUnknown file type or alias z. Examples: z...)strip
ValueErrorlowerr   rJ   r"   r;   valuer?   partitioner_shortnamesortedrK   )specrawrX   ftmatchesvalidsampleexacts           r   resolve_specifierrc      s   
**,C*++IIKE%ZXr)<)<RYAYXZZ%ZXr)<)<RYAYXZZ G""77==?e#rxx5'8NN2###(@(@(F(F(HE(QNN2   (@",?,?XRXX@)1I25H5Hrww}}IJ !

 5":&6thl6(RUVWW "S'BXX%6"''--/U:RR'ESG3 [Z AI TsH   II+III,I0I#I#"I(
:I(
1I-I-c                  ^ [        U 5      m[        T5      S:  a3  TS   R                  S;   a   [        U4S jT 5       5      (       a  TS   /mSn/ nT HU  n[	        U5      nUR
                  (       d  SnUR                   H$  nUR                  SUR                   SU 35        M&     MW     [        5       n/ nU H,  nXV;  d  M
  UR                  U5        UR                  U5        M.     [        U[        U5      S	9$ )
zKCombine evaluation for all file types matched by :func:`resolve_specifier`.   r   )rT   rH   c              3  Z   >#    U  H   oR                   TS    R                   :H  v   M"     g7f)r   Nr!   ).0ttargetss     r   	<genexpr>%evaluate_specifier.<locals>.<genexpr>   s"     Gw!
 5 55ws   (+TF[z] rE   )rc   r@   r"   allrP   r   r   r?   r;   setaddr   rO   )	r\   combined_readyall_messagesr^   resultmseendedupedri   s	           @r   evaluate_specifierrv      s    %GGqAJ!!%77GwGGG1:,N L.r2||"NA!BGG9Bqc 23 !	  UDG=HHQKNN1  .5>JJr   c                 r    SS[         R                  " 5       4SS[         R                   " 5       4SS[        4/$ )z9Rows for the environment section: (name, status, detail).Pythonr
   Platformunstructured)platformpython_versionr   r   r   r   environment_rowsr}      s>     
40023	T8,,./	{+ r   c                 2   / n [        5       u  pU R                  SX45        S H<  u  p4[        U[        R                  " U5      SL5      u  pVU R                  X5U45        M>     [        5       nU R                  SU(       a  SOSU(       a  SU 3OS45        U $ )	zRows for optional system tools.zlibmagic (MIME detection)))ztesseract (OCR)	tesseract)rG   rG   )zffmpeg (audio/codecs)rI   Nzsoffice (LibreOffice CLI)r
   r   zfound: znot found on PATH)r9   r?   r=   rL   rM   rN   )rowsstdetaillabelcmdstatusmsglos           r   system_tool_rowsr      s    *,D!#JBKK,b9:

 #5&,,s*;4*GHUC() 
	BKK'DI gbTN&9	
 Kr   c                 L   / n [        S [         5       S S9 H  n[        U5      u  p#U(       a  SOSnUR                  =(       d    Sn[	        U5      nUR
                  (       a  SR                  UR
                  5      OSnU R                  UR                  XEU45        M     U $ )zAOne row per partitionable file type: type, deps OK, extra, notes.c              3  J   #    U  H  oR                   (       d  M  Uv   M     g 7fN)rJ   )rg   rs   s     r   rj   /partitionable_file_type_rows.<locals>.<genexpr>   s     3Hq 2 2Hs   #	#c                    U R                   $ r   )r;   )xs    r   <lambda>.partitionable_file_type_rows.<locals>.<lambda>   s    affr   )keyyesno- | )	r[   r   rB   r"   rP   r   rK   r?   r;   )outr^   py_ok_missing	deps_cellr$   capnotess           r   partitionable_file_type_rowsr      s    +-C3H3 03"E	$+B/,/LL

3<<(c

BGGYu56 Jr   c                  ^ ^
^ U(       d  SR                  T 5      S-   $ T  Vs/ s H  n[        U5      PM     snm/ nU H_  nU Vs/ s H  n[        U5      PM     snm
UR                  T
5        [	        T
5       H   u  pg[        TU   [        U5      5      TU'   M"     Ma     SR                  S T 5       5      nSR                  UU 4S j[        [        T 5      5       5       5      U/n	U H@  m
U	R                  SR                  U
U4S j[        [        T 5      5       5       5      5        MB     SR                  U	5      S-   $ s  snf s  snf )z8Render a simple fixed-width table (no third-party deps).r   z
(no rows)
z-+-c              3  ,   #    U  H
  nS U-  v   M     g7f)r   Nr   )rg   ws     r   rj   format_table.<locals>.<genexpr>   s     1jS1Wjs   c              3  R   >#    U  H  nTU   R                  TU   5      v   M     g 7fr   ljust)rg   i
col_widthsheaderss     r   rj   r      s)     P<Oq71:##JqM22<O   $'c              3  R   >#    U  H  nTU   R                  TU   5      v   M     g 7fr   r   )rg   r   cellsr   s     r   rj   r     s'     [GZ!az!} = =GZr   
)rK   r@   strr?   	enumeratemaxrange)r   r   hstr_rowsrowcr   cellseplinesr   r   s   `         @@r   format_tabler      s   zz'"_44")*'Q#a&'*J "H!$%AQ% 'GA
1s4y9JqM ( 
 **1j1
1C

PE#g,<OPPE UZZ[uSQX\GZ[[\ 99Ud"" + &s   EE	c                    / n U R                  S5        U R                  [        S[        5       5      5        U R                  S5        [        5       nU R                  [        SU5      5        U R                  S5        [	        5       nU R                  [        SU Vs/ s H  n[        U5      PM     sn5      5        SR                  U 5      $ s  snf )zIFull diagnostic report for :command:`unstructured doctor` with no filter.zEnvironment
)	ComponentStatusDetailz,System tools (optional but commonly needed)
)Toolr   r   z)Partitionable file types (Python extras)
)z	File typezPython deps OKz	pip extraNotes )r?   r   r}   r   r   rO   rK   )partssys_rowsp_rowsrs       r   build_reportr     s    E	LL!	LL?AQASTU	LL@A!H	LL:HEF	LL=>)+F	LLA%&v!U1Xv&	
 775> 's   Cc                   [        U 5      nUR                  5       (       d  [        SSU 34S9$ SSKJn  U" [        UR                  5       5      S9nUR                  (       d  [        SSUR                   S34S9$ [        U5      $ )	z6Infer file type from ``path`` and evaluate capability.FzNot a file or not found: rE   r   )detect_filetype)	file_pathzDetected type rD   )
r   is_filer    unstructured.file_utils.filetyper   r   resolverJ   r;   rP   )pathpr   r^   s       r   file_path_to_capabilityr     s    T
A99;;e9RSTRU7V6XYY@	3qyy{#3	4B&rwwi/EFH
 	
 ),,r   )r#   r   returnr   )r#   r   r   r   )r   r   )r   tuple[Status, str])r;   r   r<   r   r   r   )r#   r   r   ztuple[bool, list[str]])r#   r   r   r   )r   z
str | None)r\   r   r   zlist[FileType])r\   r   r   r   )r   zlist[tuple[str, str, str]])r   zlist[tuple[str, Status, str]])r   zlist[tuple[str, str, str, str]])r   r   r   zlist[tuple[str, ...]]r   r   )r   r   )r   z
str | Pathr   r   )*r   
__future__r   importlib.utilr,   r{   rL   dataclassesr   pathlibr   typingr   unstructured.__version__r   unstructured.file_utils.modelr   unstructured.utilsr	   r   	frozensetDOCPPTr   r   r   r%   r)   r/   r9   r=   rB   rP   rN   rc   rv   r}   r   r   r   r   r   r   r   r   <module>r      s    X "    !   0 2 0	(	) 4=hllHLL=Y3Z 0 Z $= = =&C;
22&-@`#
!HK60 #**-r   