Python mimetypes.add_type() Examples

The following are 15 code examples of mimetypes.add_type(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mimetypes , or try the search function .
Example #1
Source File: server.py    From olapy with GNU Lesser General Public License v2.1 6 votes vote down vote up
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] 
Example #2
Source File: server.py    From olapy with GNU Lesser General Public License v2.1 6 votes vote down vote up
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] 
Example #3
Source File: program.py    From tensorboard with Apache License 2.0 6 votes vote down vote up
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") 
Example #4
Source File: gltf.py    From verge3d-blender-addon with GNU General Public License v3.0 5 votes vote down vote up
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' 
Example #5
Source File: plugin.py    From daf-recipes with GNU General Public License v3.0 5 votes vote down vote up
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') 
Example #6
Source File: __init__.py    From bdbag with Apache License 2.0 5 votes vote down vote up
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])) 
Example #7
Source File: hvcs.py    From python-semantic-release with MIT License 5 votes vote down vote up
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") 
Example #8
Source File: OPKHelper.py    From PyMenu with GNU General Public License v3.0 5 votes vote down vote up
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") 
Example #9
Source File: plugin.py    From indico-plugins with MIT License 5 votes vote down vote up
def register_custom_mimetypes():
    mimetypes.add_type(b'text/x-csharp', b'.cs') 
Example #10
Source File: plugin.py    From indico-plugins with MIT License 5 votes vote down vote up
def register_custom_mimetypes():
    mimetypes.add_type(b'application/x-ipynb+json', b'.ipynb') 
Example #11
Source File: startup.py    From ANALYSE with GNU Affero General Public License v3.0 5 votes vote down vote up
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') 
Example #12
Source File: augment_mimetypes.py    From python-compat-runtime with Apache License 2.0 5 votes vote down vote up
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') 
Example #13
Source File: file.py    From PeekabooAV with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, sample):
        self.sample = sample

        if not mimetypes.inited:
            mimetypes.init()
            mimetypes.add_type('application/javascript', '.jse') 
Example #14
Source File: PostProcessor.py    From WebTrap with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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]) 
Example #15
Source File: warcit.py    From warcit with Apache License 2.0 5 votes vote down vote up
def _init_mimes(self):
        # add any custom, fixed mime types here
        mimetypes.add_type('image/x-icon', '.ico', True)