
    pim                         d dl Zd dlZd dlZd dlmZmZ d dlmZ d Z	de
defdZde
fdZg Zdd	e
d
ee
   defdZdd	e
d
ee
   defdZdZdZ eedd      ZefdZedfdZ eee      Z eedd      Zd Zd Zy)    N)partialwraps)Optionalc           	          | t         j                  vr|S t         j                  j                  | d      }g d}g d}||v ry||vrt        d|  d| d||z          y)	z-Check if environment varable has True-y value0)1trueTRUEonONyesYES)r   falseFALSEoffOFFnoNOTz'Unexpected environment variable value `=z`. Expected one of F)osenvirongetRuntimeError)vardefaultvaltruesfalsess        c/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/torchaudio/_internal/module_utils.pyeval_envr       sw    
"**
**..c
"C;E>F
e|
&5cU!C5 A$v~.01 	1     modulesreturnc                  &    t        d | D              S )aP  Returns if a top-level module with :attr:`name` exists *without**
    importing it. This is generally safer than try-catch block around a
    `import X`. It avoids third party libraries breaking assumptions of some of
    our tests, e.g., setting multiprocessing start method when imported
    (see librosa/#747, torchvision/#544).
    c              3   ^   K   | ]%  }t         j                  j                  |      d u ' y wN)	importlibutil	find_spec).0ms     r   	<genexpr>z&is_module_available.<locals>.<genexpr>"   s$     H1y~~''*$6Hs   +-)all)r"   s    r   is_module_availabler.      s     HHHHr!   c                      | D cg c]  }t        |      r| }}|sd }|S t        |      dk(  rd|d    nd| fd}|S c c}w )zDecorate function to give error message if invoked without required optional modules.

    This decorator is to give better error message to users rather
    than raising ``NameError:  name 'module' is not defined`` at random places.
    c                     | S r&    funcs    r   	decoratorz"requires_module.<locals>.decorator/   s    Kr!      zmodule: r   z	modules: c                 2     t                fd       }|S )Nc                  R    t        j                   dj                   d       )N.z
 requires r   
__module____name__)argskwargsr3   reqs     r   wrappedz3requires_module.<locals>.decorator.<locals>.wrapped6   s*    "doo%6ajQTPU#VWWr!   r   )r3   r?   r>   s   ` r   r4   z"requires_module.<locals>.decorator5   s"    4[X X Nr!   )r.   len)r"   r+   missingr4   r>   s       @r   requires_modulerC   %   si     "@Q)<Q)?q@G@	  *-W):%)G9@U	 # As
   AA	directionversionremovec                 >     t                fd       }|S )Nc                       d }r|ddndt              z    dz  }t        j                  |d        | i |S )Nz has been deprecated. z It will be removed from za futurezthe 
 release.    )
stacklevel)strwarningswarn)r<   r=   messagerD   r3   namerF   rE   s      r   r?   z wrap_deprecated.<locals>.wrappedC   s^    F0<2:V\_bcj_kVk2llvwwGg!,T$V$$r!   r@   )r3   rP   rD   rE   rF   r?   s   ````` r   wrap_deprecatedrQ   B   s     
4[% % Nr!   c                       fd}|S )zDecorator to add deprecation message

    Args:
        direction (str): Migration steps to be given to users.
        version (str or int): The version when the object will be removed
        remove (bool): If enabled, append future removal message.
    c                     t        | | j                   d| j                         }d}r|ddn dz  }d| d d	| j                   d
|_        |S )Nr8   rE   rF   z#This function has been deprecated. zIt will be removed from futurerI   z%DEPRECATED

    .. warning::

       z
       z

    
    )rQ   r:   r;   __doc__)r3   r?   rO   rD   rF   rE   s      r   r4   zdeprecated.<locals>.decoratorW   s    !$4??*;1T]]O(Liahqwx71go(SZ1[[effG 	y { 	\\N  r!   r1   )rD   rE   rF   r4   s   ``` r   
deprecatedrX   N   s    & r!   zThis deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. Please see https://github.com/pytorch/audio/issues/3902 for more information.a*  This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information.2.9TrT   c                     t        | j                  | j                   d| j                   |dd      | _        d| d| j                   d| _        t
        j                  |        | S )Nr8   rY   TrT   ztDEPRECATED

.. warning::

    This class is deprecated from version 2.8. It will be removed in the 2.9 release.
    
)rQ   __init__r:   r;   rW   UNSUPPORTEDappend)cmsgs     r   dropping_class_supportra   |   sl     ~Qqzzl-KSZ_hlmAJ
 	E 
 AI qHr!   c                 6    d| d| j                    d| _         | S )Nz[DEPRECATED]

.. warning::

    This object is deprecated deprecated from version 2.8. It will be removed in the 2.9 release.
    r[   rV   )rW   )r_   r`   rP   s      r   dropping_const_supportrc      s1    
 	E 
 AI Hr!   )r`   c                       fd}|S )zLGenerate decorator to give users message about missing TorchAudio extension.c                 2     t                fd       }|S )Nc                  R    t        j                   dj                   d       )Nr8    r9   )r<   r=   r3   rO   s     r   r?   z5fail_with_message.<locals>.decorator.<locals>.wrapped   s(    $//!2!DMM?!G9MNNr!   r@   )r3   r?   rO   s   ` r   r4   z$fail_with_message.<locals>.decorator   s"    	t	O 
	O r!   r1   )rO   r4   s   ` r   fail_with_messagerh      s     r!   c                     | S )zlOp-op decorator. Used in place of fail_with_message when a functionality that requires extension works fine.r1   r2   s    r   no_oprj      s    Kr!   )NF)importlib.utilr'   r   rM   	functoolsr   r   typingr   r    rL   boolr.   rC   r]   rQ   rX   DEPRECATION_MSGIO_DEPRECATION_MSGdropping_supportra   rc   dropping_class_io_supportdropping_io_supportrh   rj   r1   r!   r   <module>rt      s     	  $ &I# I$ Ic 4 	3 	# 	W[ 	#  d @T T  ouTJ  #2  #2 	 $$:@RS  !3U4P 
r!   