Python mimetypes 模块,add_type() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用mimetypes.add_type()

项目:hatch    作者:hatch-sh    | 项目源码 | 文件源码
def _upload_artifacts(self, bucket):
        mimetypes.add_type('application/json', '.map')
        mimetypes.add_type('application/woff2', '.woff2')
        for artifact in recursive_glob(self.config.path, '*'):
            mime_type = mimetypes.guess_type(artifact)

            if mime_type is None:
                logger.error('Unknown mime type for %s', artifact)
                sys.exit(1)

            [content_type, _] = mime_type

            if content_type is None:
                logger.error('Unknown content-type for %s', artifact)
                sys.exit(1)

            logger.debug('Uploading %s [%s]', artifact, content_type)
            file_path = artifact.replace('{}/'.format(self.config.path), '')
            bucket.upload_file(artifact, file_path, ExtraArgs={
                'ACL': 'public-read',
                'CacheControl': 'public, max-age=31536000, no-cache',
                'ContentType': content_type
            })
项目:scriptworker    作者:mozilla-releng    | 项目源码 | 文件源码
def _force_mimetypes_to_plain_text():
    """Populate/Update the mime types database with supported extensions that we want to map to 'text/plain'.

    These extensions can then be open natively read by browsers once they're uploaded on S3. It doesn't affect artifacts
    once they're downloaded from S3.

    """
    for extension in _EXTENSIONS_TO_FORCE_TO_PLAIN_TEXT:
        mimetypes.add_type('text/plain', extension)
        log.debug('Extension "{}" forced to text/plain'.format(extension))
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
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')
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
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')
项目:dati-ckan-docker    作者:italia    | 项目源码 | 文件源码
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')
项目:PeekabooAV    作者:scVENUS    | 项目源码 | 文件源码
def guess_mime_type_from_filename(file_path):
    """ Guess the type of a file based on its filename or URL. """
    if not mimetypes.inited:
        mimetypes.init()
        mimetypes.add_type('application/javascript', '.jse')

    mt = mimetypes.guess_type(file_path)[0]
    if mt:
        return mt
项目:fg21sim    作者:liweitianux    | 项目源码 | 文件源码
def get_content_type(self):
        """
        Returns the ``Content-Type`` header to be used for this request.
        """
        # Add MIME types support used here
        mimetypes.add_type("application/fits", ".fits")
        mimetypes.add_type("text/plain", ".conf")
        return super().get_content_type()
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
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')
项目:Deploy_XXNET_Server    作者:jzp820927    | 项目源码 | 文件源码
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')
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
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')