
    h(                        S SK r S SKrS SKrS SKrS SKJr  S SKr\R                  " \5      r	\" \
5      R                  R                  S-  r " S S\R                  5      rS\4S jrS\S\4S jr/ S	QrS
\4S jrS rS rS rg)    N)Pathlibc                   J   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	rU =r$ )
_LazyImporter   zLazily import module/extension.c                 >   > [         TU ]  U5        X l        S U l        g N)super__init__import_funcmodule)selfnamer   	__class__s      N/var/www/auris/envauris/lib/python3.13/site-packages/torio/_extension/utils.pyr   _LazyImporter.__init__   s    &    c                 N    U R                  5         [        U R                  U5      $ r	   )_import_oncegetattrr   )r   items     r   __getattr___LazyImporter.__getattr__   s    t{{D))r   c                     U R                   c4  SU R                   SU R                  R                   SU R                   S3$ [        U R                   5      $ )Nz	<module '.z("z")'>)r   
__module__r   __name__r   reprr   s    r   __repr___LazyImporter.__repr__   sK    ;;t/q1H1H0ITYYKW\]]DKK  r   c                 L    U R                  5         [        U R                  5      $ r	   )r   dirr   r   s    r   __dir___LazyImporter.__dir__!   s    4;;r   c                     U R                   cE  U R                  5       U l         U R                  R                  U R                   R                  5        g g r	   )r   r   __dict__updater   s    r   r   _LazyImporter._import_once%   s?    ;;**,DK
 MM  !5!56 r   c                 F     U R                  5         g! [         a     gf = f)NFT)r   	Exceptionr   s    r   is_available_LazyImporter.is_available.   s,    	   		s    
  )r   r   )r   r   __qualname____firstlineno____doc__r   r   r    r$   r   r,   __static_attributes____classcell__)r   s   @r   r   r      s)    )*!
 7 r   r   c                 R    [         R                  S:X  a  SOSn[        U  SU 3-  nU$ )Nntpydsor   )osr   _LIB_DIR)r   suffixpaths      r   _get_lib_pathr;   6   s-    ggoU4FQvh''DKr   returnc                     [        U 5      nUR                  5       (       d  g[        R                  R	                  U5        g)a  Load extension module

Note:
    In case `torio` is deployed with `pex` format, the library file
    is not in a standard location.
    In this case, we expect that `libtorio` is available somewhere
    in the search path of dynamic loading mechanism, so that importing
    `_torio` will have library loader find and load `libtorio`.
    This is the reason why the function should not raising an error when the library
    file is not found.

Returns:
    bool:
        True if the library file is found AND the library loaded without failure.
        False if the library file is not found (like in the case where torio
        is deployed with pex format, thus the shared library file is
        in a non-standard location.).
        If the library file is found but there is an issue loading the library,
        (such as missing dependency) then this function raises the exception as-is.

Raises:
    Exception:
        If the library file is found, but there is an issue loading the library file,
        (when underlying `ctype.DLL` throws an exception), this function will pass
        the exception as-is, instead of catching it and returning bool.
        The expected case is `OSError` thrown by `ctype.DLL` when a dynamic dependency
        is not found.
        This behavior was chosen because the expected failure case is not recoverable.
        If a dependency is missing, then users have to install it.
FT)r;   existstorchopsload_library)r   r:   s     r   	_load_librB   <   s1    > D;;==	II4 r   )654 versionc                     SU  3nSU  3n[         R                  R                  U5      (       d  [        SU  S35      e[	        U5        [         R
                  " U5      $ )Nztorio.lib._torio_ffmpeglibtorio_ffmpegFFmpegz extension is not available.)	importlibutil	find_specRuntimeErrorrB   import_module)rG   extr   s      r   !_find_versionsed_ffmpeg_extensionrQ   e   s\    #G9
-CG9
%C>>##C((VG9,HIJJcN""3''r   c                     U  H=  n[         R                  SU5         [        U5      n[         R                  SU5        Us  $    [	        SU  S35      e! [         a    [         R                  SUSS9   Mr  f = f)NzLoading FFmpeg%szSuccessfully loaded FFmpeg%sz"Failed to load FFmpeg%s extension.T)exc_infoz6Failed to intialize FFmpeg extension. Tried versions: z;. Enable DEBUG logging to see more details about the error.)_LGdebugrQ   r+   ImportError)ffmpeg_vers
ffmpeg_verrP   s      r   _find_ffmpeg_extensionrY   p   s    !
		$j1	3J?CII4jAJ " 
@ ND 	D   	II:JQUIV	s   "AA65A6c                      [         n [        R                  R                  S5      =nb  X;  a  [	        SU SU  35      eU/n U $ )NTORIO_USE_FFMPEG_VERSIONzThe FFmpeg version 'z[' (read from TORIO_USE_FFMPEG_VERSION) is not one of supported values. Possible values are )_FFMPEG_VERSr7   environget
ValueError)rW   rX   s     r   _get_ffmpeg_versionsr`      sZ    Kjjnn%?@@
M(&zl 3GGRmU  "lr   c                      [        5       n [        U 5      nUR                  5         UR                  5       S:  a  UR	                  S5        U$ )N   )r`   rY   initget_log_levelset_log_level)rW   rP   s     r   _init_ffmpegrf      sA    &(K
 
-CHHJ
Q!Jr   )rK   loggingr7   typespathlibr   r?   	getLoggerr   rT   __file__parentr8   
ModuleTyper   strr;   boolrB   r\   rQ   rY   r`   rf    r   r   <module>rq      s      	   !>  ''%/&E$$ &Rs #3 #4 #L #(s ( 
r   