def guess_file_type ( kind , filepath = None , youtube_id = None , web_url = None , encoding = None ) : if youtube_id : return FileTypes . YOUTUBE_VIDEO_FILE elif web_url : return FileTypes . WEB_VIDEO_FILE elif encoding : return FileTypes . BASE64_FILE else : ext = os . path . splitext ( filepath ) [ 1 ] [ 1 : ] . lower ( ) if kind in FILE_TYPE_MAPPING and ext in FILE_TYPE_MAPPING [ kind ] : return FILE_TYPE_MAPPING [ kind ] [ ext ] return None
python file chooser restrict file types
guess_file_class : determines what file the content is Args : filepath ( str ) : filepath of file to check Returns : string indicating file s class
def guess_file_type(kind, filepath=None, youtube_id=None, web_url=None, encoding=None):
    """ guess_file_class: determines what file the content is
        Args:
            filepath (str): filepath of file to check
        Returns: string indicating file's class
    """
    if youtube_id:
        return FileTypes.YOUTUBE_VIDEO_FILE
    elif web_url:
        return FileTypes.WEB_VIDEO_FILE
    elif encoding:
        return FileTypes.BASE64_FILE
    else:
        ext = os.path.splitext(filepath)[1][1:].lower()
        if kind in FILE_TYPE_MAPPING and ext in FILE_TYPE_MAPPING[kind]:
            return FILE_TYPE_MAPPING[kind][ext]
    return None