當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。