コード例 #1
0
def image_update_data(self, data, content_type=None, size=None):
    if isinstance(data, unicode):
        raise TypeError('Data can only be str or file-like.  '
                        'Unicode objects are expressly forbidden.')
    
    if size is None: size=len(data)

    self.size=size
    if data:
        if IBlobStorage.providedBy(self._p_jar.db().storage):
            self.data = ZODB.blob.Blob(data)
        else:
            self.data = data
    else:
        self.data = ''

    ct, width, height = getImageInfo(data)
    if ct:
        content_type = ct
    if width >= 0 and height >= 0:
        self.width = width
        self.height = height

    # Now we should have the correct content type, or still None
    if content_type is not None: self.content_type = content_type

    self.ZCacheable_invalidate()
    self.ZCacheable_set(None)
    self.http__refreshEtag()
コード例 #2
0
    def _update(self, portal):

        brains = portal.portal_catalog(meta_type='Naaya Photo')

        for brain in brains:
            obj = brain.getObject()
            self.log.info("Migrating object %s", obj.absolute_url())
            for extfile in obj.objectValues('ExtFile'):
                self.log.info("Migrating extfile %s", extfile.absolute_url())
                data = extfile.index_html()
                filename = extfile.id
                obj.manage_delObjects([filename])
                child_id = obj.manage_addFile(filename)
                child = obj._getOb(child_id)
                child.content_type, child.width, child.height = getImageInfo(
                    data)
                blob = child.open_write()
                blob.write(data)
                blob.seek(0)
                blob.close()
                child.size = len(data)
                self.log.info('Migrated to bfile: %s' % child)

        self.log.info('Migration done')

        return True
コード例 #3
0
ファイル: NyPhoto.py プロジェクト: eaudeweb/trunk-eggs
    def update_data(self,
                    data,
                    content_type=None,
                    size=None,
                    filename='Original',
                    purge=True,
                    watermark=False):
        if purge:
            self.manage_delObjects(self.objectIds())
        filename = clean_display_id(filename)
        filename = self._getDisplayId(filename, watermark)
        if filename in self.objectIds():
            self.manage_delObjects([filename])

        child_id = self.manage_addFile(filename)
        child = self._getOb(child_id)
        if hasattr(data, '__class__') and data.__class__ is Pdata:
            data = str(data)
        elif getattr(data, 'index_html', None):
            data = data.index_html()

        if not isinstance(data, str):
            data = data.read()
        child.content_type, child.width, child.height = getImageInfo(data)

        child.manage_upload(data, child.content_type)
        return child.getId()
コード例 #4
0
    def _update(self, portal):

        brains = portal.portal_catalog(
            meta_type=['Naaya Photo', 'Naaya Media File'])

        for brain in brains:
            obj = brain.getObject()
            self.log.info("Migrating object %s", obj.absolute_url())
            for extfile in obj.objectValues('ExtFile'):

                if extfile.is_broken():
                    self.log.warning(
                        "\t BROKEN EXTFILE: Couldn't migrate extfile for %s "
                        "because of broken file", extfile.absolute_url())
                    continue

                self.log.info("Migrating extfile %s", extfile.absolute_url())
                data = extfile.index_html()
                filename = extfile.id
                obj.manage_delObjects([filename])
                child_id = obj.manage_addFile(filename)
                child = obj._getOb(child_id)
                child.content_type, child.width, child.height = getImageInfo(
                    data)
                blob = child.open_write()
                blob.write(data)
                blob.seek(0)
                blob.close()
                child.size = len(data)
                self.log.info('Migrated to bfile: %s' % child)

        self.log.info('Migration done')

        return True
コード例 #5
0
    def _update(self, portal):

        brains = portal.portal_catalog(meta_type=['Naaya Photo',
                                                  'Naaya Media File'])

        for brain in brains:
            obj = brain.getObject()
            self.log.info("Migrating object %s", obj.absolute_url())
            for extfile in obj.objectValues('ExtFile'):

                if extfile.is_broken():
                    self.log.warning(
                        "\t BROKEN EXTFILE: Couldn't migrate extfile for %s "
                        "because of broken file", extfile.absolute_url()
                    )
                    continue

                self.log.info("Migrating extfile %s", extfile.absolute_url())
                data = extfile.index_html()
                filename = extfile.id
                obj.manage_delObjects([filename])
                child_id = obj.manage_addFile(filename)
                child = obj._getOb(child_id)
                child.content_type, child.width, child.height = getImageInfo(
                    data)
                blob = child.open_write()
                blob.write(data)
                blob.seek(0)
                blob.close()
                child.size = len(data)
                self.log.info('Migrated to bfile: %s' % child)

        self.log.info('Migration done')

        return True
コード例 #6
0
    def _update(self, portal):

        brains = portal.portal_catalog(meta_type="Naaya Photo")

        for brain in brains:
            obj = brain.getObject()
            self.log.info("Migrating object %s", obj.absolute_url())
            for extfile in obj.objectValues("ExtFile"):
                self.log.info("Migrating extfile %s", extfile.absolute_url())
                data = extfile.index_html()
                filename = extfile.id
                obj.manage_delObjects([filename])
                child_id = obj.manage_addFile(filename)
                child = obj._getOb(child_id)
                child.content_type, child.width, child.height = getImageInfo(data)
                blob = child.open_write()
                blob.write(data)
                blob.seek(0)
                blob.close()
                child.size = len(data)
                self.log.info("Migrated to bfile: %s" % child)

        self.log.info("Migration done")

        return True
コード例 #7
0
ファイル: ExtImage.py プロジェクト: eaudeweb/naaya
 def _get_content_type(self, file, body, id, content_type=None):
     """ Determine the mime-type """
     ct, w, h = getImageInfo(body)
     if ct:
         content_type = ct
     else:
         content_type = super(ExtImage, self)._get_content_type(file, body, id, content_type)
     return content_type
コード例 #8
0
 def _readFile(self, reparse):
     data = self._data = self._readFileAsResourceOrDirect()
     if reparse or self.content_type == 'unknown/unknown':
         self.ZCacheable_invalidate()
         ct, width, height = getImageInfo(data)
         self.content_type = ct
         self.width = width
         self.height = height
     return data
コード例 #9
0
ファイル: FSImage.py プロジェクト: goschtl/zope
 def _readFile(self, reparse):
     data = self._data = self._readFileAsResourceOrDirect()
     if reparse or self.content_type == 'unknown/unknown':
         self.ZCacheable_invalidate()
         ct, width, height = getImageInfo( data )
         self.content_type = ct
         self.width = width
         self.height = height
     return data
コード例 #10
0
ファイル: ExtImage.py プロジェクト: chrisrivard/Blend-CMS
 def _get_content_type(self, file, body, id, content_type=None):
     """ Determine the mime-type """
     ct, w, h = getImageInfo(body)
     if ct:
         content_type = ct
     else:
         content_type = super(ExtImage, self)._get_content_type(
             file, body, id, content_type)
     return content_type
コード例 #11
0
ファイル: utils.py プロジェクト: CGTIC/Plone_SP
def getImageSize(img):
    """ determine the dimensions for the given image file """
    if hasPIL:
        try:
            return iopen(img).size
        except IOError:
            return 0, 0
    else:
        data = img.read(32)
        return getImageInfo(data)[1:]
コード例 #12
0
ファイル: ExtImage.py プロジェクト: eaudeweb/naaya
 def _get_content_type(self, file, body, id, content_type=None):
     """ Determine the mime-type """
     from OFS.Image import getImageInfo
     ct, w, h = getImageInfo(body)
     if ct: 
         content_type = ct
     else:
         content_type = ExtImage.inheritedAttribute('_get_content_type')(self, 
                                                 file, body, id, content_type)
     return content_type
コード例 #13
0
ファイル: utils.py プロジェクト: enfold-josh/plone.app.blob
def getImageSize(img):
    """ determine the dimensions for the given image file """
    if hasPIL:
        try:
            return iopen(img).size
        except IOError:
            return 0, 0
    else:
        data = img.read(32)
        return getImageInfo(data)[1:]
コード例 #14
0
ファイル: PUT_factory.py プロジェクト: clearwired/Blend-CMS
def PUT_factory(self, name, typ, body):
    '''Creates ExtImage instead of plain Image.'''
    ct, w, h = getImageInfo(body)
    if ct:
        major, minor = string.split(ct, '/')
        if major == 'image':
            return ExtImage(name, '', '')
    major, minor = string.split(typ, '/')
    if major == 'image':
        return ExtImage(name, '', '')
    return None
コード例 #15
0
 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'rb')
     try: data = file.read()
     finally: file.close()
     if reparse or self.content_type == 'unknown/unknown':
         ct, width, height = getImageInfo( data )
         self.content_type = ct
         self.width = width
         self.height = height
     return data
コード例 #16
0
ファイル: PUT_factory.py プロジェクト: chrisrivard/Blend-CMS
def PUT_factory(self, name, typ, body):
    '''Creates ExtImage instead of plain Image.'''
    ct, w, h = getImageInfo(body)
    if ct:
        major, minor = string.split(ct, '/')
        if major == 'image':
            return ExtImage(name, '', '')
    major, minor = string.split(typ, '/')
    if major == 'image':
        return ExtImage(name, '', '')
    return None
コード例 #17
0
ファイル: NyFSFile.py プロジェクト: Hamzahashmi4444/Salman-
 def update_data(self, data, content_type=None, size=None):
     file = data
     data, size = self._read_data(data)
     content_type = self._get_content_type(file, data, self.__name__,
                                           'application/octet-stream')
     ct, width, height = getImageInfo(data)
     if ct:
         content_type = ct
     if width >= 0 and height >= 0:
         self.width = width
         self.height = height
     NyFSImage.inheritedAttribute('update_data')(self, data, content_type,
                                                 size)
コード例 #18
0
ファイル: NyFSFile.py プロジェクト: eaudeweb/naaya
 def update_data(self, data, content_type=None, size=None, filename=""):
     file = data
     data, size = self._read_data(data)
     if not filename:
         filename = getattr(file, "filename", "")
     content_type = self._get_content_type(file, data, self.__name__, "application/octet-stream")
     ct, width, height = getImageInfo(data)
     if ct:
         content_type = ct
     if width >= 0 and height >= 0:
         self.width = width
         self.height = height
     NyFSImage.inheritedAttribute("update_data")(self, data, content_type, size, filename)
コード例 #19
0
    def _readFile(self, reparse):
        """Read the data from the filesystem.
        """
        file = open(self._filepath, 'rb')
        try:
            data = self._data = file.read()
        finally:
            file.close()

        if reparse or self.content_type == 'unknown/unknown':
            self.ZCacheable_invalidate()
            ct, width, height = getImageInfo( data )
            self.content_type = ct
            self.width = width
            self.height = height
        return data
コード例 #20
0
ファイル: Image.py プロジェクト: esosaja/erp5
  def _update_image_info(self):
    """
      This method tries to determine the content type of an image and
      its geometry. It uses currently OFS.Image for this purpose.
      However, this method is known to be too simplistic.

      TODO:
      - use image magick or PIL
    """
    self.size = len(self.data)
    content_type, width, height = getImageInfo(self.data)
    if not content_type:
      if self.size >= 30 and self.data[:2] == 'BM':
        header = struct.unpack('<III', self.data[14:26])
        if header[0] >= 12:
          content_type = 'image/x-bmp'
          width, height = header[1:]
    self.height = height
    self.width = width
    self._setContentType(content_type or 'application/unknown')
コード例 #21
0
    def _update_image_info(self):
        """
      This method tries to determine the content type of an image and
      its geometry. It uses currently OFS.Image for this purpose.
      However, this method is known to be too simplistic.

      TODO:
      - use image magick or PIL
    """
        self.size = len(self.data)
        content_type, width, height = getImageInfo(self.data)
        if not content_type:
            if self.size >= 30 and self.data[:2] == 'BM':
                header = struct.unpack('<III', self.data[14:26])
                if header[0] >= 12:
                    content_type = 'image/x-bmp'
                    width, height = header[1:]
        self.height = height
        self.width = width
        self._setContentType(content_type or 'application/unknown')
コード例 #22
0
    def update_data(self, data, content_type=None, size=None, filename='Original', purge=True, watermark=False):
        if purge:
            self.manage_delObjects(self.objectIds())
        filename = clean_display_id(filename)
        filename = self._getDisplayId(filename, watermark)
        if filename in self.objectIds():
            self.manage_delObjects([filename])

        child_id = self.manage_addFile(filename)
        child = self._getOb(child_id)
        if hasattr(data, '__class__') and data.__class__ is Pdata:
            data = str(data)
        elif getattr(data, 'index_html', None):
            data = data.index_html()
        
        if not isinstance(data, str):
            data = data.read()
        child.content_type, child.width, child.height = getImageInfo(data)
        
        child.manage_upload(data, child.content_type)
        return child.getId()
コード例 #23
0
    def _readFile(self, reparse):
        """Read the data from the filesystem.
        """
        file = open(self._filepath, 'rb')
        try:
            data = self._data = file.read()
        finally:
            file.close()

        if reparse or self.content_type == 'unknown/unknown':
            try:
                mtime = os.stat(self._filepath).st_mtime
            except:
                mtime = 0.0
            if mtime != self._file_mod_time or mtime == 0.0:
                self.ZCacheable_invalidate()
                self._file_mod_time = mtime
            ct, width, height = getImageInfo(data)
            self.content_type = ct
            self.width = width
            self.height = height
        return data
コード例 #24
0
ファイル: NyPhoto.py プロジェクト: eaudeweb/trunk-eggs
    def update_data(self,
                    data,
                    content_type=None,
                    size=None,
                    filename='Original',
                    purge=True,
                    watermark=False):

        if hasattr(data, '__class__') and data.__class__ is Pdata:
            data = str(data)
        elif getattr(data, 'index_html', None):
            data = data.index_html()

        if not isinstance(data,
                          str):  #dealing with a blobstreamiterator or StringIO
            data = data.read()

        if purge:
            self.manage_delObjects(self.objectIds())

        filename = clean_display_id(filename)
        filename = self._getDisplayId(filename, watermark)

        if filename in self.objectIds():
            self.manage_delObjects([filename])

        child_id = self.manage_addFile(filename)
        child = self._getOb(child_id)
        child.content_type, child.width, child.height = getImageInfo(data)

        #ZZZ: migration
        #child.manage_upload(data, child.content_type)
        blob = child.open_write()
        blob.write(data)
        blob.seek(0)
        blob.close()
        child.size = len(data)
        return child.getId()
コード例 #25
0
 def _update_image_info(self):
     """
   This method tries to determine the content type of an image and
   its geometry.
 """
     self.size = len(self.data)
     content_type, width, height = getImageInfo(self.data)
     if not content_type:
         try:
             image = PIL.Image.open(StringIO(str(self.data)))
         except IOError:
             width = height = -1
             content_type = 'application/unknown'
         else:
             width, height = image.size
             content_type = image.get_format_mimetype()
             # normalize the mimetype using the registry
             mimetype_list = self.getPortalObject(
             ).mimetypes_registry.lookup(content_type)
             if mimetype_list:
                 content_type = mimetype_list[0].normalized()
     self.height = height
     self.width = width
     self._setContentType(content_type)
コード例 #26
0
def validateLogoIsImage(value):
    ct, w, h = getImageInfo(value)
    if ct == '':
        raise ImageValidationError(value)
    return True
コード例 #27
0
def validateIsImage(value):
    ct, w, h = getImageInfo(value)
    if ct == '':
        raise ImageValidationError(value)
    return True