• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mimetype.get_mimetype函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中website.util.mimetype.get_mimetype函数的典型用法代码示例。如果您正苦于以下问题:Python get_mimetype函数的具体用法?Python get_mimetype怎么用?Python get_mimetype使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_mimetype函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_unknown_extension_with_python_contents_results_in_python_mimetype

 def test_unknown_extension_with_python_contents_results_in_python_mimetype(self):
     name = 'test.thisisnotarealextensionidonotcarwhatyousay'
     python_file = os.path.join(HERE, 'test_utils.py')
     with open(python_file, 'r') as the_file:
         content = the_file.read()
     mimetype = get_mimetype(name, content)
     assert_equal('text/x-python', mimetype)
开发者ID:XTech2K,项目名称:osf.io,代码行数:7,代码来源:test_utils.py


示例2: github_download_file

def github_download_file(**kwargs):

    node_settings = kwargs['node_addon']

    path = get_path(kwargs)

    ref = request.args.get('sha')
    connection = GitHub.from_settings(node_settings.user_settings)

    try:
        name, data, _ = connection.file(
            node_settings.user, node_settings.repo, path, ref=ref
        )
    except TooBigError:
        raise HTTPError(
            http.BAD_REQUEST,
            data={
                'message_short': 'File too large',
                'message_long': 'This file is too large to download through '
                'the GitHub API.',
            },
        )
    if data is None:
        raise HTTPError(http.NOT_FOUND)

    # Build response
    resp = make_response(data)
    mimetype = get_mimetype(path, data)
    # Add binary MIME type if mimetype not found
    if mimetype is None:
        resp.headers['Content-Type'] = 'application/octet-stream'
    else:
        resp.headers['Content-Type'] = mimetype

    resp.headers['Content-Disposition'] = 'attachment; filename={0}'.format(
        name)

    return resp
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:38,代码来源:crud.py


示例3: test_unknown_extension_with_real_file_results_in_python_mimetype

 def test_unknown_extension_with_real_file_results_in_python_mimetype(self):
     name = 'test_views.notarealfileextension'
     maybe_python_file = os.path.join(HERE, 'test_files', name)
     mimetype = get_mimetype(maybe_python_file)
     assert_equal('text/x-python', mimetype)
开发者ID:XTech2K,项目名称:osf.io,代码行数:5,代码来源:test_utils.py


示例4: test_unknown_extension_with_no_contents_not_real_file_results_in_exception2

 def test_unknown_extension_with_no_contents_not_real_file_results_in_exception2(self):
     name = 'test.thisisnotarealextensionidonotcarwhatyousay'
     mime_type = get_mimetype(name)
     assert_equal(None, mime_type)
开发者ID:XTech2K,项目名称:osf.io,代码行数:4,代码来源:test_utils.py


示例5: test_unknown_extension_with_no_contents_not_real_file_results_in_exception

 def test_unknown_extension_with_no_contents_not_real_file_results_in_exception(self):
     name = 'test.thisisnotarealextensionidonotcarwhatyousay'
     with assert_raises(IOError):
         get_mimetype(name)
开发者ID:XTech2K,项目名称:osf.io,代码行数:4,代码来源:test_utils.py


示例6: test_get_markdown_mimetype_from_filename

 def test_get_markdown_mimetype_from_filename(self):
     name = 'test.md'
     mimetype = get_mimetype(name)
     assert_equal('text/x-markdown', mimetype)
开发者ID:XTech2K,项目名称:osf.io,代码行数:4,代码来源:test_utils.py



注:本文中的website.util.mimetype.get_mimetype函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python paths.resolve_addon_path函数代码示例发布时间:2022-05-26
下一篇:
Python util.web_url_for函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap