
    Mi5                    h   S SK J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  S SKJr  S SKJr  S S	KJr  S S
KJrJr  SrSrSrSrSr            S                           SS jjr              SS jr       S                 SS jjr g)    )annotationsN)IOAnyOptionalSequence)UnstructuredClient)
operationsshared)retries)Element)logger)exactly_one)elements_from_dictselements_from_jsoni  i
 g      ?i@w Tc           	        [        XS9  U(       a  U(       a  [        S5      eUb  Un[        R                  " S5        SU;   a  USS OUn[	        X]S9nU b9  [        U S5       n[        R                  " UR                  5       U S	9nSSS5        O%Ub"  Uc  [        S
5      e[        R                  " X&S	9n[        R                  " [        R                  " SSW0UD6S9n[        UU	UU
UUS9nUR                  R                  UUS9nUR                  S:X  a  [!        UR"                  R$                  S9$ [        SUR                   S35      e! , (       d  f       N= f)a  Partitions a document using the Unstructured REST API. This is equivalent to
running the document through partition.

See https://api.unstructured.io/general/docs for the hosted API documentation or
https://github.com/Unstructured-IO/unstructured-api for instructions on how to run
the API locally as a container.

Parameters
----------
filename
    A string defining the target filename path.
content_type
    A string defining the file content in MIME type
file
    A file-like object using "rb" mode --> open(filename, "rb").
metadata_filename
    When file is not None, the filename (string) to store in element metadata. E.g. "foo.txt"
api_url
    The URL for the Unstructured API. Defaults to the hosted Unstructured API.
api_key
    The API key to pass to the Unstructured API.
retries_initial_interval
    Defines the time interval (in seconds) to wait before the first retry in case of a request
    failure. Defaults to 3000. If set should be > 0.
retries_max_interval
    Defines the maximum time interval (in seconds) to wait between retries (the interval
    between retries is increased as using exponential increase algorithm
    - this setting limits it). Defaults to 720000. If set should be > 0.
retries_exponent
    Defines the exponential factor to increase the interval between retries. Defaults to 1.5.
    If set should be > 0.0.
retries_max_elapsed_time
    Defines the maximum time (in seconds) to wait for retries. If exceeded, the original
    exception is raised. Defaults to 1800000. If set should be > 0.
retries_connection_errors
    Defines whether to retry on connection errors. Defaults to True.
request_kwargs
    Additional parameters to pass to the data field of the request to the Unstructured API.
    For example the `strategy` parameter.
)filenamefilezOnly one of metadata_filename and file_filename is specified. metadata_filename is preferred. file_filename is marked for deprecation.NzuThe file_filename kwarg will be deprecated in a future version of unstructured. Please use metadata_filename instead.z/general/v0/generali)api_key_auth
server_urlrb)content	file_namezWIf file is specified in partition_via_api, metadata_filename must be specified as well.files)partition_parameters)retries_connection_errorsretries_exponentretries_initial_intervalretries_max_elapsed_timeretries_max_intervalsdk)requestr      )textReceive unexpected status code  from the API. )r   
ValueErrorr   warningr   openr
   Filesreadr	   PartitionRequestPartitionParametersget_retries_configgeneral	partitionstatus_coder   raw_responser#   )r   content_typer   file_filenameapi_urlapi_keymetadata_filenamer   r   r   r   r   request_kwargsbase_urlr    fr   reqretries_configresponses                       t/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/api.pypartition_via_apir?      s~   n -]W
 	

  )4	
 !6 @wt}gH
'
GC(D!QLL"E "! 
	$?  TG

%
%#77VeV~VC (";)!9!91N {{$$ % H
 s"!x'<'<'A'ABB-h.B.B-C>R
 	
G "!s   #$E
Ec           	       ^
 SnUR                   R                  m
[        S UUUUU 4 5       5      (       a  SU
4S jjnT
(       a  T
R                  b  T
R                  O[        n[
        R                  " U=(       d    U" S[        5      U=(       d    U" S[        5      U=(       d    U" S[        5      U=(       d    U" S[        5      S9n	[
        R                  " S	U	U b  U OUS
9nU$ )a  Constructs a RetryConfig object from the provided parameters. If any of the parameters
are None, the default values are taken from the SDK configuration or the default constants.

If all parameters are None, returns None (and the SDK-managed defaults are used within the
client)

The solution is not perfect as the RetryConfig object does not include the defaults by
itself so we might need to construct it basing on our defaults.

Parameters
----------
retries_connection_errors
    Defines whether to retry on connection errors. If not set the
    DEFAULT_RETRIES_CONNECTION_ERRORS constant is used.
retries_exponent
    Defines the exponential factor to increase the interval between retries.
    If set, should be > 0.0 (otherwise the DEFAULT_RETRIES_EXPONENT constant is used)
retries_initial_interval
    Defines the time interval to wait before the first retry in case of a request failure.
    If set, should be > 0 (otherwise the DEFAULT_RETRIES_INITIAL_INTERVAL_SEC constant is used)
retries_max_elapsed_time
    Defines the maximum time to wait for retries. If exceeded, the original exception is raised.
    If set, should be > 0 (otherwise the DEFAULT_RETRIES_MAX_ELAPSED_TIME_SEC constant is used)
retries_max_interval
    Defines the maximum time interval to wait between retries. If set, should be > 0
    (otherwise the DEFAULT_RETRIES_MAX_INTERVAL_SEC constant is used)
sdk
    The UnstructuredClient object to take the default values from.
Nc              3  *   #    U  H	  nUS Lv   M     g 7fNr&   ).0settings     r>   	<genexpr>%get_retries_config.<locals>.<genexpr>   s       	
G 	t
s   c                T   > T(       a  [        TR                  U 5      =n(       a  U$ U$ rB   )getattrbackoff)setting_namedefault_valuesetting_valuesdk_default_retries_configs      r>   get_backoff_default/get_retries_config.<locals>.get_backoff_default   s,    )$+,F,N,NP\$]]=]((      initial_intervalmax_intervalexponentmax_elapsed_time)rQ   rR   rS   rT   rI   )strategyrI   retry_connection_errors)rJ   strrK   r   returnr   )sdk_configurationretry_configanyrV   !DEFAULT_RETRIES_CONNECTION_ERRORSr   BackoffStrategy$DEFAULT_RETRIES_INITIAL_INTERVAL_SEC DEFAULT_RETRIES_MAX_INTERVAL_SECDEFAULT_RETRIES_EXPONENT$DEFAULT_RETRIES_MAX_ELAPSED_TIME_SECRetryConfig)r   r   r   r   r   r    r<   rN   "default_retries_connneciton_errorsbackoff_strategyrM   s             @r>   r.   r.      s   J N!$!6!6!C!C
 	 % $%
	 	 		! **BBN '>> 3	 	+ #22( a&'9;_` % Y&~7WX !]$7
D\$] ) a&'9;_`
" !,,$ -8 *7
 rP   c           
        SUS.nU(       a  U(       a  [        S5      eUb  Un[        R                  " S5        U b  U(       a#  [        U5      [        U 5      :w  a  [        S5      e[        R
                  " 5        n	U  V
s/ s H  oR                  [        U
S5      5      PM     nn
/ n[        U5       H'  u  pX   nUb  X   OSnUR                  SXU445        M)     [        R                  " UUUUS	9nSSS5        OUb  U(       a#  [        U5      [        U5      :w  a  [        S
5      eU(       d  [        S5      e[        U5      [        U5      :w  a  [        S5      e/ n[        U5       H)  u  nnUb  X   OSnXl   nUR                  SUUU445        M+     [        R                  " UUUUS	9nWR                  S:X  aR  / nUR                  5       n[        US   [        5      (       d  U/nU H  nUR                  [!        U5      5        M     U$ [        SUR                   S35      es  sn
f ! , (       d  f       N= f)a  Partitions multiple documents using the Unstructured REST API by batching
the documents into a single HTTP request.

See https://api.unstructured.io/general/docs for the hosted API documentation or
https://github.com/Unstructured-IO/unstructured-api for instructions on how to run
the API locally as a container.

Parameters
----------
filenames
    A list of strings defining the target filename paths.
content_types
    A list of strings defining the file contents in MIME types.
files
    A list of file-like object using "rb" mode --> open(filename, "rb").
metadata_filename
    When file is not None, the filename (string) to store in element metadata. E.g. "foo.txt"
api_url
    The URL for the Unstructured API. Defaults to the hosted Unstructured API.
api_key
    The API key to pass to the Unstructured API.
request_kwargs
    Additional parameters to pass to the data field of the request to the Unstructured API.
    For example the `strategy` parameter.
zapplication/json)ACCEPTzUNSTRUCTURED-API-KEYzOnly one of metadata_filenames and file_filenames is specified. metadata_filenames is preferred. file_filenames is marked for deprecation.NzwThe file_filenames kwarg will be deprecated in a future version of unstructured. Please use metadata_filenames instead.z6content_types and filenames must have the same length.r   r   )headersdatar   z2content_types and files must have the same length.z8metadata_filenames must be specified if files are passedz7metadata_filenames and files must have the same length.r"   r   r$   r%   )r'   r   r(   len
contextlib	ExitStackenter_contextr)   	enumerateappendrequestspostr1   json
isinstancelistr   )	filenamescontent_typesr   file_filenamesr5   r6   metadata_filenamesr8   rg   stackr:   _filesir   r   r3   r=   _file	documentsresponse_listdocuments                        r>   partition_multiple_via_apir      sP   H % 'G
 nY
 	

 !+5	

 S/3y>AUVV!!#uAJKA((a7EKF$U+$<3@3L}/RVw(FGH ,
  }}#	H $#  
	S/3u:=QRR!WXX#$E
2VWW!%(HAu/</H=+dL),HMM7Xul$CDE )
 ==	
 s"	  -*D11*OM%H0:; &-h.B.B-C>R
 	
c L $#s   <H2$H-%AH2-H22
I )NNNN.https://api.unstructured.io/general/v0/general NNNNNN)r   Optional[str]r3   r   r   zOptional[IO[bytes]]r4   r   r5   rW   r6   rW   r7   r   r   z[int]r   Optional[int]r   Optional[float]r   r   r   Optional[bool]r8   r   rX   zlist[Element])r   r   r   r   r   r   r   r   r   r   r    r   rX   zOptional[retries.RetryConfig])NNNNr   r   N)rt   Optional[list[str]]ru   r   r   zOptional[Sequence[IO[bytes]]]rv   r   r5   rW   r6   rW   rw   r   r8   r   rX   zlist[list[Element]])!
__future__r   rj   typingr   r   r   r   ro   unstructured_clientr   unstructured_client.modelsr	   r
   unstructured_client.utilsr   unstructured.documents.elementsr   unstructured.loggerr   $unstructured.partition.common.commonr   unstructured.staging.baser   r   r^   r_   r`   ra   r\   r?   r.   r   r&   rP   r>   <module>r      s   "  . .  2 9 - 3 & < M (, $#)   '. $$( ! #"& $#'C'+&**.(,.204q
q
q
 q
 !	q

 q
 q
 %q
 $q
 (q
 &q
 ,q
  .q
 q
 q
hY-Y%Y ,Y ,	Y
 (Y 
Y #Yz &*)-+/*.C.2m
"m
&m
 )m
 (	m

 m
 m
 ,m
 m
 m
rP   