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 # 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 # it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
""" """
Access to objects in the file system. Access to objects in the file system.
$Id$
""" """
import os, stat import os, stat
@ -115,10 +113,13 @@ class ContainerFactory(ContainerFactory):
class FileFactory(FileFactory): class FileFactory(FileFactory):
proxyClass = File
imageClass = Image
def __call__(self, address, **kw): def __call__(self, address, **kw):
contentType = kw.pop('contentType', None) contentType = kw.pop('contentType', None)
width = height = 0 width = height = 0
obj = File(address, contentType, **kw) obj = self.proxyClass(address, contentType, **kw)
if not contentType: if not contentType:
data = obj.getData(50) data = obj.getData(50)
contentType, width, height = getImageInfo(data) contentType, width, height = getImageInfo(data)
@ -126,7 +127,7 @@ class FileFactory(FileFactory):
name = os.path.basename(address) name = os.path.basename(address)
contentType, encoding = guess_content_type(name, data, '') contentType, encoding = guess_content_type(name, data, '')
if contentType.startswith('image/'): if contentType.startswith('image/'):
return Image(address, contentType=contentType, return self.imageClass(address, contentType=contentType,
width=width, height=height, **kw) width=width, height=height, **kw)
else: else:
obj.contentType = contentType obj.contentType = contentType