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