U
    ,:%e                     @   s   d dl Zd dlZd dlZd dlmZ d dlmZ dd Ze	e
dddZe	d	d
dZde	ee	 e
dddZdd Zdd ZdS )    Nwraps)Optionalc                 C   sv   | t jkr|S t j| d}dddddddg}dd	d
ddddg}||krLdS ||krrtd|  d| d||  dS )z-Check if environment varable has True-y value01trueTRUEonONyesZYESfalseFALSEoffZOFFnoNOTz'Unexpected environment variable value `=z`. Expected one of F)osenvirongetRuntimeError)vardefaultvalZtruesZfalses r   `/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torchaudio/_internal/module_utils.pyeval_env   s    
r   )modulesreturnc                  G   s   t d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                 s   s   | ]}t j|d k	V  qd S N)	importlibutil	find_spec.0mr   r   r   	<genexpr>"   s     z&is_module_available.<locals>.<genexpr>)allr   r   r   r   is_module_available   s    r(   r'   c                     sP   dd | D }|sdd }n0t |dkr6d|d  nd|   fd	d}|S )
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   s   g | ]}t |s|qS r   )r(   r"   r   r   r   
<listcomp>+   s      z#requires_module.<locals>.<listcomp>c                 S   s   | S r   r   funcr   r   r   	decorator/   s    z"requires_module.<locals>.decorator   zmodule: r   z	modules: c                    s   t   fdd}|S )Nc                     s    t  j d j d d S )N.z
 requires r   
__module____name__argskwargs)r+   reqr   r   wrapped6   s    z3requires_module.<locals>.decorator.<locals>.wrappedr   r+   r6   r5   r*   r   r,   5   s    )len)r   missingr,   r   r8   r   requires_module%   s    
$r;   F)	directionversionremovec                    s    fd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                    s^   t   fdd}d}r>|dd kr2dn d7 }d j d| d	 d
|_|S )Nc                     sP   j  dj d  }r8|dd kr,dn d7 }tj|dd | |S )Nr.   z has been deprecated. z It will be removed from future
 release.    )
stacklevel)r0   r1   warningswarn)r3   r4   message)r<   r+   r>   r=   r   r   r6   I   s
    z.deprecated.<locals>.decorator.<locals>.wrappedz#This function has been deprecated. zIt will be removed from r?   r@   zDEPRECATED: z

    .. warning::

       z
       z	
        )r   __doc__)r+   r6   rE   r<   r>   r=   r*   r   r,   H   s    

zdeprecated.<locals>.decoratorr   )r<   r=   r>   r,   r   rG   r   
deprecated?   s    	rH   c                    s    fdd}|S )zLGenerate decorator to give users message about missing TorchAudio extension.c                    s   t   fdd}|S )Nc                     s    t  j d j d d S )Nr.    r/   r2   )r+   rE   r   r   r6   f   s    z5fail_with_message.<locals>.decorator.<locals>.wrappedr   r7   rE   r*   r   r,   e   s    z$fail_with_message.<locals>.decoratorr   )rE   r,   r   rJ   r   fail_with_messageb   s    rK   c                 C   s   | S )zlOp-op decorator. Used in place of fail_with_message when a functionality that requires extension works fine.r   r*   r   r   r   no_opo   s    rL   )NF)importlib.utilr   r   rC   	functoolsr   typingr   r   strboolr(   r;   rH   rK   rL   r   r   r   r   <module>   s   
#