{ "info": { "author": "Souheil Chelfouh", "author_email": "trollfot@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Other Audience", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "===========\ndolmen.blob\n===========\n\n`dolmen.blob` is a layer above `dolmen.file`, using the ZODB blobs as\na storage facility. It respects the `zope.file` IFile and the\n`dolmen.file` INamedFile interfaces.\n\n\nCompatibility\n=============\n\nIn order to make sure that our BlobFile is functional, we test it\nagainst some common uses, implemented by `zope.file.file.File` and\n`dolmen.file.NamedFile`::\n\n >>> from dolmen.blob import BlobFile, IBlobFile\n\n >>> blob = BlobFile()\n >>> print blob.contentType\n application/octet-stream\n >>> blob.data\n ''\n >>> blob.filename\n u''\n\n >>> blob = BlobFile(data='mydata', filename=\"foo.txt\")\n >>> blob.filename\n u'foo.txt'\n >>> blob.data\n 'mydata'\n >>> blob.contentType\n 'text/plain'\n >>> blob.mimeType\n 'text/plain'\n\n >>> blob = BlobFile(data=u'some random data', filename=\"foo.txt\")\n >>> blob.filename\n u'foo.txt'\n >>> blob.data\n 'some random data'\n\n >>> blob = BlobFile(contentType=\"plain/text\")\n >>> blob.filename\n u''\n >>> blob.data\n ''\n >>> blob.contentType\n 'plain/text'\n\n >>> import cStringIO\n >>> data = cStringIO.StringIO(\"mydata\")\n >>> blob = BlobFile(data=data)\n >>> blob.data\n 'mydata'\n >>> blob.size\n 6\n\n >>> from zope.size.interfaces import ISized\n >>> sized = ISized(blob)\n >>> sized\n \n >>> sized.sizeForDisplay()\n u'1 KB'\n >>> sized.sizeForSorting()\n ('byte', 6)\n\n >>> from zope.filerepresentation.interfaces import IReadFile, IWriteFile\n >>> reader = IReadFile(blob)\n >>> writer = IWriteFile(blob)\n\n >>> reader.read()\n 'mydata'\n >>> reader.size()\n 6\n\n >>> writer.write('changing data')\n >>> reader.read()\n 'changing data'\n >>> reader.size()\n 13\n\nLet's verify the implementation in depth::\n\n >>> from dolmen.file import INamedFile\n >>> from zope.interface import verify\n >>> import zope.file \n\n >>> blob = BlobFile(data='my data')\n >>> verify.verifyObject(IBlobFile, blob)\n True\n >>> verify.verifyObject(INamedFile, blob)\n True\n >>> verify.verifyObject(zope.file.interfaces.IFile, blob)\n True\n\n\nStorage\n=======\n\nThe ZODB blobs mimic a basic Python file and implement basic methods,\nlike read, write, readlines, seek, etc. In order to provide a very\npluggable and performant way to persist the datas, `dolmen.file`\nproposes a storage mechanism, based on adapters. This idea, originally\nimplemented in z3c.blobfile, has been enhanced to rely on multi\nadapters, adapting an ZODB.interfaces.IBlob and a data object.\n\nAs seen above, in the ``compatibility`` section, the\ndolmen.blob.BlobFile handles String, Unicode and file-like objects,\nout of the box.\n\nErrors\n------\n\nIf the storage can't find a way to persist the data, a\n`dolmen.blob.StorageError` exception is raised::\n\n >>> blob = BlobFile(data={'something': 1})\n Traceback (most recent call last):\n ...\n StorageError: An error occured during the blob storage. Check the value type (). This value should implement IFile, IString or IUnicode (see `dolmen.builtins`).\n\n\nStorage implementation\n----------------------\n\nThe example above shows us that the Dict object is not handled by\ndolmen.blob, out of the box. Let's implement a storage for this\nusecase::\n\n >>> import zope.component\n >>> from ZODB.interfaces import IBlob\n >>> from dolmen.builtins import IDict\n >>> from dolmen.blob import IFileStorage\n \n >>> def store_dict(blob, dictionnary):\n ... dict_repr = repr(dictionnary.items())\n ... fp = blob.open('w')\n ... fp.write(dict_repr)\n ... fp.close()\n ... return True\n\n >>> zope.component.provideAdapter(\n ... store_dict, adapts=(IBlob, IDict), provides=IFileStorage)\n\n >>> blob = BlobFile(data={'something': 1})\n >>> blob.data\n \"[('something', 1)]\"\n\n\nBlob to blob storage\n--------------------\n\n`dolmen.blob` provides a blob to blob copy, using shutils::\n\n >>> source = BlobFile(data='Some data here')\n >>> destination = BlobFile(data='')\n\n >>> destination.data = source\n >>> destination.data\n 'Some data here'\n\n\nMimetype and charset\n====================\n\n`dolmen.blob` provides components implementing the `zope.mimetype`\nIContentTypeAware interface. It allows your content to be manipulated\nin order to set a mimetype and extensive headers coptions.\n\nSeveral adapters are provided by `zope.mimetype`. We don't want to\nreview them all, but there are some interesting ones.\n\nThe IContentInfo components allow you to get detailed information for\nyour content, formatted in a convenient way, to publish them easily::\n\n >>> from zope.interface import alsoProvides\n >>> from zope.mimetype.interfaces import IContentInfo\n\n >>> blob = BlobFile(data=u'some random data', filename=\"foo.txt\")\n >>> info = IContentInfo(blob)\n >>> print info\n \n >>> print info.effectiveMimeType\n text/plain\n >>> print info.effectiveParameters\n {}\n \nIt allows a rough handling of the data encoding too::\n\n >>> from zope.mimetype.interfaces import IContentTypeEncoded\n\n >>> encoded = BlobFile(data=u'La Pe\\xf1a',\n ... parameters={'charset': 'utf-8'})\n\n >>> info = IContentInfo(encoded)\n >>> print info.effectiveParameters\n {}\n\n >>> alsoProvides(encoded, IContentTypeEncoded)\n >>> info = IContentInfo(encoded)\n\n >>> info.effectiveParameters\n {'charset': 'utf-8'}\n\n >>> info.effectiveMimeType\n 'application/octet-stream'\n\n >>> info.contentType\n 'application/octet-stream;charset=utf-8'\n\n >>> codec = info.getCodec()\n >>> codec.name\n 'utf-8'\n\n\nAccesses\n========\n\nFilesystem access\n-----------------\n\nIn some cases, it's useful to be able to be able to get the location\nof the physical blob file on the filesystem. This is possible through\nthe attribute `physical_path`. However, this attribute is available\nonly when the file has been persisted and the transaction commited::\n\n >>> import transaction\n >>> root = getRootFolder()\n >>> root['myblob'] = BlobFile(data='my data', filename=\"data.txt\")\n\nThe transaction has not been commited, we try to access the attribute::\n\n >>> myblob = root['myblob']\n >>> print myblob.physical_path\n None\n \nWe now commit the transaction and retry::\n\n >>> transaction.commit()\n >>> print myblob.physical_path\n /tmp/tmp.../....blob\n\n\nBrowser access\n-------------- \n\n.. attention::\n\n Please read `dolmen.file` README.txt for more information.\n\nAs an dolmen.file.INamedFile, the BlobFile can bee accessed by the\nbrowser, using a \"file_publish\" view::\n\n >>> from zope.component import getMultiAdapter\n >>> from zope.publisher.browser import TestRequest\n\n >>> request = TestRequest()\n >>> view = getMultiAdapter((myblob, request), name='file_publish')\n >>> view\n \n\n >>> view.update()\n >>> for key, value in view.response.getHeaders(): print key, repr(value)\n X-Powered-By 'Zope (www.zope.org), Python (www.python.org)'\n Content-Length '7'\n Content-Type 'text/plain'\n Content-Disposition 'attachment; filename=\"data.txt\"'\n\n >>> view.render()\n \n\n\nProperty\n========\n\n.. attention::\n\n Please read `dolmen.file` README.txt for more information.\n\nThe persistency of the data can be handled, in complex object, by a\nFileField using a BlobProperty::\n\n >>> from persistent import Persistent\n >>> from dolmen.file import FileField\n >>> from dolmen.blob import BlobProperty\n >>> from zope.interface import Interface, implements\n\n >>> class IContent(Interface):\n ... binary = FileField(title=u\"Binary data\")\n\n >>> class MyContent(Persistent):\n ... implements(IContent)\n ... binary = BlobProperty(IContent['binary'])\n\n >>> root['mammoth'] = MyContent()\n >>> manfred = root['mammoth']\n >>> manfred.binary = 'Foobar'\n >>> manfred.binary\n \n\n >>> verify.verifyObject(IBlobFile, manfred.binary)\n True\n >>> ISized(manfred.binary).sizeForDisplay()\n u'1 KB'\n\n\nCopy using zope.copy\n====================\n\nA copy hook exists for IBlob objects. It allows to copy stored\nblobs transparently, while working with `zope.copy`::\n\n >>> import zope.copy\n\n >>> source = BlobFile(data='Some data here')\n >>> target = zope.copy.copy(source)\n >>> target.data\n 'Some data here'\n\nIt works recursiverly::\n\n >>> from zope.container.btree import BTreeContainer\n >>> root['gunther'] = BTreeContainer()\n >>> root['gunther']['mammoth'] = MyContent()\n\n >>> manfred = root['gunther']['mammoth']\n >>> manfred.binary = 'Some data with no interest'\n >>> manfred.binary.filename = u\"filename.txt\"\n >>> manfred.binary.mimeType = \"text/plain\"\n\n >>> copy_of_gunther = zope.copy.copy(root['gunther'])\n >>> judith = copy_of_gunther['mammoth']\n\n >>> judith.binary.data\n 'Some data with no interest'\n >>> judith.binary.filename\n u'filename.txt'\n >>> judith.binary.mimeType\n 'text/plain'\n\n\nChangelog\n=========\n\n0.5.0 (2010-02-28)\n------------------\n\n* Cleaned base code. We are now fully pep8 compliant.\n\n* ``dolmen.blob`` now has its own ``zope.filerepresentation``\n adapters, in order to use the natural getters and setters. We no\n longer need to include ``zope.file`` in the `configure.zcml`, as\n ``dolmen.blob`` now provides all the needed components to be\n independant.\n\n* Echoed ``dolmen.file`` changes and dropped ``zope.app.file`` support.\n\n* Dependency cleaned. Had to retain ``zope.app.testing`` and\n ``zope.app.appsetup`` since we need the ZODB support for the\n tests. All other zope.app dependencies have been severed.\n\n\n0.4.1 (2009-11-18)\n------------------\n\n* Now using Grok 1.1a1 versions.\n\n* zope.copy is no longer pinned down to version 3.5 but to 3.5 and\n greater.\n\n\n0.4 (2009-11-09)\n----------------\n\n* Added ICopyHook for ZODB.interfaces.IBlob objects. Now the data is\n copied using `zope.copy`.\n\n\n0.3 (2009-11-08)\n----------------\n\n* Added Blob to Blob copy, using a new storage. Added tests for this\n new storage.\n\n\n0.2.1 (2009-10-23)\n------------------\n\n* Corrected a bug of a variable used when not defined, if a mimeType\n was given using the contentType argument at the BlobValue creation.\n Added a test to fix this behavior.\n\n\n0.2 (2009-10-23)\n----------------\n\n* Added a bunch of new tests for the compatibility with the new\n packages used.\n\n* A new access view is available for `IBlobFile` objects, returning a\n `zope.file.download.DownloadResult`. This access view also uses\n an adapter to `zope.mimetype.interfaces.IContentInfo` to get the\n header values.\n\n* `IBlobFile` now inherits from `zope.file.interfaces.IFile`. This\n brings in a lot of new features, including the compatibility with\n the `zope.mimetype` package and its adapters.\n\n* `dolmen.blob` now proposes a non `Persistent` blob, called\n BlobValue. It allows to have object storing an attribute value in a\n blob, without getting an independant connection to the database\n (Blob already do that). The BlobProperty uses this new component\n now.\n\n\n0.1 (2009-10-19)\n----------------\n\n* Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "Grok Zope3 CMS Dolmen", "license": "GPL", "maintainer": null, "maintainer_email": null, "name": "dolmen.blob", "package_url": "https://pypi.org/project/dolmen.blob/", "platform": "Any", "project_url": "https://pypi.org/project/dolmen.blob/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/dolmen.blob/0.5.0/", "requires_dist": null, "requires_python": null, "summary": "Dolmen zodb blob handlers", "version": "0.5.0" }, "last_serial": 791327, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "dcbb7671aa7ce243f61c7b5c126975fd", "sha256": "70ac8b49ffd97fc039522ea9a24cf997496847ffb2f248b3d72be784546b30cf" }, "downloads": -1, "filename": "dolmen.blob-0.1.tar.gz", "has_sig": false, "md5_digest": "dcbb7671aa7ce243f61c7b5c126975fd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6368, "upload_time": "2009-10-20T23:28:23", "url": "https://files.pythonhosted.org/packages/b5/3e/44efec57db97af19f252b6c6c59d77893e1cf728db7ea6a7293a30d20990/dolmen.blob-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "91e822730b3fecbae94451cd9f73e76a", "sha256": "adab1a7e2af5825ead02e51e532ff4a45feef6e55a3241dcef4071cba656edb0" }, "downloads": -1, "filename": "dolmen.blob-0.2.tar.gz", "has_sig": false, "md5_digest": "91e822730b3fecbae94451cd9f73e76a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9417, "upload_time": "2009-10-23T15:50:13", "url": "https://files.pythonhosted.org/packages/0f/c9/409b4e3fcfd99c1892e15f0b10a52974859aa8143cb89912010ea79c65c1/dolmen.blob-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "9c2c8c85df04d0231df80d0e63a30906", "sha256": "881d4aec9b60fa557ff675743e5548c0aebbd7f994f95ddd7f61c6740e0372cc" }, "downloads": -1, "filename": "dolmen.blob-0.2.1.tar.gz", "has_sig": false, "md5_digest": "9c2c8c85df04d0231df80d0e63a30906", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9609, "upload_time": "2009-10-23T16:11:26", "url": "https://files.pythonhosted.org/packages/2b/f4/09509d8f3071196e92d469858c765cfc61dc1962708b199fd1bc222d5ec3/dolmen.blob-0.2.1.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "b2944434c7b6a223596c63e61e6b750f", "sha256": "682e6eee86ed6258df526a80af2ad32d1621a036abaee9aec1ca56ab403d6289" }, "downloads": -1, "filename": "dolmen.blob-0.3.tar.gz", "has_sig": false, "md5_digest": "b2944434c7b6a223596c63e61e6b750f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9868, "upload_time": "2009-11-08T19:38:22", "url": "https://files.pythonhosted.org/packages/15/48/d6f1f1d2f8be1fc9c93bb493b57b5f055fcc6b24cae537d128749d756600/dolmen.blob-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "4afb82ec067e74a6d3a44554371a35f3", "sha256": "2771f11719711e389978a14efd1696c47bc54de7e538ee446179994e50ba9ba4" }, "downloads": -1, "filename": "dolmen.blob-0.4.tar.gz", "has_sig": false, "md5_digest": "4afb82ec067e74a6d3a44554371a35f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9640, "upload_time": "2009-11-10T00:11:59", "url": "https://files.pythonhosted.org/packages/4c/b0/9da9d191046f4cb4ee4324adb85c95f8a584427c5957580d2004b187cbd5/dolmen.blob-0.4.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "81b9767aa7614235bea631c8eb731268", "sha256": "383ed5b926c899c4867f400f45eb6460ab4adc9ff52c754d01d5295e18238da0" }, "downloads": -1, "filename": "dolmen.blob-0.4.1.tar.gz", "has_sig": false, "md5_digest": "81b9767aa7614235bea631c8eb731268", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9772, "upload_time": "2009-11-18T17:58:52", "url": "https://files.pythonhosted.org/packages/69/ab/f394d296cc3e5b124bd9a26b3e0285dca97be27c090a243ffb0615f2611e/dolmen.blob-0.4.1.tar.gz" } ], "0.5.0": [ { "comment_text": "", "digests": { "md5": "c8431e0b3c88ed5f6ceaa31e57685014", "sha256": "451c342fcabe5deb86e030cbf8644e85153bdd8cf3326dc0fc2c550ca1a30454" }, "downloads": -1, "filename": "dolmen.blob-0.5.0.tar.gz", "has_sig": false, "md5_digest": "c8431e0b3c88ed5f6ceaa31e57685014", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13531, "upload_time": "2010-02-28T18:52:13", "url": "https://files.pythonhosted.org/packages/15/af/f9a69235dc3ef9c44ddbf1ced7e00345315b4ab58fc3c7bb2e02cd2ddd39/dolmen.blob-0.5.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c8431e0b3c88ed5f6ceaa31e57685014", "sha256": "451c342fcabe5deb86e030cbf8644e85153bdd8cf3326dc0fc2c550ca1a30454" }, "downloads": -1, "filename": "dolmen.blob-0.5.0.tar.gz", "has_sig": false, "md5_digest": "c8431e0b3c88ed5f6ceaa31e57685014", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13531, "upload_time": "2010-02-28T18:52:13", "url": "https://files.pythonhosted.org/packages/15/af/f9a69235dc3ef9c44ddbf1ced7e00345315b4ab58fc3c7bb2e02cd2ddd39/dolmen.blob-0.5.0.tar.gz" } ] }