예제 #1
0
파일: image.py 프로젝트: adamchainz/depot
    def process_content(self, content, filename=None, content_type=None):
        orig_content = content
        content = utils.file_from_content(content)
        __, filename, content_type = FileStorage.fileinfo(orig_content)

        uploaded_image = Image.open(content)
        if max(uploaded_image.size) >= self.max_size:
            uploaded_image.thumbnail((self.max_size, self.max_size), Image.BILINEAR)
            content = SpooledTemporaryFile(INMEMORY_FILESIZE)
            uploaded_image.save(content, uploaded_image.format)

        content.seek(0)
        super(UploadedImageWithThumb, self).process_content(content, filename, content_type)

        thumbnail = uploaded_image.copy()
        thumbnail.thumbnail(self.thumbnail_size, Image.ANTIALIAS)
        thumbnail = thumbnail.convert('RGBA')
        thumbnail.format = self.thumbnail_format

        output = SpooledTemporaryFile(INMEMORY_FILESIZE)
        thumbnail.save(output, self.thumbnail_format)
        output.seek(0)

        thumb_path, thumb_id = self.store_content(output,
                                                  'thumb.%s' % self.thumbnail_format.lower())
        self['thumb_id'] = thumb_id
        self['thumb_path'] = thumb_path

        thumbnail_file = self.thumb_file
        self['_thumb_public_url'] = thumbnail_file.public_url
예제 #2
0
    def process_content(self, content, filename=None, content_type=None):
        orig_content = content
        content = utils.file_from_content(content)
        __, filename, content_type = FileStorage.fileinfo(orig_content)

        uploaded_image = Image.open(content)
        if max(uploaded_image.size) >= self.max_size:
            uploaded_image.thumbnail((self.max_size, self.max_size),
                                     Image.BILINEAR)
            content = SpooledTemporaryFile(INMEMORY_FILESIZE)
            uploaded_image.save(content, uploaded_image.format)

        content.seek(0)
        super(UploadedImageWithThumb,
              self).process_content(content, filename, content_type)

        thumbnail = uploaded_image.copy()
        thumbnail.thumbnail(self.thumbnail_size, Image.ANTIALIAS)
        thumbnail = thumbnail.convert('RGBA')
        thumbnail.format = self.thumbnail_format

        output = SpooledTemporaryFile(INMEMORY_FILESIZE)
        thumbnail.save(output, self.thumbnail_format)
        output.seek(0)

        thumb_path, thumb_id = self.store_content(
            output, 'thumb.%s' % self.thumbnail_format.lower())
        self['thumb_id'] = thumb_id
        self['thumb_path'] = thumb_path

        thumbnail_file = self.thumb_file
        self['_thumb_public_url'] = thumbnail_file.public_url
예제 #3
0
파일: helpers.py 프로젝트: kunthar/zopsedu
    def process_content(self, content, filename=None, content_type=None):
        """process_content"""
        __, filename, content_type = FileStorage.fileinfo(content)

        if content_type not in ALLOWED_EXTENSIONS.values():
            raise ValueError(_(f"Yüklenen dosya uygun formatta değildir."))

        super(AllowedUploadedFile,
              self).process_content(content, filename, content_type)
예제 #4
0
파일: utils.py 프로젝트: ra2003/oy-cms
 def process_content(self, content, filename=None, content_type=None):
     file = file_from_content(content)
     FileTypeCheckFilter(
         filetypes=["raster-image", "raw-image", "vector-image"
                    ]).validate_filetype(file)
     __, filename, content_type = FileStorage.fileinfo(content)
     for name, size in self.thumbnail_sizes.items():
         self.store_thumbnail(file, filename, name, size)
     content.seek(0)
     super().process_content(content, filename, content_type)
예제 #5
0
        def _convert_to_python(self, value, state=None):
            if isinstance(value, cgi.FieldStorage):
                if self.required and not getattr(value, 'filename', None):
                    raise tw2.core.ValidationError('required', self)

                if (self.extension is not None
                        and not value.filename.endswith(self.extension)):
                    raise tw2.core.ValidationError('badext', self)
            elif value:
                raise tw2.core.ValidationError('corrupt', self)
            elif self.required:
                raise tw2.core.ValidationError('required', self)

            return FileIntent(*FileStorage.fileinfo(value))
예제 #6
0
파일: helpers.py 프로젝트: kunthar/zopsedu
    def process_content(self, content, filename=None, content_type=None):
        """process_content"""
        __, filename, content_type = FileStorage.fileinfo(content)

        # Get a file object even if content was bytes
        content = utils.file_from_content(content)
        content.seek(0, 2)
        if content.tell() >= self.max_size:
            raise ValueError(
                _(f"Yüklenen resim boyutu {self.max_size/1024} KB büyük olamaz."
                  ))
        content.seek(0)
        super(LimitedSizeUploadedFile,
              self).process_content(content, filename, content_type)
예제 #7
0
        def _convert_to_python(self, value, state=None):
            if isinstance(value, cgi.FieldStorage):
                if self.required and not getattr(value, 'filename', None):
                    raise tw2.core.ValidationError('required', self)

                if (self.extension is not None
                        and not value.filename.endswith(self.extension)):
                    raise tw2.core.ValidationError('badext', self)
            elif value:
                raise tw2.core.ValidationError('corrupt', self)
            elif self.required:
                raise tw2.core.ValidationError('required', self)

            return FileIntent(*FileStorage.fileinfo(value))
예제 #8
0
    def process_content(self, content, filename=None, content_type=None):
        filename, content_type = FileStorage.fileinfo(content)[1:]
        content = utils.file_from_content(content)

        try:
            for processor in self.processors:
                content = processor(self, content, content_type) or content
                content.seek(0)
        except Image.DecompressionBombError:
            # not a real content type - but useful for us to be able to rely
            # on anything uploaded having a content type, even though that
            # content is discarded soon afterwards
            content = b''
            content_type = 'application/malicious'

        super().process_content(content, filename, content_type)
예제 #9
0
파일: helpers.py 프로젝트: kunthar/zopsedu
    def process_content(self, content, filename=None, content_type=None):
        """process_content"""
        __, filename, content_type = FileStorage.fileinfo(content)

        # Get a file object even if content was bytes
        content = utils.file_from_content(content)

        uploaded_image = Image.open(content)
        width, height = uploaded_image.size
        if content_type not in self.accepted_file_types:
            raise ValueError(
                _("Yüklenen resim bu dosya türlerinden biri olmalıdır : {}".
                  format(', '.join(
                      [i.split('/')[1] for i in self.accepted_file_types]))))
        if width > self.max_width or height > self.max_height:
            raise ValueError(
                _(f"Yüklenen resim boyutu {self.max_width}x{self.max_height}"
                  f" pikselden büyük olamaz."))

        content.seek(0)
        super(UploadedImageWithMaxDimensions,
              self).process_content(content, filename, content_type)