本文整理汇总了Python中OFS.Image.File.getContentType方法的典型用法代码示例。如果您正苦于以下问题:Python File.getContentType方法的具体用法?Python File.getContentType怎么用?Python File.getContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OFS.Image.File
的用法示例。
在下文中一共展示了File.getContentType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeFile
# 需要导入模块: from OFS.Image import File [as 别名]
# 或者: from OFS.Image.File import getContentType [as 别名]
def writeFile(self, path, data):
basepath = '/'.join(path.split('/')[:-1])
if basepath:
self.makeDirectory(basepath)
filename = path.split('/')[-1]
if isinstance(filename, unicode):
filename = filename.encode('utf-8')
f = File(filename, filename, data)
if f.getContentType() == 'text/html':
# otherwise HTTPResponse.setBody assumes latin1 and mangles things
f.content_type = 'text/html; charset=utf-8'
container = self.context.unrestrictedTraverse(basepath)
if filename in container:
container._delOb(filename)
container._setOb(filename, f)
示例2: writeFile
# 需要导入模块: from OFS.Image import File [as 别名]
# 或者: from OFS.Image.File import getContentType [as 别名]
def writeFile(self, path, data):
basepath = '/'.join(path.split('/')[:-1])
if basepath:
self.makeDirectory(basepath)
filename = path.split('/')[-1]
if isinstance(filename, unicode):
filename = filename.encode('utf-8')
f = File(filename, filename, data)
ct = f.getContentType()
if ct.startswith('text/') or ct == 'application/javascript':
# otherwise HTTPResponse.setBody assumes latin1 and mangles things
f.content_type = ct + '; charset=utf-8'
container = self.context.unrestrictedTraverse(basepath)
if filename in container:
container._delOb(filename)
event = PloneResourceModifiedEvent
else:
event = PloneResourceCreatedEvent
container._setOb(filename, f)
obj = container._getOb(filename)
notify(event(obj))