def test_create_update(self): # create plain NyBlobFile bf = NyBlobFile() self.assertEqual(bf.content_type, 'application/octet-stream') self.assertEqual(bf.filename, None) self.assertEqual(bf.open().read(), '') # create NyBlobFile with properties and content bf2 = NyBlobFile(filename='my_file.txt', content_type='text/plain') f = bf2.open_write() f.write('hello world') f.close() self.assertEqual(bf2.content_type, 'text/plain') self.assertEqual(bf2.filename, 'my_file.txt') self.assertEqual(bf2.open().read(), 'hello world') # change properties and content f = bf2.open_write() f.write('other content') f.close() bf2.filename = 'other_file.txt' bf2.content_type = 'text/html' self.assertEqual(bf2.content_type, 'text/html') self.assertEqual(bf2.filename, 'other_file.txt') self.assertEqual(bf2.open().read(), 'other content')
def __setstate__(self, state): """ Updates """ NyFSFile.inheritedAttribute("__setstate__")(self, state) if not hasattr(self, '_bfile'): etitle = getattr(self, 'title', 'File system data') eid = getattr(self, '__name__', 'data.fs') self._bfile = NyBlobFile(id=eid, title=etitle, size=0)
def image2blob(image, filename, content_type): blobfile = NyBlobFile(filename=filename, content_type=content_type) bf_stream = blobfile.open_write() # data = image.data # bf_stream.write(data) bf_stream.write(image) bf_stream.close() blobfile.size = len(image) return blobfile
def __init__(self, id, title, file, content_type='', precondition=''): try: id = id() except TypeError: pass self.__name__ = id self.title = title self.data = '' self.size = 0 self.content_type = content_type self.precondition = precondition self._bfile = NyBlobFile(id=id, title=title, size=0)
def make_blobfile(self, filename='bf.txt', content='hello world', content_type='text/plain'): bf = NyBlobFile(filename=filename, content_type=content_type, timestamp=datetime.utcnow(), contributor='tester') bf.removed = False bf.size = len(content) f = bf.open_write() f.write(content) f.close() return bf
def afterSetUp(self): self.portal.info.contact._theblob = NyBlobFile(filename='a.txt') f = self.portal.info.contact._theblob.open_write() f.write('some content') f.close() transaction.commit()
def manage_beforeUpdate(self, item=None, container=None): self_id = getattr(self, '__name__', 'data.fs') self._bfile = NyBlobFile(id=self_id, title=self.title_or_id())