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


Python mimetypes.types_map方法代码示例

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


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

示例1: get_string

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def get_string(self):
        """ Get file format as string

        :return: String describing the file format
        :rtype: str
        """
        if self is MimeType.TAR:
            return 'application/x-tar'
        if self is MimeType.JSON:
            return 'application/json'
        if self in [MimeType.TIFF_d8, MimeType.TIFF_d16, MimeType.TIFF_d32f]:
            return 'image/{}'.format(self.value)
        if self is MimeType.JP2:
            return 'image/jpeg2000'
        if self is MimeType.RAW:
            return self.value
        return mimetypes.types_map['.' + self.value] 
开发者ID:sentinel-hub,项目名称:sentinelhub-py,代码行数:19,代码来源:constants.py

示例2: process

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def process(self, mtree, options=None):
        """guess the file type now (will be useful later)
        """
        filetype, other = self.guess_filetype(mtree, options)

        mtree.guess.set('type', filetype, confidence=1.0)
        log_found_guess(mtree.guess)

        filetype_info = Guess(other, confidence=1.0)
        # guess the mimetype of the filename
        # TODO: handle other mimetypes not found on the default type_maps
        # mimetypes.types_map['.srt']='text/subtitle'
        mime, _ = mimetypes.guess_type(mtree.string, strict=False)
        if mime is not None:
            filetype_info.update({'mimetype': mime}, confidence=1.0)

        node_ext = mtree.node_at((-1,))
        found_guess(node_ext, filetype_info)

        if mtree.guess.get('type') in [None, 'unknown']:
            if options.get('name_only'):
                mtree.guess.set('type', 'movie', confidence=0.6)
            else:
                raise TransformerException(__name__, 'Unknown file type') 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:26,代码来源:guess_filetype.py

示例3: _setup_mimetypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [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: extensions

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def extensions(self):
        """
        Map content types to file extensions
        Skip parts without extensions
        """
        exts = set([os.path.splitext(part.PartName)[-1] for part in self.Override])
        return [(ext[1:], mimetypes.types_map[ext]) for ext in sorted(exts) if ext] 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:manifest.py

示例5: _register_mimetypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def _register_mimetypes(self, filenames):
        """
        Make sure that the mime type for all file extensions is registered
        """
        for fn in filenames:
            ext = os.path.splitext(fn)[-1]
            if not ext:
                continue
            mime = mimetypes.types_map[ext]
            fe = FileExtension(ext[1:], mime)
            self.Default.append(fe) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:13,代码来源:manifest.py

示例6: _mimetype

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def _mimetype(self):
        _, extension = path.splitext(self.filename)
        if extension == '':
            extension = '.txt'
        mimetypes.init()
        try:
            return mimetypes.types_map[extension]
        except KeyError:
            return 'plain/text' 
开发者ID:NullArray,项目名称:Archivist,代码行数:11,代码来源:base.py

示例7: loadMimeTypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def loadMimeTypes(mimetype_locations=None, init=mimetypes.init):
    """
    Produces a mapping of extensions (with leading dot) to MIME types.

    It does this by calling the C{init} function of the L{mimetypes} module.
    This will have the side effect of modifying the global MIME types cache
    in that module.

    Multiple file locations containing mime-types can be passed as a list.
    The files will be sourced in that order, overriding mime-types from the
    files sourced beforehand, but only if a new entry explicitly overrides
    the current entry.

    @param mimetype_locations: Optional. List of paths to C{mime.types} style
        files that should be used.
    @type mimetype_locations: iterable of paths or L{None}
    @param init: The init function to call. Defaults to the global C{init}
        function of the C{mimetypes} module. For internal use (testing) only.
    @type init: callable
    """
    init(mimetype_locations)
    mimetypes.types_map.update(
        {
            '.conf':  'text/plain',
            '.diff':  'text/plain',
            '.flac':  'audio/x-flac',
            '.java':  'text/plain',
            '.oz':    'text/x-oz',
            '.swf':   'application/x-shockwave-flash',
            '.wml':   'text/vnd.wap.wml',
            '.xul':   'application/vnd.mozilla.xul+xml',
            '.patch': 'text/plain'
        }
    )
    return mimetypes.types_map 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:37,代码来源:static.py

示例8: loadMimeTypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def loadMimeTypes(mimetype_locations=['/etc/mime.types']):
    """
    Multiple file locations containing mime-types can be passed as a list.
    The files will be sourced in that order, overriding mime-types from the
    files sourced beforehand, but only if a new entry explicitly overrides
    the current entry.
    """
    import mimetypes
    # Grab Python's built-in mimetypes dictionary.
    contentTypes = mimetypes.types_map  # @UndefinedVariable
    # Update Python's semi-erroneous dictionary with a few of the
    # usual suspects.
    contentTypes.update(
        {
            '.conf': 'text/plain',
            '.diff': 'text/plain',
            '.exe': 'application/x-executable',
            '.flac': 'audio/x-flac',
            '.java': 'text/plain',
            '.ogg': 'application/ogg',
            '.oz': 'text/x-oz',
            '.swf': 'application/x-shockwave-flash',
            '.tgz': 'application/x-gtar',
            '.wml': 'text/vnd.wap.wml',
            '.xul': 'application/vnd.mozilla.xul+xml',
            '.py': 'text/plain',
            '.patch': 'text/plain',
        }
    )
    # Users can override these mime-types by loading them out configuration
    # files (this defaults to ['/etc/mime.types']).
    for location in mimetype_locations:
        if os.path.exists(location):
            contentTypes.update(mimetypes.read_mime_types(location))

    return contentTypes 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:38,代码来源:util.py

示例9: get_extension

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [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

示例10: _embed_css_resources

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def _embed_css_resources(css, types=('.png',)):
    """ Replace urls in css with data urls
    """
    type_str = '|'.join('\%s' % t for t in types)
    rx = re.compile('(url\s*\(\s*(.*(%s))\s*\))' % type_str)
    found = rx.findall(css)
    for match, item, ext in found:
        data = base64.b64encode(_get_data(item)).decode()
        mime = mimetypes.types_map[ext]
        repl = 'url(data:%s;base64,%s)' % (mime, data)
        css = css.replace(match, repl)
    return css 
开发者ID:flexxui,项目名称:flexx,代码行数:14,代码来源:leaflet.py

示例11: editItemInfo

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def editItemInfo(self, itemInfo, thumbnailFile=None):
        """Edits the itemInfo for service.
        
        Args:
            itemInfo: JSON itemInfo objet representing metadata.
            thumbnailFile: Path to optional thumbnail image, defaults to None.
        """

        query_url = self.url + '/iteminfo/edit'
        if thumbnailFile and os.path.exists(thumbnailFile):
            # use mimetypes to guess "content_type"
            import mimetypes
            known = mimetypes.types_map
            common = mimetypes.common_types
            ext = os.path.splitext(thumbnailFile)[-1].lower()
            content_type = 'image/jpg'
            if ext in known:
                content_type = known[ext]
            elif ext in common:
                content_type = common[ext]

            # make multi-part encoded file
            files = {'thumbnail': (os.path.basename(thumbnailFile), open(thumbnailFile, 'rb'), content_type)}
        else:
            files = ''

        params = {'serviceItemInfo': json.dumps(itemInfo) if isinstance(itemInfo, dict) else itemInfo,
                  'token': self.token.token if isinstance(self.token, Token) else self.token,
                  'f': 'json'}

        return requests.post(query_url, params, files=files, verify=False).json() 
开发者ID:Bolton-and-Menk-GIS,项目名称:restapi,代码行数:33,代码来源:__init__.py

示例12: loadMimeTypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def loadMimeTypes(mimetype_locations=['/etc/mime.types']):
    """
    Multiple file locations containing mime-types can be passed as a list.
    The files will be sourced in that order, overriding mime-types from the
    files sourced beforehand, but only if a new entry explicitly overrides
    the current entry.
    """
    import mimetypes
    # Grab Python's built-in mimetypes dictionary.
    contentTypes = mimetypes.types_map
    # Update Python's semi-erroneous dictionary with a few of the
    # usual suspects.
    contentTypes.update(
        {
            '.conf':  'text/plain',
            '.diff':  'text/plain',
            '.exe':   'application/x-executable',
            '.flac':  'audio/x-flac',
            '.java':  'text/plain',
            '.ogg':   'application/ogg',
            '.oz':    'text/x-oz',
            '.swf':   'application/x-shockwave-flash',
            '.tgz':   'application/x-gtar',
            '.wml':   'text/vnd.wap.wml',
            '.xul':   'application/vnd.mozilla.xul+xml',
            '.py':    'text/plain',
            '.patch': 'text/plain',
        }
    )
    # Users can override these mime-types by loading them out configuration
    # files (this defaults to ['/etc/mime.types']).
    for location in mimetype_locations:
        if os.path.exists(location):
            more = mimetypes.read_mime_types(location)
            if more is not None:
                contentTypes.update(more)

    return contentTypes 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:40,代码来源:static.py

示例13: loadMimeTypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def loadMimeTypes(mimetype_locations=['/etc/mime.types']):
    """
    Multiple file locations containing mime-types can be passed as a list.
    The files will be sourced in that order, overriding mime-types from the
    files sourced beforehand, but only if a new entry explicitly overrides
    the current entry.
    """
    import mimetypes
    # Grab Python's built-in mimetypes dictionary.
    contentTypes = mimetypes.types_map
    # Update Python's semi-erroneous dictionary with a few of the
    # usual suspects.
    contentTypes.update(
        {
            '.conf':  'text/plain',
            '.diff':  'text/plain',
            '.exe':   'application/x-executable',
            '.flac':  'audio/x-flac',
            '.java':  'text/plain',
            '.ogg':   'application/ogg',
            '.oz':    'text/x-oz',
            '.swf':   'application/x-shockwave-flash',
            '.tgz':   'application/x-gtar',
            '.wml':   'text/vnd.wap.wml',
            '.xul':   'application/vnd.mozilla.xul+xml',
            '.py':    'text/plain',
            '.patch': 'text/plain',
        }
    )
    # Users can override these mime-types by loading them out configuration
    # files (this defaults to ['/etc/mime.types']).
    for location in mimetype_locations:
        if os.path.exists(location):
            more = mimetypes.read_mime_types(location)
            if more is not None:
                contentTypes.update(more)
            
    return contentTypes 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:40,代码来源:static.py

示例14: get_file

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import types_map [as 别名]
def get_file(file_path):
    mimetypes.init()
    return (path.basename(file_path), open(path.abspath(file_path), 'rb'),
            mimetypes.types_map[path.splitext(file_path)[1]]) 
开发者ID:mister-monster,项目名称:YouTube2PeerTube,代码行数:6,代码来源:youtube2peertube.py


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