- Timestamp:
- 13 Nov 2014, 14:40:27 (10 years ago)
- Location:
- main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba
- Files:
-
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/README.txt
r7819 r11949 1 waeup. kofa.image -- handling image files1 waeup.ikoba.image -- handling image files 2 2 ======================================== 3 3 4 The image file widget is built on top of the :class:` KofaImageFile` object::5 6 >>> from waeup. kofa.image import KofaImageFile7 >>> file = KofaImageFile('foo.jpg', 'mydata')4 The image file widget is built on top of the :class:`IkobaImageFile` object:: 5 6 >>> from waeup.ikoba.image import IkobaImageFile 7 >>> file = IkobaImageFile('foo.jpg', 'mydata') 8 8 >>> file.filename 9 9 'foo.jpg' … … 16 16 'mydata' 17 17 18 We can also create KofaImageFile objects from file-like objects::18 We can also create IkobaImageFile objects from file-like objects:: 19 19 20 20 >>> from StringIO import StringIO … … 36 36 ---------------- 37 37 38 The KofaImageFile object normally stores the file data using ZODB38 The IkobaImageFile object normally stores the file data using ZODB 39 39 persistence. Files can however also be stored by tramline. If 40 40 tramline is installed in Apache, the Tramline takes care of generating … … 73 73 just '1') will now be created:: 74 74 75 >>> file = KofaImageFile('foo.jpg', '1')75 >>> file = IkobaImageFile('foo.jpg', '1') 76 76 77 77 The data is now '1', referring to the real file:: … … 102 102 We expect the same behavior as when tramline is not installed:: 103 103 104 >>> file = KofaImageFile('foo.jpg', 'data')104 >>> file = IkobaImageFile('foo.jpg', 'data') 105 105 >>> f = file.file 106 106 >>> f.read() … … 114 114 >>> shutil.rmtree(dirpath) 115 115 116 Support for :mod:`waeup. kofa.imagestorage`116 Support for :mod:`waeup.ikoba.imagestorage` 117 117 ------------------------------------------ 118 118 119 119 The behaviour shown above can be used for any Zope3 application. With 120 :mod:`waeup. kofa` we use a special file retrieval utility defined in121 :mod:`waeup. kofa.imagestorage`. As this utility is based on122 :mod:`waeup. kofa` internal stuff we do not show it here but in the120 :mod:`waeup.ikoba` we use a special file retrieval utility defined in 121 :mod:`waeup.ikoba.imagestorage`. As this utility is based on 122 :mod:`waeup.ikoba` internal stuff we do not show it here but in the 123 123 tests that come with that storage type. 124 124 … … 135 135 The `ImageFile` field accepts only certain content types: 136 136 137 >>> from waeup. kofa.image.schema import ImageFile137 >>> from waeup.ikoba.image.schema import ImageFile 138 138 >>> from zope.publisher.browser import TestRequest 139 139 >>> field = ImageFile(__name__='foo', title=u'Foo') … … 141 141 Traceback (most recent call last): 142 142 ... 143 WrongType: ('asd', <class 'waeup. kofa.image.image.KofaImageFile'>, 'foo')143 WrongType: ('asd', <class 'waeup.ikoba.image.image.IkobaImageFile'>, 'foo') 144 144 145 145 which means: `ImageFile` fields should better contain 146 :class:` KofaImageFile` instances.147 148 We can store normal :class:` KofaImageFile` instances:149 150 >>> field.validate( KofaImageFile('bar.jpg', 'data')) is None146 :class:`IkobaImageFile` instances. 147 148 We can store normal :class:`IkobaImageFile` instances: 149 150 >>> field.validate(IkobaImageFile('bar.jpg', 'data')) is None 151 151 True 152 152 … … 173 173 174 174 >>> field.validate( 175 ... KofaImageFile('bar.jpg', '123456789012')) is None176 True 177 178 >>> field.validate( 179 ... KofaImageFile('bar.jpg', '12345')) is None175 ... IkobaImageFile('bar.jpg', '123456789012')) is None 176 True 177 178 >>> field.validate( 179 ... IkobaImageFile('bar.jpg', '12345')) is None 180 180 True 181 181 … … 183 183 184 184 >>> field.validate( 185 ... KofaImageFile('bar.jpg', '1234567890123'))185 ... IkobaImageFile('bar.jpg', '1234567890123')) 186 186 Traceback (most recent call last): 187 187 ... … … 189 189 190 190 >>> field.validate( 191 ... KofaImageFile('bar.jpg', '1234'))191 ... IkobaImageFile('bar.jpg', '1234')) 192 192 Traceback (most recent call last): 193 193 ... … … 198 198 ---------------------------- 199 199 200 KofaImageFile does not reproduce the broken unequal comparison from200 IkobaImageFile does not reproduce the broken unequal comparison from 201 201 its base: 202 202 203 >>> f1 = KofaImageFile('bar.jpg', '123456789')204 >>> f2 = KofaImageFile('bar.jpg', '123456789')205 >>> f3 = KofaImageFile('baz.jpg', '1234')203 >>> f1 = IkobaImageFile('bar.jpg', '123456789') 204 >>> f2 = IkobaImageFile('bar.jpg', '123456789') 205 >>> f3 = IkobaImageFile('baz.jpg', '1234') 206 206 >>> f1 == f2 207 207 True -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/__init__.py
r11480 r11949 3 3 Including schemas, widgets and the content components. 4 4 """ 5 from waeup. kofa.image.image import KofaImageFile, createKofaImageFile5 from waeup.ikoba.image.image import IkobaImageFile, createIkobaImageFile 6 6 7 7 __all__ = [ 8 " KofaImageFile",9 "create KofaImageFile",8 "IkobaImageFile", 9 "createIkobaImageFile", 10 10 ] -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/browser/__init__.py
r7811 r11949 1 1 # The public API part 2 2 # Contains the widgets defined for image files. 3 from waeup. kofa.image.browser.widget import (3 from waeup.ikoba.image.browser.widget import ( 4 4 EncodingImageFileWidget, ThumbnailWidget, 5 5 ) -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/browser/tests/image.txt
r7819 r11949 12 12 13 13 >>> import os 14 >>> from waeup. kofa.image import KofaImageFile14 >>> from waeup.ikoba.image import IkobaImageFile 15 15 >>> testimage = os.path.join(os.path.dirname(__file__), 'sample.jpg') 16 16 >>> testimage2 = os.path.join(os.path.dirname(__file__), 'sample2.jpg') 17 >>> some_file = KofaImageFile('foo.jpg', open(testimage, 'rb').read())17 >>> some_file = IkobaImageFile('foo.jpg', open(testimage, 'rb').read()) 18 18 >>> some_file.filename 19 19 'foo.jpg' … … 26 26 >>> from hurry.file.browser import DownloadWidget 27 27 >>> from hurry.file.schema import File 28 >>> from waeup. kofa.image.schema import ImageFile28 >>> from waeup.ikoba.image.schema import ImageFile 29 29 >>> from zope.publisher.browser import TestRequest 30 30 >>> field = ImageFile(__name__='foo', title=u'Foo') … … 51 51 Instead of downloading, we can also use a thumbnail widget: 52 52 53 >>> from waeup. kofa.image.browser import ThumbnailWidget53 >>> from waeup.ikoba.image.browser import ThumbnailWidget 54 54 >>> request = TestRequest(form={'field.foo': FileUpload(some_file)}) 55 55 >>> widget = ThumbnailWidget(field, request) … … 61 61 data already available, and no data in request: 62 62 63 >>> from waeup. kofa.image.browser import EncodingImageFileWidget63 >>> from waeup.ikoba.image.browser import EncodingImageFileWidget 64 64 >>> field = ImageFile(__name__='foo', title=u'Foo', required=False) 65 65 >>> field = field.bind(None) … … 166 166 prepare some new file: 167 167 168 >>> another_file = KofaImageFile('bar.txt', 'bar contents')168 >>> another_file = IkobaImageFile('bar.txt', 'bar contents') 169 169 170 170 We happen to know, due to the implementation of … … 200 200 --------------------------- 201 201 202 As :class:`waeup. kofa.image.KofaImageFile` objects support storing202 As :class:`waeup.ikoba.image.IkobaImageFile` objects support storing 203 203 image data by using external 'storages', also our widgets should do 204 204 so. … … 220 220 ... contents = f.read() 221 221 ... id_string = hashlib.md5(contents).hexdigest() 222 ... result = KofaImageFile(filename, id_string)222 ... result = IkobaImageFile(filename, id_string) 223 223 ... self.storage[id_string] = contents 224 224 ... return result … … 260 260 We now want to simulate, that the field contains already data, 261 261 identified by some `file_id`. To do so, we first store the data in our 262 file retrieval and then create a KofaImageFile object with that262 file retrieval and then create a IkobaImageFile object with that 263 263 file_id stored: 264 264 265 >>> from waeup. kofa.image import createKofaImageFile266 >>> image = create KofaImageFile(265 >>> from waeup.ikoba.image import createIkobaImageFile 266 >>> image = createIkobaImageFile( 267 267 ... 'sample.jpg', open(testimage, 'rb')) 268 268 >>> file_id = image.data … … 274 274 '9feac4265077922000aa8b88748e25be' 275 275 276 The new file was stored by our utility, as create KofaImageFile looks276 The new file was stored by our utility, as createIkobaImageFile looks 277 277 up IFileRetrieval utilities and uses them: 278 278 -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/browser/tests/test_views.py
r7811 r11949 30 30 from hurry.file.file import IdFileRetrieval 31 31 from hurry.file.interfaces import IFileRetrieval 32 from waeup. kofa.image.browser.views import HurryFileView32 from waeup.ikoba.image.browser.views import HurryFileView 33 33 from zope.component import getMultiAdapter, provideUtility 34 34 from zope.publisher.browser import TestRequest … … 41 41 class ImageBrowserViewsLayer(object): 42 42 """A layer that registers all components in 43 `waeup. kofa.image.browser.views` module.43 `waeup.ikoba.image.browser.views` module. 44 44 """ 45 45 @classmethod 46 46 def setUp(cls): 47 grok.testing.grok('waeup. kofa.image.browser.views')47 grok.testing.grok('waeup.ikoba.image.browser.views') 48 48 49 49 @classmethod -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/browser/widget.py
r7819 r11949 19 19 """ 20 20 import os 21 from waeup. kofa.image import KofaImageFile21 from waeup.ikoba.image import IkobaImageFile 22 22 from hurry.file.browser.widget import ( 23 23 EncodingFileWidget, DownloadWidget, FakeFieldStorage) … … 62 62 seek(0) 63 63 return retrieval.createFile(input.filename, input) 64 return KofaImageFile(input.filename, data)64 return IkobaImageFile(input.filename, data) 65 65 else: 66 66 return self.context.missing_value … … 143 143 data = file_id.decode('base64') 144 144 filename, filedata = data.split('\n', 1) 145 return KofaImageFile(filename, filedata)145 return IkobaImageFile(filename, filedata) 146 146 147 147 class ThumbnailWidget(DownloadWidget): -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/image.py
r7819 r11949 23 23 from zope.component import getUtility 24 24 from zope.interface import implements 25 from waeup. kofa.image.interfaces import IKofaImageFile25 from waeup.ikoba.image.interfaces import IIkobaImageFile 26 26 27 class KofaImageFile(HurryFile):27 class IkobaImageFile(HurryFile): 28 28 """A file prepared for storing image files. 29 29 … … 32 32 regular hurry files. 33 33 34 To create a :class:` KofaImageFile` you should use35 :func:`create KofaImageFile`.34 To create a :class:`IkobaImageFile` you should use 35 :func:`createIkobaImageFile`. 36 36 """ 37 implements(I KofaImageFile)37 implements(IIkobaImageFile) 38 38 39 39 def __ne__(self, other): … … 45 45 return True 46 46 47 def create KofaImageFile(filename, f):47 def createIkobaImageFile(filename, f): 48 48 retrieval = getUtility(IFileRetrieval) 49 49 return retrieval.createFile(filename, f) -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/interfaces.py
r7819 r11949 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 """Interfaces for waeup. kofa.image18 """Interfaces for waeup.ikoba.image 19 19 """ 20 20 from hurry.file.interfaces import IFile, IFileRetrieval, IHurryFile … … 24 24 """ 25 25 26 class I KofaImageFile(IHurryFile):26 class IIkobaImageFile(IHurryFile): 27 27 """Image file. 28 28 """ -
main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/image/schema.py
r7819 r11949 22 22 from zope.schema.interfaces import TooBig, TooSmall 23 23 from hurry.file.schema import File 24 from waeup. kofa.image.interfaces import IImageFile25 from waeup. kofa.image.image import KofaImageFile24 from waeup.ikoba.image.interfaces import IImageFile 25 from waeup.ikoba.image.image import IkobaImageFile 26 26 27 27 class MinMaxSize(object): … … 82 82 implements(IImageFile) 83 83 84 _type = KofaImageFile84 _type = IkobaImageFile
Note: See TracChangeset for help on using the changeset viewer.