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


Python mimetypes.MimeTypes方法代码示例

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


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

示例1: __init__

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def __init__(self,
                 local_directory,
                 view_name,
                 url_token='filename',
                 show_timestamp=False,
                 width=70):
        """
        Args:
            local_directory: The local file system path that will be served.
            view_name: The name of the app view that maps to the directory.
            url_token: The path will be inserted into this token in the URL.
            show_timestamp: Include the last accessed timestamp for each file.
            width: The page width to use when formatting timestamp strings.
        """
        self.local_directory = local_directory
        self.view_name = view_name
        self.url_token = url_token
        self.show_timestamp = show_timestamp
        self.width = width

        #  Custom file extensions can be added via self.mimetypes.add_type()
        self.mimetypes = mimetypes.MimeTypes() 
开发者ID:michael-lazar,项目名称:flask-gopher,代码行数:24,代码来源:flask_gopher.py

示例2: do_GET

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def do_GET(self):


		parts = urlparse(self.path)
		path = parts.path.strip('/')
		if path == "":
			path = "index.htm"

		file = os.path.join("./UI/", path)
		mime = mimetypes.MimeTypes().guess_type(file)[0] 

		self.send_response(200)
		# self.send_header("Access-Control-Allow-Origin", "*")
		self.send_header("Content-Type", mime)
		self.end_headers()
		
		with open(file, "rb") as f:
			self.wfile.write(f.read()) 
开发者ID:AliFlux,项目名称:MapTilesDownloader,代码行数:20,代码来源:server.py

示例3: video_tag

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def video_tag(self, attrs=None):
        if attrs is None:
            attrs = {}
        else:
            attrs = attrs.copy()
        if self.thumbnail:
            attrs['poster'] = self.thumbnail.url

        transcodes = self.transcodes.exclude(processing=True).filter(error_message__exact='')
        sources = []
        for transcode in transcodes:
            sources.append("<source src='{0}' type='video/{1}' >".format(transcode.url, transcode.media_format.name))

        mime = mimetypes.MimeTypes()
        sources.append("<source src='{0}' type='{1}'>"
                       .format(self.url, mime.guess_type(self.url)[0]))

        sources.append("<p>Sorry, your browser doesn't support playback for this video</p>")
        return mark_safe(
            "<video {0}>\n{1}\n</video>".format(flatatt(attrs), "\n".join(sources))) 
开发者ID:neon-jungle,项目名称:wagtailvideos,代码行数:22,代码来源:models.py

示例4: builtin_mimetypes

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def builtin_mimetypes(func):

    @wraps(func)
    async def decorated(*args, **kwargs):
        with patch.object(utils, 'magic') as magic:
            magic.__bool__.return_value = False
            with patch.object(utils, 'mime') as mime:
                mime.guess_type.side_effect = mimetypes.MimeTypes().guess_type

                await func(*args, **kwargs)

    return decorated 
开发者ID:odrling,项目名称:peony-twitter,代码行数:14,代码来源:test_utils.py

示例5: setUp

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def setUp(self):
        self.db = mimetypes.MimeTypes() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_mimetypes.py

示例6: test_registry_parsing

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def test_registry_parsing(self):
        # the original, minimum contents of the MIME database in the
        # Windows registry is undocumented AFAIK.
        # Use file types that should *always* exist:
        eq = self.assertEqual
        mimetypes.init()
        db = mimetypes.MimeTypes()
        eq(db.guess_type("foo.txt"), ("text/plain", None))
        eq(db.guess_type("image.jpg"), ("image/jpeg", None))
        eq(db.guess_type("image.png"), ("image/png", None)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_mimetypes.py

示例7: __init__

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def __init__(self, server):
        Module.__init__(self, server)
        self.dispatcher = Dispatcher(self.scheduler)
        self.mimetypedatabase = mimetypes.MimeTypes(self.mimetypes)
        self._cache = {}
        self.apiroutine = RoutineContainer(self.scheduler)
        self.lastcleartime = 0
        def start(asyncStart = False):
            self._createHandlers(self)
        def close():
            self.dispatcher.close()
        self.apiroutine.start = start
        self.apiroutine.close = close
        self.routines.append(self.apiroutine)
        self.createAPI(api(self.updateconfig)) 
开发者ID:hubo1016,项目名称:vlcp,代码行数:17,代码来源:static.py

示例8: assets_set_asset

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def assets_set_asset(self, asset_name, file, **kwargs):
        """Set an asset image by name."""
        content_type = mimetypes.MimeTypes().guess_type(file)
        files = {
            asset_name: (file, open(file, 'rb'), content_type[0], {'Expires': '0'}),
        }
        return self.__call_api_post('assets.setAsset', kwargs=kwargs, use_json=False, files=files) 
开发者ID:jadolg,项目名称:rocketchat_API,代码行数:9,代码来源:rocketchat.py

示例9: test_encoding

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def test_encoding(self):
        getpreferredencoding = locale.getpreferredencoding
        self.addCleanup(setattr, locale, 'getpreferredencoding',
                                 getpreferredencoding)
        locale.getpreferredencoding = lambda: 'ascii'

        filename = support.findfile("mime.types")
        mimes = mimetypes.MimeTypes([filename])
        exts = mimes.guess_all_extensions('application/vnd.geocube+xml',
                                          strict=True)
        self.assertEqual(exts, ['.g3', '.g\xb3']) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:13,代码来源:test_mimetypes.py

示例10: __init__

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def __init__(self):
        self.classes = {}
        self.mimetypes = MimeTypes()
        mimedata = get_data('scrapy', 'mime.types').decode('utf8')
        self.mimetypes.readfp(StringIO(mimedata))
        for mimetype, cls in six.iteritems(self.CLASSES):
            self.classes[mimetype] = load_object(cls) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:9,代码来源:responsetypes.py

示例11: mime_type

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def mime_type(self):
        if not self._mime_type:
            if self.abspath.endswith(".js"):
                self._mime_type = "application/javascript"
            elif self.abspath.endswith(".css"):
                self._mime_type = "text/css"
            elif self.abspath.endswith(".json"):
                self._mime_type = mimetype.JSON
            else:
                mime = MimeTypes()
                self._mime_type, _ = mime.guess_type(self.abspath)
                if not self._mime_type:
                    self._mime_type = "application/binary"
        return self._mime_type 
开发者ID:mozilla,项目名称:jx-sqlite,代码行数:16,代码来源:__init__.py

示例12: open_files

# 需要导入模块: import mimetypes [as 别名]
# 或者: from mimetypes import MimeTypes [as 别名]
def open_files(self):
        self.close_files()

        files = []

        for x, file_or_name in enumerate(self.paths):
            name = ''
            if isinstance(file_or_name, tuple) and len(file_or_name) >= 2:
                name = file_or_name[1]
                file_or_name = file_or_name[0]

            if hasattr(file_or_name, 'read'):
                f = file_or_name

                if hasattr(f, 'name'):
                    filename = f.name
                else:
                    filename = name
            else:
                filename = file_or_name
                f = open(filename, 'rb')
                self.opened_files.append(f)

            mimetype = mimetypes.MimeTypes().guess_type(filename)[0]

            files.append(
                (self.key_format.format(x), ('file{}'.format(x), f, mimetype))
            )

        return files 
开发者ID:python273,项目名称:telegraph,代码行数:32,代码来源:upload.py


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