コード例 #1
0
ファイル: field.py プロジェクト: CGTIC/Plone_SP
 def set(self, instance, value, **kwargs):
     """ use input value to populate the blob and set the associated
         file name and mimetype.  the latter can be overridden by an
         option "mimetype" keyword argument """
     if value in ('DELETE_FILE', 'DELETE_IMAGE'):
         super(BlobField, self).unset(instance, **kwargs)
         return
     # create a new blob instead of modifying the old one to
     # achieve copy-on-write semantics
     blob = BlobWrapper(self.default_content_type)
     if isinstance(value, basestring):
         value = StringIO(value)     # simple strings cannot be adapted...
         setattr(value, 'filename', kwargs.get('filename', None))
     if value is not None:
         blobbable = IBlobbable(value)
         try:
             blobbable.feed(blob.getBlob())
         except ReuseBlob, exception:
             blob.setBlob(exception.args[0])     # reuse the given blob
         mimetype = kwargs.get('mimetype', None)
         if not mimetype:
             mimetype = blobbable.mimetype()
         if mimetype and mimetype != 'None':
             blob.setContentType(mimetype)
         blob.setFilename(kwargs.get('filename', blobbable.filename()))
コード例 #2
0
ファイル: storage.py プロジェクト: 4teamwork/ftw.pdfify
 def store(self, data):
     blob = Blob()
     blobbable = IBlobbable(data)
     try:
         blobbable.feed(blob)
     except ReuseBlob, exception:
         blob = exception.args[0]  # reuse the given blob
コード例 #3
0
ファイル: test_adapters.py プロジェクト: CGTIC/Plone_SP
 def testBlobbableOFSFileWithoutFileName(self):
     obj = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(),
         getFile('plone.pdf').read())
     self.assertEqual(blobbable.filename(), '')
     self.assertEqual(blobbable.mimetype(), 'application/pdf')
コード例 #4
0
ファイル: test_adapters.py プロジェクト: CGTIC/Plone_SP
 def testBlobbableOFSImage(self):
     gif = getImage()
     obj = Image('foo', 'Foo', StringIO(gif))
     obj.filename = 'foo.gif'
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(), gif)
     self.assertEqual(blobbable.filename(), 'foo.gif')
     self.assertEqual(blobbable.mimetype(), 'image/gif')
コード例 #5
0
ファイル: test_adapters.py プロジェクト: CGTIC/Plone_SP
 def testBlobbableBinaryFile(self):
     _file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
     with open(_file, 'rb') as f:
         obj = Binary(f)
         obj.filename = 'image.gif'
         blobbable = IBlobbable(obj)
         target = Blob()
         blobbable.feed(target)
         self.assertEqual(target.open('r').read(),
                          getFile('image.gif').read())
         self.assertEquals(blobbable.filename(), 'image.gif')
         self.assertEquals(blobbable.mimetype(), 'image/gif')
コード例 #6
0
 def set(self, instance, value, **kwargs):
     """ use input value to populate the blob and set the associated
         file name and mimetype.  the latter can be overridden by an
         option "mimetype" keyword argument """
     if value in ('DELETE_FILE', 'DELETE_IMAGE'):
         super(BlobField, self).unset(instance, **kwargs)
         return
     # create a new blob instead of modifying the old one to
     # achieve copy-on-write semantics
     blob = BlobWrapper(self.default_content_type)
     if isinstance(value, basestring):
         value = StringIO(value)  # simple strings cannot be adapted...
         setattr(value, 'filename', kwargs.get('filename', None))
     if value is not None:
         blobbable = IBlobbable(value)
         try:
             blobbable.feed(blob.getBlob())
         except ReuseBlob, exception:
             blob.setBlob(exception.args[0])  # reuse the given blob
         mimetype = kwargs.get('mimetype', None)
         if not mimetype:
             mimetype = blobbable.mimetype()
         if mimetype and mimetype != 'None':
             blob.setContentType(mimetype)
         blob.setFilename(kwargs.get('filename', blobbable.filename()))
コード例 #7
0
ファイル: field.py プロジェクト: vedantc98/Plone-test
 def set(self, instance, value, **kwargs):
     """ use input value to populate the blob and set the associated
         file name and mimetype.  the latter can be overridden by an
         option "mimetype" keyword argument """
     if value in ('DELETE_FILE', 'DELETE_IMAGE'):
         super(BlobField, self).unset(instance, **kwargs)
         return
     # create a new blob instead of modifying the old one to
     # achieve copy-on-write semantics
     blob = BlobWrapper(self.default_content_type)
     if isinstance(value, six.string_types):
         value = StringIO(value)     # simple strings cannot be adapted...
         setattr(value, 'filename', kwargs.get('filename', None))
     if value is not None:
         blobbable = IBlobbable(value)
         try:
             blobbable.feed(blob.getBlob())
         except ReuseBlob as exception:
             blob.setBlob(exception.args[0])     # reuse the given blob
         mimetype = kwargs.get('mimetype', None)
         if not mimetype:
             mimetype = blobbable.mimetype()
         if mimetype and mimetype != 'None':
             blob.setContentType(mimetype)
         blob.setFilename(kwargs.get('filename', blobbable.filename()))
     super(BlobField, self).set(instance, blob, **kwargs)
     # a transaction savepoint is created after setting the blob's value
     # in order to make it available at its temporary path (e.g. to index
     # pdfs etc using solr & tika within the same transaction)
     savepoint(optimistic=True)
コード例 #8
0
 def testBlobbableOFSFileWithoutFileName(self):
     obj = File('foo', 'Foo', getFile('plone.pdf'), 'application/pdf')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(), getFile('plone.pdf').read())
     self.assertEqual(blobbable.filename(), '')
     self.assertEqual(blobbable.mimetype(), 'application/pdf')
コード例 #9
0
 def testBlobbableOFSImage(self):
     gif = getImage()
     obj = Image('foo', 'Foo', StringIO(gif))
     obj.filename = 'foo.gif'
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
     self.assertEqual(target.open('r').read(), gif)
     self.assertEqual(blobbable.filename(), 'foo.gif')
     self.assertEqual(blobbable.mimetype(), 'image/gif')
コード例 #10
0
 def testBlobbableBinaryFile(self):
     _file = os.path.join(os.path.dirname(__file__), 'data', 'image.gif')
     with open(_file, 'rb') as f:
         obj = Binary(f)
         obj.filename = 'image.gif'
         blobbable = IBlobbable(obj)
         target = Blob()
         blobbable.feed(target)
         self.assertEqual(
             target.open('r').read(),
             getFile('image.gif').read())
         self.assertEquals(blobbable.filename(), 'image.gif')
         self.assertEquals(blobbable.mimetype(), 'image/gif')
コード例 #11
0
    def set(self, instance, value, **kwargs):
        """ use input value to populate the blob and set the associated
            file name and mimetype """
        if value == "DELETE_FILE":
            ObjectField.unset(self, instance, **kwargs)
            return
        # create a new blob instead of modifying the old one to
        # achieve copy-on-write semantics.

        if isinstance(value, basestring):
            # make StringIO from string, because StringIO may be adapted to Blobabble
            value = StringIO(value)
        if value is not None:
            blobbable = IBlobbable(value)
            #move blob ctor down to where we know the mimetype
            blob = BlobWrapper(blobbable.mimetype())
            blobbable.feed(blob.getBlob())
            blob.setContentType(blobbable.mimetype())
            
            blob.setFilename(blobbable.filename())
        ObjectField.set(self, instance, blob, **kwargs)
        self.fixAutoId(instance)
コード例 #12
0
 def testBlobbableEmptyATFile(self):
     obj = ATFile('foo')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
コード例 #13
0
ファイル: test_adapters.py プロジェクト: CGTIC/Plone_SP
 def testBlobbableEmptyATFile(self):
     obj = ATFile('foo')
     blobbable = IBlobbable(obj)
     target = Blob()
     blobbable.feed(target)
コード例 #14
0
 def manage_upload(self, data):
     if isinstance(data, basestring):
         data = StringIO(data)
     blobbable = IBlobbable(data)
     blobbable.feed(self.getBlob())