Switch to unified view

a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
1
import os
1
import os
2
from cStringIO import StringIO
2
from cStringIO import StringIO
3
import logging
3
4
4
import pylons
5
import pylons
5
import Image
6
import Image
6
from gridfs import GridFS
7
from gridfs import GridFS
7
8
...
...
10
from ming.orm.declarative import MappedClass
11
from ming.orm.declarative import MappedClass
11
12
12
from .session import project_orm_session
13
from .session import project_orm_session
13
from allura.lib import utils
14
from allura.lib import utils
14
15
16
log = logging.getLogger(__name__)
15
17
16
SUPPORTED_BY_PIL=set([
18
SUPPORTED_BY_PIL=set([
17
        'image/jpg',
19
        'image/jpg',
18
        'image/jpeg',
20
        'image/jpeg',
19
        'image/pjpeg',
21
        'image/pjpeg',
...
...
145
        if content_type is None:
147
        if content_type is None:
146
            content_type = utils.guess_mime_type(filename)
148
            content_type = utils.guess_mime_type(filename)
147
        if not content_type.lower() in SUPPORTED_BY_PIL:
149
        if not content_type.lower() in SUPPORTED_BY_PIL:
148
            return None, None
150
            return None, None
149
151
152
        try:
150
        image = Image.open(fp)
153
            image = Image.open(fp)
154
        except IOError as e:
155
            log.error('Error opening image %s %s', filename, e)
156
            return None, None
157
151
        format = image.format
158
        format = image.format
152
        if save_original:
159
        if save_original:
153
            original_meta = original_meta or {}
160
            original_meta = original_meta or {}
154
            original = cls(
161
            original = cls(
155
                filename=filename, content_type=content_type, **original_meta)
162
                filename=filename, content_type=content_type, **original_meta)
...
...
166
        return original, thumbnail
173
        return original, thumbnail
167
174
168
    def is_image(self):
175
    def is_image(self):
169
        return (self.content_type
176
        return (self.content_type
170
                and self.content_type.lower() in SUPPORTED_BY_PIL)
177
                and self.content_type.lower() in SUPPORTED_BY_PIL)
171
    
178
172
    @property
179
    @property
173
    def length(self):
180
    def length(self):
174
        return self.rfile().length
181
        return self.rfile().length