flickr_cli.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Flickr3 作者: chew-z 项目源码 文件源码
def valid_img(f):
    """
    Is this a valid image that we can use to upload?

    :param f: str that indicates the file directory.
    :return: boolean
    """
    if not os.path.isfile(f) :
        return False
    if re.search(r'\.(jpg|gif|png|tiff|mp4|mp2|avi|wmv|mov|m4v)$', f, flags=re.IGNORECASE):
        return True
    try:
        file_type = imghdr.what(f)
        supported_types = ['jpeg', 'gif', 'png']
        if file_type in supported_types:
            return True
    except AttributeError as e:
        # You probably passed something that is not a path.
        logging.warning(e)
    except IOError as e:
        # You passed a path that does not exist, or you do not have access to it.
        logging.warning(e)
    return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号