PIL n'arrive pas à redimensionner certaines image. Par exemple:

http://www.bxlug.be/uploadfiles/39
This commit is contained in:
fpeters 2004-03-07 17:37:46 +00:00
parent 232592cd16
commit 9c00678b69
3 changed files with 19 additions and 4 deletions

View File

@ -91,6 +91,7 @@ register(AdminUploadFiles)
class UploadFile(ObjectServerMixin, UploadFileCommon): class UploadFile(ObjectServerMixin, UploadFileCommon):
def acquireNonCore(self, objectDirectoryPath = None, def acquireNonCore(self, objectDirectoryPath = None,
dataDirectoryPath = None, parentSlot = None): dataDirectoryPath = None, parentSlot = None):
self.properties = []
ObjectServerMixin.acquireNonCore( ObjectServerMixin.acquireNonCore(
self, objectDirectoryPath = objectDirectoryPath, self, objectDirectoryPath = objectDirectoryPath,
dataDirectoryPath = dataDirectoryPath, parentSlot = parentSlot) dataDirectoryPath = dataDirectoryPath, parentSlot = parentSlot)
@ -131,7 +132,7 @@ class UploadFile(ObjectServerMixin, UploadFileCommon):
property.kind.isTranslatable = 0 property.kind.isTranslatable = 0
property.kind.label = label property.kind.label = label
self.values[name] = value self.values[name] = value
self.properties.append(property) self.properties = self.properties[:]
if self.isType('image') and PILImage and self.data: if self.isType('image') and PILImage and self.data:
uploadFileFile = cStringIO.StringIO(self.data) uploadFileFile = cStringIO.StringIO(self.data)
@ -344,7 +345,10 @@ class UploadFilesServer(UploadFilesCommonMixin, ObjectsServer):
except IOError: except IOError:
pass pass
else: else:
objectObject.thumbnail((width, height)) try:
objectObject.thumbnail((width, height))
except IOError:
raise faults.UnresizableImage()
thumbnailFile = cStringIO.StringIO() thumbnailFile = cStringIO.StringIO()
objectObject.save( objectObject.save(
thumbnailFile, objectObject.format) thumbnailFile, objectObject.format)

View File

@ -119,6 +119,7 @@ faultCodeDuplicateSerial = 5004
faultCodeWrongToken = 5005 faultCodeWrongToken = 5005
faultCodeDisabledAccount = 5006 faultCodeDisabledAccount = 5006
faultCodeUnresizableImage = 6000
Fault = xmlrpclib.Fault Fault = xmlrpclib.Fault
@ -500,6 +501,13 @@ class DisabledAccount(BaseFault):
return 'Disabled account' return 'Disabled account'
class UnresizableImage(BaseFault):
faultCode = faultCodeUnresizableImage
def makeFaultString(self):
return 'unresizable image'
class UnknownStringDigest(BaseFault): class UnknownStringDigest(BaseFault):
faultCode = faultCodeUnknownStringDigest faultCode = faultCodeUnknownStringDigest

View File

@ -204,7 +204,7 @@ class UploadFilesWeb(ObjectsWebMixin, UploadFilesProxy):
id, ['modificationTime', 'dataFileName']) id, ['modificationTime', 'dataFileName'])
rememberObject(id) rememberObject(id)
if fileName and object.dataFileName != fileName: if fileName and object.dataFileName != urllib.unquote(fileName):
pageNotFound() pageNotFound()
if not fileName and object.dataFileName: if not fileName and object.dataFileName:
uri = X.idUrl(id, 'download/%s' % object.dataFileName) uri = X.idUrl(id, 'download/%s' % object.dataFileName)
@ -284,7 +284,10 @@ class UploadFilesWeb(ObjectsWebMixin, UploadFilesProxy):
height = int(height) height = int(height)
except ValueError: except ValueError:
height = 128 height = 128
object = self.getObjectThumbnail(id, width, height) try:
object = self.getObjectThumbnail(id, width, height)
except faults.UnresizableImage:
return pageNotFound() # FIXME: why not HTTP_NOT_IMPLEMENTED
rememberObject(id) rememberObject(id)
req = context.getVar('req') req = context.getVar('req')