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

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

项目:Simple-File-Server    作者:RDCH106    | 项目源码 | 文件源码
def read_config():
    global settings
    global extensions_map
    exist = os.path.isfile(setting_file_name)
    if not exist:
        print 'Creating config file...'
        shutil.copyfile(default_setting_file_name, setting_file_name)
        print 'Edit config.json and launch the script again.'
        sys.exit()

    with open(setting_file_name) as data_file:
        settings = json.load(data_file)

        ####################################################################
        #Load default mimetypes and update them with config.json extensions#
        ####################################################################
        if not mimetypes.inited:
            mimetypes.init()  # try to read system mime.types
        extensions_map = mimetypes.types_map.copy()
        extensions_map.update({
            '': 'application/octet-stream'  # Default
        })
        extensions_map.update(settings['extensions'])  # Read extensions from config.json
        #####################################################################
    return
项目: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
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
def test_usesGlobalInitFunction(self):
        """
        By default, C{mimetypes.init} is called.
        """
        # Checking mimetypes.inited doesn't always work, because
        # something, somewhere, calls mimetypes.init. Yay global
        # mutable state :)
        if _PY3:
            signature = inspect.signature(static.loadMimeTypes)
            self.assertIs(signature.parameters["init"].default,
                          mimetypes.init)
        else:
            args, _, _, defaults = inspect.getargspec(static.loadMimeTypes)
            defaultInit = defaults[args.index("init")]
            self.assertIs(defaultInit, mimetypes.init)