filesystem integration: more control on factories

This commit is contained in:
Helmut Merz 2012-11-18 15:52:18 +01:00
parent 56212ad441
commit 834ac35fd5

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
"""
Access to objects in the file system.
$Id$
"""
import os, stat
@ -115,10 +113,13 @@ class ContainerFactory(ContainerFactory):
class FileFactory(FileFactory):
proxyClass = File
imageClass = Image
def __call__(self, address, **kw):
contentType = kw.pop('contentType', None)
width = height = 0
obj = File(address, contentType, **kw)
obj = self.proxyClass(address, contentType, **kw)
if not contentType:
data = obj.getData(50)
contentType, width, height = getImageInfo(data)
@ -126,7 +127,7 @@ class FileFactory(FileFactory):
name = os.path.basename(address)
contentType, encoding = guess_content_type(name, data, '')
if contentType.startswith('image/'):
return Image(address, contentType=contentType,
return self.imageClass(address, contentType=contentType,
width=width, height=height, **kw)
else:
obj.contentType = contentType