本文整理汇总了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;未经允许,请勿转载。 |
请发表评论