o
    *Î®cJ  ã                   @   sZ   d dl mZ ddlmZ ddlmZmZ eZdd„ Zdd„ Zd	d
„ Zddd„Z	dd„ Z
dS )é    )Úabsolute_importé   ©Úmatch)ÚTYPESÚTypec                 C   s   | rt | ƒS dS )a\  
    Infers the type of the given input.

    Function is overloaded to accept multiple types in input
    and peform the needed type inference based on it.

    Args:
        obj: path to file, bytes or bytearray.

    Returns:
        The matched type instance. Otherwise None.

    Raises:
        TypeError: if obj is not a supported type.
    Nr   )Úobj© r	   ú8/tmp/pip-target-vg8gfxp4/lib/python/filetype/filetype.pyÚguess   s   r   c                 C   ó   t | ƒ}|r	|jS |S )a  
    Infers the file type of the given input
    and returns its MIME type.

    Args:
        obj: path to file, bytes or bytearray.

    Returns:
        The matched MIME type as string. Otherwise None.

    Raises:
        TypeError: if obj is not a supported type.
    )r   Úmime©r   Úkindr	   r	   r
   Ú
guess_mime   ó   r   c                 C   r   )a  
    Infers the file type of the given input
    and returns its RFC file extension.

    Args:
        obj: path to file, bytes or bytearray.

    Returns:
        The matched file extension as string. Otherwise None.

    Raises:
        TypeError: if obj is not a supported type.
    )r   Ú	extensionr   r	   r	   r
   Úguess_extension1   r   r   Nc                 C   s*   t D ]}|j|ks|j| kr|  S qdS )a  
    Returns the file type instance searching by
    MIME type or file extension.

    Args:
        ext: file extension string. E.g: jpg, png, mp4, mp3
        mime: MIME string. E.g: image/jpeg, video/mpeg

    Returns:
        The matched file type instance. Otherwise None.
    N)Útypesr   r   )r   Úextr   r	   r	   r
   Úget_typeC   s
   ÿr   c                 C   s"   t | tƒs	tdƒ‚t d| ¡ dS )z“
    Adds a new type matcher instance to the supported types.

    Args:
        instance: Type inherited instance.

    Returns:
        None
    z.instance must inherit from filetype.types.Typer   N)Ú
isinstancer   Ú	TypeErrorr   Úinsert)Úinstancer	   r	   r
   Úadd_typeU   s   

r   )NN)Ú
__future__r   r   r   r   r   r   r   r   r   r   r	   r	   r	   r
   Ú<module>   s   
