コード例 #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
ファイル: image.py プロジェクト: trb116/pythonanalyzer
    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
ファイル: validators.py プロジェクト: vlcinsky/depot
        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
ファイル: validators.py プロジェクト: adamchainz/depot
        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
ファイル: attachments.py プロジェクト: OneGov/onegov.file
    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)