本文整理汇总了Python中mimetypes.MimeTypes.add_type方法的典型用法代码示例。如果您正苦于以下问题:Python MimeTypes.add_type方法的具体用法?Python MimeTypes.add_type怎么用?Python MimeTypes.add_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mimetypes.MimeTypes
的用法示例。
在下文中一共展示了MimeTypes.add_type方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_mimetypes
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
def configure_mimetypes(extra_types):
"""
Add additional mimetypes to a local MimeTypes instance to avoid polluting
global registery
"""
mimetypes = MimeTypes()
for content_type, extension in extra_types:
mimetypes.add_type(content_type, extension)
return mimetypes
示例2: make_headers
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
def make_headers(filename):
mime = MimeTypes()
mime.add_type('text/plain', '.log')
mime.add_type('text/x-yaml', '.yaml')
content_type, encoding = mime.guess_type(filename)
headers = {"Content-Type": "application/octet-stream"}
if content_type:
headers['Content-Type'] = content_type
if encoding:
headers['Content-Encoding'] = encoding
return headers
示例3: mimes
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
def mimes(self):
"""
Returns extended MimeTypes.
"""
_mimes = MimeTypes(strict=False)
_mimes.suffix_map.update({".tbz2": ".tar.bz2"})
_mimes.encodings_map.update({".bz2": "bzip2"})
if cfg["CFG_BIBDOCFILE_ADDITIONAL_KNOWN_MIMETYPES"]:
for key, value in iteritems(cfg["CFG_BIBDOCFILE_ADDITIONAL_KNOWN_MIMETYPES"]):
_mimes.add_type(key, value)
del key, value
return _mimes
示例4: write
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
def write(self, filename, contents, encoding='utf8'):
"""
Write a file to the data store.
"""
mime = MimeTypes()
mime.add_type('text/x-yaml', '.yaml')
content_type, _ = mime.guess_type(filename)
key = self.bucket.new_key(self._path(filename))
key.set_contents_from_string(contents.encode(encoding), {
'Content-Type': content_type or 'text/plain',
'Content-Encoding': encoding,
})
if self.public:
key.set_canned_acl('public-read')
示例5: exit
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
# Check that all the given paths really exist
if not os.path.exists(moduleLocation):
print 'ERROR: given module location does not exist'
exit()
isMissing = False
for f in filenames:
if not os.path.exists(moduleLocation + os.sep + f):
print 'ERROR: Cannot find %s' % f
isMissing = True
if isMissing:
exit()
# Initialisation of `magic` module
mime = MimeTypes()
mime.add_type('text/plain', '.bsh')
mime.add_type('text/plain', '.properties')
# Make browser
br = mechanize.Browser()
# Initialisation of `mechanize` module (Some stuff I copied from Stack Overflow)
cookiejar = cookielib.LWPCookieJar()
br.set_cookiejar (cookiejar)
br.set_handle_gzip (True)
br.set_handle_equiv (True)
br.set_handle_gzip (True)
br.set_handle_redirect(True)
br.set_handle_referer (True)
br.set_handle_robots (False)
示例6: QApplication
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
#==============================
#
#==============================
if __name__ == "__main__":
#log.setLevel(logging.WARNING)
log.debug("------ start imgimport-------")
app = QApplication(sys.argv)
mime = MimeTypes()
mime.add_type('image/tiff','.arw')
# get global settings
SourceDir = settings.SourceDir
#DestDir=settings.DestDir
exif = ExifTools()
exif.initArglist()
filemgr = Filemanager()
#filemgr.readFiles(Filelist, item_list)
window = ImageWindow()
window.show()
sys.exit(app.exec_())
示例7: _init_mimeutils_mime_types
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
def _init_mimeutils_mime_types():
obj = MimeTypes()
# this is a special case since the DOT extension is normally mapped to 'application/msword'
obj.add_type('text/plain', '.dot', True)
return obj
示例8: parseArguments
# 需要导入模块: from mimetypes import MimeTypes [as 别名]
# 或者: from mimetypes.MimeTypes import add_type [as 别名]
)
proc.wait()
if __name__ == "__main__":
parseArguments()
checkVerbose()
print "DestDir is " + DestDir
print "DoRename is %r" % DoRename
print "DoMove is %r" % DoMove
checkCreateDate()
mime = MimeTypes()
mime.add_type("image/tiff", ".arw")
fdnull = os.open("/dev/null", os.O_WRONLY)
inodlist = []
for f in Files:
lista = glob.glob(SourceDir + f)
for l in lista:
mt = mime.guess_type(l)
mtype = mt[0]
if mtype in acceptedImages:
st_ino = os.stat(l)[1]
inodlist.append(st_ino)
print "{}: mime={}, inode={}".format(l, mtype, st_ino)