本文整理汇总了Python中pyaid.file.FileUtils.FileUtils.getMimeType方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtils.getMimeType方法的具体用法?Python FileUtils.getMimeType怎么用?Python FileUtils.getMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.file.FileUtils.FileUtils
的用法示例。
在下文中一共展示了FileUtils.getMimeType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _generateHeaders
# 需要导入模块: from pyaid.file.FileUtils import FileUtils [as 别名]
# 或者: from pyaid.file.FileUtils.FileUtils import getMimeType [as 别名]
def _generateHeaders(self, keyName, expires =None, eTag =None, maxAge =-1):
"""Doc..."""
headers = dict()
if expires:
if isinstance(expires, unicode):
headers['Expires'] = expires.encode('utf-8', 'ignore')
elif isinstance(expires, str):
headers['Expires'] = expires
else:
headers['Expires'] = TimeUtils.dateTimeToWebTimestamp(expires)
elif eTag:
headers['ETag'] = unicode(eTag)
if maxAge > -1:
headers['Cache-Control'] = 'public, max-age=' + unicode(maxAge)
if keyName.endswith('.jpg'):
contentType = MIME_TYPES.JPEG_IMAGE
elif keyName.endswith('.png'):
contentType = MIME_TYPES.PNG_IMAGE
elif keyName.endswith('.gif'):
contentType = MIME_TYPES.GIF_IMAGE
else:
contentType = FileUtils.getMimeType(keyName)
if StringUtils.begins(contentType, ('text/', 'application/')):
headers['Content-Type'] = contentType + '; charset=UTF-8'
else:
headers['Content-Type'] = contentType
return headers
示例2: _generateHeaders
# 需要导入模块: from pyaid.file.FileUtils import FileUtils [as 别名]
# 或者: from pyaid.file.FileUtils.FileUtils import getMimeType [as 别名]
def _generateHeaders(
cls, keyName, expires =None, eTag =None, maxAge =-1, gzipped =False
):
"""Doc..."""
headers = dict()
if expires:
if StringUtils.isStringType(expires):
headers['Expires'] = StringUtils.toBytes(expires)
elif StringUtils.isBinaryType(expires):
headers['Expires'] = expires
else:
headers['Expires'] = StringUtils.toBytes(
TimeUtils.dateTimeToWebTimestamp(expires))
elif eTag:
headers['ETag'] = StringUtils.toBytes(eTag)
if maxAge > -1:
headers['Cache-Control'] = StringUtils.toBytes(
'max-age=%s; public' % maxAge)
if keyName.endswith('.jpg'):
contentType = MIME_TYPES.JPEG_IMAGE
elif keyName.endswith('.png'):
contentType = MIME_TYPES.PNG_IMAGE
elif keyName.endswith('.gif'):
contentType = MIME_TYPES.GIF_IMAGE
else:
contentType = FileUtils.getMimeType(keyName)
if StringUtils.begins(contentType, ('text/', 'application/')):
contentType = '%s; charset=UTF-8' % contentType
headers['Content-Type'] = contentType
if gzipped:
headers['Content-Encoding'] = 'gzip'
return headers