source: main/waeup.sirp/trunk/src/waeup/sirp/image/image.py @ 6309

Last change on this file since 6309 was 6309, checked in by uli, 13 years ago

Change WAeUPImageFile implementation: it now uses a local Blob to
store image data (much more efficient than the up to now used in-ZODB
string). We also do not check for any external filestorages any more.

File size: 1.7 KB
Line 
1##
2## image.py
3## Login : <uli@pu.smp.net>
4## Started on  Mon Apr 25 12:32:42 2011 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2011 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""
23Components for handling image files.
24"""
25import os
26from ZODB.blob import Blob
27from hurry.file import HurryFile
28from zope.interface import implements
29from waeup.sirp.image.interfaces import IWAeUPImageFile
30
31class WAeUPImageFile(HurryFile):
32    """A file prepared for storing image files.
33
34    This file type is built upon :class:`hurry.file.HurryFile`.
35    """
36    implements(IWAeUPImageFile)
37
38    def __init__(self, filename, data):
39        self.filename = filename
40        self._file = Blob(data)
41        self.headers = {}
42
43    def _getFile(self):
44        return self._file.open('r')
45
46    file = property(_getFile)
47
48    @property
49    def size(self):
50        f = self._file.open('r')
51        size = int(os.fstat(f.fileno()).st_size)
52        f.close()
53        return size
54
55    @property
56    def data(self):
57        f = self._file.open('r')
58        result = f.read()
59        f.close()
60        return result
Note: See TracBrowser for help on using the repository browser.