python类inited()的实例源码

simple_file_server.py 文件源码 项目:Simple-File-Server 作者: RDCH106 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
files.py 文件源码 项目:PeekabooAV 作者: scVENUS 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
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
test_static.py 文件源码 项目:zenchmarks 作者: squeaky-pl 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号