
    Mi6F                       % S r SSKJr  SSKrSSKrSSKrSSKJrJrJ	r	J
r
  SSKrSSKJr  SSKJrJr  SSKJrJr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SKJ r   SSK!J"r"  \	S\#\   4   r$S\%S'    SSSSS0 SS\ RL                  / SQSSSSSSSSSSSSSSS.                                                   SS jjjr'S0 SS4           SS jjr(        SS jr) " S S5      r*g) z9Provides partitioning with automatic file-type detection.    )annotationsN)IOAnyCallableOptional)	TypeAlias)DataSourceMetadataElement)detect_filetypeis_json_processableis_ndjson_processable)FileType)logger)UnsupportedFileFormatError)exactly_one)check_language_args)PartitionStrategy)dependency_exists.r   PartitionerT)pdfjpgpngheicF   )fileencodingcontent_typeurlheaders
ssl_verifyrequest_timeoutstrategyskip_infer_table_typesocr_languages	languagesdetect_language_per_elementlanguage_fallbackpdf_infer_table_structureextract_images_in_pdfextract_image_block_typesextract_image_block_output_dirextract_image_block_to_payloaddata_source_metadatametadata_filenamehi_res_model_name
model_namestarting_page_numberc               @  ^^^^$ [        XTS9  UR                  SU5        U(       a  [        R                  " S5        [	        U=(       d    / U
5      nTb  [        TTUUUS9u  nm$O)U0 :w  a  [        R                  " S5        [        U UUTUS9m$Ub  UR                  S5        UR                  S	S5      nUb  UO[        T$U	U5      n[        5       nSUUU$U4S
 jjnT$[        R                  :X  a9  UR                  T$5      nU" SU USUUUUUU=(       d    UUUUUUS.UD6nU" U5      $ T$R                  (       aI  T$R                  S:X  a9  UR                  T$5      nU" SU USUUUUUU=(       d    UUUUUUS.UD6nU" U5      $ T$[        R                  :X  a<  [!        XS9(       d  [#        S5      eUR                  T$5      n U " SXS.UD6nU" U5      $ T$[        R$                  :X  a<  ['        XS9(       d  [#        S5      eUR                  T$5      n!U!" SXS.UD6nU" U5      $ T$[        R(                  :X  a  / $ [*        R,                  " U5      n"UU"S'   UU"S'   UU"S'   UU"S	'   UU"S'   UU"S'   UU"S'   UU"S'   UU"S'   UR                  T$5      n#U#" SXS.U"D6nU" U5      $ )a  Partitions a document into its constituent elements.

Uses libmagic to determine the file's type and route it to the appropriate partitioning
function. Applies the default parameters for each partitioning function. Use the document-type
specific partitioning functions if you need access to additional kwarg options.

Parameters
----------
filename
    A string defining the target filename path.
file
    A file-like object using "rb" mode --> open(filename, "rb").
encoding
    The character-encoding used to decode the input bytes when drawn from `filename` or `file`.
    Defaults to "utf-8".
url
    The url for a remote document. Pass in content_type if you want partition to treat
    the document as a specific content_type.
headers
    The headers to be used in conjunction with the HTTP request if URL is set.
ssl_verify
    If the URL parameter is set, determines whether or not partition uses SSL verification
    in the HTTP request.
request_timeout
    The timeout for the HTTP request if URL is set. Defaults to None meaning no timeout and
    requests will block indefinitely.
content_type
    A string defining the file content in MIME type
metadata_filename
    When file is not None, the filename (string) to store in element metadata. E.g. "foo.txt"
strategy
    The strategy to use for partitioning PDF/image. Uses a layout detection model if set
    to 'hi_res', otherwise partition simply extracts the text from the document
    and processes it.
skip_infer_table_types
    The document types that you want to skip table extraction with.
languages
    The languages present in the document, for use in partitioning and/or OCR. For partitioning
    image or pdf documents with Tesseract, you'll first need to install the appropriate
    Tesseract language pack. For other partitions, language is detected using naive Bayesian
    filter via `langdetect`. Multiple languages indicates text could be in either language.
detect_language_per_element
    Detect language per element instead of at the document level.
language_fallback
    Optional callable for short text (e.g. when detection defaults to English).
    Called with the text; return a list of ISO 639-3 codes or None to leave
    language unspecified.
pdf_infer_table_structure
    Deprecated! Use `skip_infer_table_types` to opt out of table extraction for any document
    type.
    If True and strategy=hi_res, any Table Elements extracted from a PDF will include an
    additional metadata field, "text_as_html," where the value (string) is a just a
    transformation of the data into an HTML <table>.
    The "text" field for a partitioned Table Element is always present, whether True or False.
extract_images_in_pdf
    Only applicable if `strategy=hi_res`.
    If True, any detected images will be saved in the path specified by
    'extract_image_block_output_dir' or stored as base64 encoded data within metadata fields.
    Deprecation Note: This parameter is marked for deprecation. Future versions will use
    'extract_image_block_types' for broader extraction capabilities.
extract_image_block_types
    Only applicable if `strategy=hi_res`.
    Images of the element type(s) specified in this list (e.g., ["Image", "Table"]) will be
    saved in the path specified by 'extract_image_block_output_dir' or stored as base64
    encoded data within metadata fields.
extract_image_block_to_payload
    Only applicable if `strategy=hi_res`.
    If True, images of the element type(s) defined in 'extract_image_block_types' will be
    encoded as base64 data and stored in two metadata fields: 'image_base64' and
    'image_mime_type'.
    This parameter facilitates the inclusion of element data directly within the payload,
    especially for web-based applications or APIs.
extract_image_block_output_dir
    Only applicable if `strategy=hi_res` and `extract_image_block_to_payload=False`.
    The filesystem path for saving images of the element type(s)
    specified in 'extract_image_block_types'.
hi_res_model_name
    The layout detection model used when partitioning strategy is set to `hi_res`.
model_name
    The layout detection model used when partitioning strategy is set to `hi_res`. To be
    deprecated in favor of `hi_res_model_name`.
starting_page_number
    Indicates what page number should be assigned to the first page in the document.
    This information will be reflected in elements' metadata and can be be especially
    useful when partitioning a document that is part of a larger document.
)r   filenamer   r.   z]The pdf_infer_table_structure kwarg is deprecated. Please use skip_infer_table_types instead.N)r   r   r   r    r!   zUThe headers kwarg is set but the url kwarg is not. The headers kwarg will be ignored.)	file_pathr   r   r   metadata_file_pathr   infer_table_structurec                  > U  H  nTUR                   l        TUR                   l        Tb<  [        R                  " T5      nU(       a  UR
                  OSUR                   l        Md  TR
                  UR                   l        M     U $ )z)Add some metadata fields to each element.N)metadatar   data_sourcer   from_mime_type	mime_typefiletype)elementselementout_filetyper   r-   	file_typer   s      u/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/auto.pyaugment_metadata#partition.<locals>.augment_metadata   ss    G#&G +?G(''66|DFRL,B,BX\  ),5,?,?  )       )r3   r   r   r6   r"   r%   r&   r'   r/   r)   r*   r+   r,   r1   image)r3   r   zDetected a JSON file that does not conform to the Unstructured schema. partition_json currently only processes serialized Unstructured output.zDetected an NDJSON file that does not conform to the Unstructured schema. partition_json currently only processes serialized Unstructured output.r&   r'   r   r%   r1   r"   r*   r,   )r=   list[Element]returnrF    )r   
setdefaultr   warningr   file_and_type_from_urlr   seekpopdecide_table_extraction_PartitionerLoaderr   PDFgetpartitioner_shortnameJSONr   
ValueErrorNDJSONr   EMPTYcopydeepcopy)%r3   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   kwargskwargs_infer_table_structurer6   partitioner_loaderrB   partition_pdfr=   partition_imagepartition_jsonpartition_ndjsonpartitioning_kwargs	partitionr@   s%      ``              `                @rA   ra   ra      sV   d T#6
)+<= 	

 $IO]CI
0%!+
i b=NN5 $%0
	 		! $*::.Et#L  (3 	%$"%
  ,-  HLL *..y9  
"7(C//=:"7&?+I+I!5
 
"  ))&&9+J+Jg+U,00;" 
"7(C//=:"7&?+I+I!5
 
"  )) HMM!"H@Z  ,//	:!I8I&I))HOO#$hBZ  .11)<#KXKFK)) HNN"	 --/9T56/@+,&.
#3H/0'0$2F./&.
#7P34<Z89"&&y1IM(M9LMHH%%rD   c                V   [         R                  " XX4S9n[        R                  " UR                  5      nU=(       d    UR
                  R                  SS 5      =n(       a0  UR                  S5      S   R                  5       R                  5       nUR                  n[        XgUS9nXh4$ )N)r   verifytimeoutzContent-Type;r   )r   r   r   )requestsrQ   ioBytesIOcontentr   splitstriplowerr   r   )	r   r   r   r    r!   responser   r   r<   s	            rA   rK   rK   /  s     ||C]H::h&&'D#Qx'7'7';';ND'QQ|Q#))#.q1779??A   HD,WH>rD   c                v    U (       a  U R                   R                  5       OS nUS:X  a  U=(       d    X1;  $ X1;  $ )Nr   )namerl   )r<   r#   r(   doc_types       rA   rN   rN   C  s;    
 )1x}}""$dH5
 )RH,RR11rD   c                  <    \ rS rSr% Sr0 rS\S'   S	S jrS	S jrSr	g)
rO   iT  a  Provides uniform helpful error when a partitioner dependency is not installed.

Used by `partition()` to encapsulate coping with the possibility the Python environment it is
executing in may not have all dependencies installed for a particular partitioner.

Provides `.get()` to access partitioners by file-type, which raises when one or more
dependencies for that partitioner are not installed.

The error message indicates what extra needs to be installed to enable that partitioner. This
avoids an inconsistent variety of possibly puzzling exceptions arising from much deeper in the
partitioner when access to the missing dependency is first attempted.
zdict[FileType, Partitioner]_partitionersc                    UR                   (       d  [        SU S35      eXR                  ;  a  U R                  U5      U R                  U'   U R                  U   $ )zReturn partitioner for `file_type`.

Raises when one or more package dependencies for that file-type have not been
installed. Also raises when the file-type is not partitionable.
z&Partitioning is not supported for the z file type.)is_partitionabler   rr   _load_partitioner)selfr@   s     rA   rQ   _PartitionerLoader.gete  s`     )),8;O  ...,0,B,B9,MDy)!!),,rD   c                "   UR                    H8  n[        U5      (       a  M  [        UR                   SUR                   S35      e   UR
                  (       d   e[        R                  " UR                  5      n[        X1R                  5      $ )zBLoad the partitioner for `file_type` after verifying dependencies.zg() is not available because one or more dependencies are not installed. Use: pip install "unstructured[z:]" (including quotes) to install the required dependencies)
importable_package_dependenciesr   ImportErrorpartitioner_function_name
extra_namert   	importlibimport_modulepartitioner_module_qnamegetattr)rv   r@   pkg_namepartitioner_modules       rA   ru   $_PartitionerLoader._load_partitionerw  s     "AAH$X..! ::; <22;2F2F1G H<=  B ))))&44Y5W5WX)+N+NOOrD   rH   N)r@   r   rG   r   )
__name__
__module____qualname____firstlineno____doc__rr   __annotations__rQ   ru   __static_attributes__rH   rD   rA   rO   rO   T  s     24M.3-$PrD   rO   )N)4r3   Optional[str]r   zOptional[IO[bytes]]r   r   r   r   r   r   r   dict[str, str]r    boolr!   Optional[int]r"   strr#   	list[str]r$   r   r%   Optional[list[str]]r&   r   r'   z.Optional[Callable[[str], Optional[list[str]]]]r(   r   r)   r   r*   r   r+   r   r,   r   r-   zOptional[DataSourceMetadata]r.   r   r/   r   r0   r   r1   intrY   r   rG   rF   )r   r   r   r   r   r   r    r   r!   r   rG   ztuple[io.BytesIO, FileType])r<   zOptional[FileType]r#   r   r(   r   rG   r   )+r   
__future__r   rW   r}   rg   typingr   r   r   r   rf   typing_extensionsr   unstructured.documents.elementsr	   r
    unstructured.file_utils.filetyper   r   r   unstructured.file_utils.modelr   unstructured.loggerr   unstructured.partition.commonr   $unstructured.partition.common.commonr   "unstructured.partition.common.langr   &unstructured.partition.utils.constantsr   unstructured.utilsr   listr   r   AUTOra   rK   rN   rO   rH   rD   rA   <module>r      sX   ? "   	 . .  ' G 
 3 & D < B D 0!#tG}"45Y 5 #N& !%""& %)%**(E#'%)(-HL&+"'5948+09='+'+ $ !3N&N& N& 	N&
  N& 
N& N& N& #N& N& &N& !N& #N& "&N& FN&   $!N&"  #N&$  3%N&& %2'N&( %))N&* 7+N&, %-N&. %/N&0 1N&2 3N&4 5N&6 7N&f #' %)	  	
 # !(2 2%2  $2 
	2"2P 2PrD   