当前位置: 首页>>代码示例>>Python>>正文


Python mimetypes.inited方法代码示例

本文整理汇总了Python中mimetypes.inited方法的典型用法代码示例。如果您正苦于以下问题:Python mimetypes.inited方法的具体用法?Python mimetypes.inited怎么用?Python mimetypes.inited使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mimetypes的用法示例。


在下文中一共展示了mimetypes.inited方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getFileExtensions

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def getFileExtensions(mime):
    if(not mimetypes.inited):
        mimetypes.init()
        initKnowMimetypes()

    types = mime.split(";")

    result = []

    for t in types:
        if(t):
            res = mimetypes.guess_all_extensions(t)
            #print("getting extensions for mime " + str(t) + " " + str(res))
            result.extend(res)

    if(len(result) == 0):
        result.append(".*")
        
    return result 
开发者ID:JackD83,项目名称:PyMenu,代码行数:21,代码来源:OPKHelper.py

示例2: upload_fake_file

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def upload_fake_file():
    if not request.files:
        return "", 401

    if not mimetypes.inited:
        mimetypes.init()

    for key, item in request.files.items():
        if item.filename:
            filetype = ".{}".format(item.filename.split(".")[-1])
            if filetype in mimetypes.suffix_map:
                if not item.content_type:
                    return "", 400

    # Try to download each of the files downloaded to /tmp and
    # then remove them
    for key in request.files:
        file_to_save = request.files[key]
        path = os.path.join("/tmp", file_to_save.filename)
        file_to_save.save(path)

    return "", 200 
开发者ID:taverntesting,项目名称:tavern,代码行数:24,代码来源:server.py

示例3: _setup_mimetypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def _setup_mimetypes():
    """Pre-initialize global mimetype map."""
    if not mimetypes.inited:
        mimetypes.init()
    mimetypes.types_map['.dwg'] = 'image/x-dwg'
    mimetypes.types_map['.ico'] = 'image/x-icon'
    mimetypes.types_map['.bz2'] = 'application/x-bzip2'
    mimetypes.types_map['.gz'] = 'application/x-gzip' 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:10,代码来源:static.py

示例4: guess_mime_type

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def guess_mime_type(filename):
  """Guess mime type based of file extension."""
  if not mimetypes.inited:
    mimetypes.init()

  return mimetypes.guess_type(filename)[0] 
开发者ID:google,项目名称:clusterfuzz,代码行数:8,代码来源:http_server.py

示例5: test_usesGlobalInitFunction

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:test_static.py

示例6: test_usesGlobalInitFunction

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
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 getattr(inspect, "signature", None):
            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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:17,代码来源:test_static.py

示例7: get_extension

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def get_extension(mime_type):
    """ Returns a valid filename extension (recognized by python) for a given mime type.

    Args:
        mime_type (`str`): The mime type for which to find an extension

    Returns:
        `str`: A file extension used for the given mimetype
    """
    if not mimetypes.inited:
        mimetypes.init()
    for ext in mimetypes.types_map:
        if mimetypes.types_map[ext] == mime_type:
            return ext 
开发者ID:Cimbali,项目名称:pympress,代码行数:16,代码来源:document.py

示例8: __init__

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def __init__(self, sample):
        self.sample = sample

        if not mimetypes.inited:
            mimetypes.init()
            mimetypes.add_type('application/javascript', '.jse') 
开发者ID:scVENUS,项目名称:PeekabooAV,代码行数:8,代码来源:file.py

示例9: upload_fake_file_and_data

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def upload_fake_file_and_data():
    if not request.files:
        return "", 401

    if not request.form.to_dict():
        return "", 402

    # Verify that the content type is `multipart`
    if not request.content_type.startswith("multipart/form-data"):
        return "", 403

    if not mimetypes.inited:
        mimetypes.init()

    for key, item in request.files.items():
        if item.filename:
            filetype = ".{}".format(item.filename.split(".")[-1])
            if filetype in mimetypes.suffix_map:
                if not item.content_type:
                    return "", 400

    # Try to download each of the files downloaded to /tmp
    for key in request.files:
        file_to_save = request.files[key]
        path = os.path.join("/tmp", file_to_save.filename)
        file_to_save.save(path)

    return "", 200 
开发者ID:taverntesting,项目名称:tavern,代码行数:30,代码来源:server.py

示例10: _get_file_arguments

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import inited [as 别名]
def _get_file_arguments(request_args, stack):
    """Get corect arguments for anything that should be passed as a file to
    requests

    Args:
        stack (ExitStack): context stack to add file objects to so they're
            closed correctly after use

    Returns:
        dict: mapping of {"files": ...} to pass directly to requests
    """

    files_to_send = {}

    for key, filespec in request_args.get("files", {}).items():
        if not mimetypes.inited:
            mimetypes.init()

        filepath, content_type, encoding = _read_filespec(filespec)

        filename = os.path.basename(filepath)

        # a 2-tuple ('filename', fileobj)
        file_spec = [filename, stack.enter_context(open(filepath, "rb"))]

        # Try to guess as well, but don't override what the user specified
        guessed_content_type, guessed_encoding = mimetypes.guess_type(filepath)
        content_type = content_type or guessed_content_type
        encoding = encoding or guessed_encoding

        # If it doesn't have a mimetype, or can't guess it, don't
        # send the content type for the file
        if content_type:
            # a 3-tuple ('filename', fileobj, 'content_type')
            logger.debug("content_type for '%s' = '%s'", filename, content_type)
            file_spec.append(content_type)
            if encoding:
                # or a 4-tuple ('filename', fileobj, 'content_type', custom_headers)
                logger.debug("encoding for '%s' = '%s'", filename, encoding)
                # encoding is None for no encoding or the name of the
                # program used to encode (e.g. compress or gzip). The
                # encoding is suitable for use as a Content-Encoding header.
                file_spec.append({"Content-Encoding": encoding})

        files_to_send[key] = tuple(file_spec)

    if files_to_send:
        return {"files": files_to_send}
    else:
        return {} 
开发者ID:taverntesting,项目名称:tavern,代码行数:52,代码来源:request.py


注:本文中的mimetypes.inited方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。