我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用mimetypes.add_type()。
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 })
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))
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')
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')
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
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()