本文整理匯總了Python中mimetypes.add_type方法的典型用法代碼示例。如果您正苦於以下問題:Python mimetypes.add_type方法的具體用法?Python mimetypes.add_type怎麽用?Python mimetypes.add_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mimetypes
的用法示例。
在下文中一共展示了mimetypes.add_type方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: app
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def app(environ, start_response):
path_info = environ["PATH_INFO"]
mimetypes.add_type('application/wasm', '.wasm')
mimetypes.add_type('text/html', '.data')
if path_info == '/':
path_info = "/olapy.html"
resource = "_build" + path_info
headers = []
headers.append(("Content-Type", mimetypes.guess_type(path_info.split("/")[-1])[0]))
headers.append(('Access-Control-Allow-Origin', '*'))
with open(resource, "rb") as f:
resp_file = f.read()
start_response("200 OK", headers)
return [resp_file]
示例2: _fix_mime_types
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def _fix_mime_types(self):
"""Fix incorrect entries in the `mimetypes` registry.
On Windows, the Python standard library's `mimetypes` reads in
mappings from file extension to MIME type from the Windows
registry. Other applications can and do write incorrect values
to this registry, which causes `mimetypes.guess_type` to return
incorrect values, which causes TensorBoard to fail to render on
the frontend.
This method hard-codes the correct mappings for certain MIME
types that are known to be either used by TensorBoard or
problematic in general.
"""
# Known to be problematic when Visual Studio is installed:
# <https://github.com/tensorflow/tensorboard/issues/3120>
mimetypes.add_type("application/javascript", ".js")
# Not known to be problematic, but used by TensorBoard:
mimetypes.add_type("font/woff2", ".woff2")
mimetypes.add_type("text/html", ".html")
示例3: register_custom_mimetypes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def register_custom_mimetypes():
mimetypes.add_type(b'application/x-ipynb+json', b'.ipynb')
示例4: imageMimeType
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def imageMimeType(path):
# NOTE: add missing HDR mime type to python database
if sys.version_info < (3, 0):
mimetypes.add_type('image/vnd.radiance', '.hdr')
mime = mimetypes.guess_type(path)[0]
if mime in ['image/jpeg', 'image/bmp', 'image/vnd.radiance', 'image/png']:
return mime
else:
return 'image/png'
示例5: update_config
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def update_config(self, config):
''' Set up the resource library, public directory and
template directory for all the spatial extensions
'''
p.toolkit.add_public_directory(config, 'public')
p.toolkit.add_template_directory(config, 'templates')
p.toolkit.add_resource('public', 'ckanext-spatial')
# Add media types for common extensions not included in the mimetypes
# module
mimetypes.add_type('application/json', '.geojson')
mimetypes.add_type('application/gml+xml', '.gml')
示例6: add_mime_types
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def add_mime_types(types):
if not types:
return
for t in types.keys():
for e in types[t]:
mimetypes.add_type(type=t, ext=e if e.startswith(".") else "".join([".", e]))
示例7: _fix_mime_types
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def _fix_mime_types():
"""Fix incorrect entries in the `mimetypes` registry.
On Windows, the Python standard library's `mimetypes` reads in
mappings from file extension to MIME type from the Windows
registry. Other applications can and do write incorrect values
to this registry, which causes `mimetypes.guess_type` to return
incorrect values, which causes TensorBoard to fail to render on
the frontend.
This method hard-codes the correct mappings for certain MIME
types that are known to be either used by python-semantic-release or
problematic in general.
"""
mimetypes.add_type("text/markdown", ".md")
示例8: initKnowMimetypes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def initKnowMimetypes():
mimetypes.add_type("application/x-nes-rom", ".nes")
mimetypes.add_type("application/x-snes-rom", ".sfc")
mimetypes.add_type("application/x-gameboy-rom", ".gb")
mimetypes.add_type("application/x-gbc-rom", ".gbc")
mimetypes.add_type("application/x-genesis-rom" ,".md")
mimetypes.add_type("application/x-megadrive-rom", ".md")
mimetypes.add_type("application/x-genesis-rom" ,".32x")
mimetypes.add_type("application/x-megadrive-rom", ".32x")
mimetypes.add_type("application/x-sms-rom", ".sms")
mimetypes.add_type("application/x-cd-image", ".bin")
mimetypes.add_type("application/x-cd-image", ".chd")
mimetypes.add_type("application/x-cd-image", ".cue")
mimetypes.add_type("application/x-cd-image", ".pbp")
mimetypes.add_type("application/x-ms-dos-executable", ".exe")
mimetypes.add_type("application/x-ms-dos-executable", ".com")
mimetypes.add_type("application/x-ms-dos-program", ".exe")
mimetypes.add_type("application/x-ms-dos-program", ".com")
mimetypes.add_type("application/x-ms-dos-batch", ".bat")
mimetypes.add_type("application/x-gzip", ".zip")
mimetypes.add_type("application/gzip", ".zip")
示例9: register_custom_mimetypes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def register_custom_mimetypes():
mimetypes.add_type(b'text/x-csharp', b'.cs')
示例10: add_mimetypes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def add_mimetypes():
"""
Add extra mimetypes. Used in xblock_resource.
If you add a mimetype here, be sure to also add it in lms/startup.py.
"""
import mimetypes
mimetypes.add_type('application/vnd.ms-fontobject', '.eot')
mimetypes.add_type('application/x-font-opentype', '.otf')
mimetypes.add_type('application/x-font-ttf', '.ttf')
mimetypes.add_type('application/font-woff', '.woff')
示例11: init
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def init():
mimetypes.add_type('application/dart', '.dart')
mimetypes.add_type('text/css', '.gss')
mimetypes.add_type('text/html', '.ng')
mimetypes.add_type('application/x-font-ttf', '.ttf')
mimetypes.add_type('application/font-woff', '.woff')
mimetypes.add_type('application/font-woff2', '.woff2')
示例12: __init__
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def __init__(self, sample):
self.sample = sample
if not mimetypes.inited:
mimetypes.init()
mimetypes.add_type('application/javascript', '.jse')
示例13: _init_mimetypes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def _init_mimetypes(self):
mimetypes.init()
for missing_mime_type in self.MISSING_MIME_TYPES:
mimetypes.add_type(missing_mime_type, self.MISSING_MIME_TYPES[missing_mime_type])
示例14: _init_mimes
# 需要導入模塊: import mimetypes [as 別名]
# 或者: from mimetypes import add_type [as 別名]
def _init_mimes(self):
# add any custom, fixed mime types here
mimetypes.add_type('image/x-icon', '.ico', True)