{ "info": { "author": "Dolmen Team", "author_email": "dolmen@list.dolmen-project.org", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "=================\ndolmen.collection\n=================\n\nDolmen collection offers a collection implementation which permits to \nmanipulate named elements: arrange order, extract part of the collection,\nenforce a type of component and add new ones easily.\n\nIt originated from zeam.form where it was used to implement forms as \ncollections of fields, actions and widgets.\n\n.. contents::\n\n\nAPI description\n===============\n\nComponents\n----------\n\nFirst let's see the component, that is elements taking parts in collections::\n\n >>> from dolmen.collection.components import Component\n >>> c1 = Component(u'The Sun', 'sun')\n >>> c1\n \n >>> c1.identifier\n 'sun'\n >>> c1.title\n u'The Sun'\n\nIt correctly implement IComponent::\n\n >>> from zope.interface.verify import verifyObject\n >>> from dolmen.collection import interfaces\n >>> verifyObject(interfaces.IComponent, c1)\n True\n\nActually you can create a component without an id, and even using a\nunicode title::\n\n >>> c2 = Component(u'Moon')\n >>> c2\n \n >>> c2.identifier\n 'moon'\n >>> c2.title\n u'Moon'\n\nOr a number (it won't be converted to string. Like this, this support\nZope translation messages)::\n\n >>> c69 = Component(69)\n >>> c69.title\n 69\n\nIf by doing so, the title contain spaces, they will be replaced by\n``-``. If UTF-8 character are included, the identifiant will be\nencoded::\n\n >>> c3 = Component(u'Some lost planet')\n >>> c3.identifier\n 'some-lost-planet'\n >>> c4 = Component(u'\u00c9tat du d\u00e9sir')\n >>> c4.identifier\n 'c383c2897461742d64752d64c383c2a9736972'\n\nSpaces are normalized::\n\n >>> c5 = Component(' Some unappropriate spacing ')\n >>> c5.identifier\n 'some-unappropriate-spacing'\n\nYou can clone a component and change its identifier::\n\n >>> c3clone = c3.clone('new-world')\n >>> c3clone\n \n >>> c3clone.identifier\n 'new-world'\n >>> c3clone is c3\n False\n\nBut you can keep the old one as well::\n\n >>> c4clone = c4.clone()\n >>> c4clone.identifier\n 'c383c2897461742d64752d64c383c2a9736972'\n >>> c4clone is c4\n False\n\n\nCollection\n----------\n\nCollection are simple objects, implementing ICollection::\n\n >>> from dolmen.collection.components import Collection\n >>> s1 = Collection()\n >>> s1\n \n >>> len(s1)\n 0\n >>> verifyObject(interfaces.ICollection, s1)\n True\n\nAdding components to a collection\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nNow we can put components in a collection, and list it back in the\nsame order::\n\n >>> s1.append(c1)\n >>> list(s1)\n []\n >>> s1.append(c2)\n >>> list(s1)\n [, ]\n\nBut you can't add twice the same component::\n\n >>> s1.append(c1)\n Traceback (most recent call last):\n ...\n ValueError: (u'Duplicate identifier', 'sun')\n\nAnd this need to be a component::\n\n >>> s1.append('home')\n Traceback (most recent call last):\n ...\n TypeError: (u'Invalid type', 'home')\n\nYou create a collection with components or collection as argument::\n\n >>> s2 = Collection(Component('Jupiter'), Component('Saturn'))\n >>> list(s2)\n [, ]\n >>> len(s2)\n 2\n >>> list(Collection(s2, Component('Uranus')))\n [, , ]\n >>> Collection(42)\n Traceback (most recent call last):\n ...\n TypeError: (u'Invalid type', 42)\n\nYou can add collections. You will receive a copy with all\ncomponents. Components will ordered as the addition is::\n\n >>> s3 = s1 + s2\n >>> s3\n \n >>> s3 is s1\n False\n >>> list(s3)\n [, ,\n , ]\n >>> len(s3)\n 4\n >>> list(s2 + s1)\n [, ,\n , ]\n\nYou can extend a collection. It work pretty much like the construtor::\n\n >>> s3.extend(Component('Venus'), Component('Uranus'))\n >>> list(s3)\n [, ,\n , ,\n , ]\n >>> s3.extend('Kitty')\n Traceback (most recent call last):\n ...\n TypeError: (u'Invalid type', 'Kitty')\n\nYou can copy a collection::\n\n >>> s3copy = s3.copy()\n >>> list(s3copy) == list(s3)\n True\n >>> s3copy is s3\n False\n\nYou can remove all elements from a collection::\n\n >>> len(s1)\n 2\n >>> s1.clear()\n >>> len(s1)\n 0\n\nIgnoring already defined components\n...................................\n\n >>> from dolmen.collection.components import IGNORE \n >>> ignoring = Collection()\n >>> ignoring.behavior = IGNORE\n \n >>> ignoring.append(c1)\n >>> list(ignoring)\n []\n >>> ignoring.append(c2)\n >>> list(ignoring)\n [, ]\n\n >>> c1prime = Component(u'The Sun prime', 'sun')\n \nYou can add twice the same component, the second is ignored::\n\n >>> ignoring.append(c1prime)\n >>> list(ignoring)\n [, ]\n\n\nOverriding already defined components\n.....................................\n\n >>> from dolmen.collection.components import OVERRIDE \n >>> overriding = Collection()\n >>> overriding.behavior = OVERRIDE\n\n >>> overriding.append(c1)\n >>> list(overriding)\n []\n >>> overriding.append(c2)\n >>> list(overriding)\n [, ]\n\n >>> c1prime = Component(u'The Sun prime', 'sun')\n \nYou can add twice the same component, the second overrides the first::\n\n >>> overriding.append(c1prime)\n Traceback (most recent call last):\n ...\n NotImplementedError\n\nIt needs to be a IMutableCollection::\n\n >>> from dolmen.collection import IMutableCollection\n >>> from zope.interface import directlyProvides\n >>> directlyProvides(overriding, IMutableCollection)\n\n >>> overriding.append(c1prime)\n >>> list(overriding)\n [, ]\n\n\nRetriving components from a collection\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can retrieve one element of the collection::\n\n >>> s3.get('moon')\n \n >>> s3.get('uranus')\n \n >>> s3.get('me')\n Traceback (most recent call last):\n ...\n KeyError: 'me'\n >>> s3.get('me', default=42)\n 42\n\nAnd dictionnary like access works::\n\n >>> s3['uranus']\n \n >>> s3['venus']\n \n >>> s3['somewhere']\n Traceback (most recent call last):\n ...\n KeyError: 'somewhere'\n\nYou can get all components ids::\n\n >>> s3.keys()\n ['sun', 'moon', 'jupiter', 'saturn', 'venus', 'uranus']\n\nYou can test if a component id is in the collection::\n\n >>> 'moon' in s3\n True\n >>> 'earth' in s3\n False\n\nYou can get a new collection with some of the components of the first\none::\n\n >>> s4 = s3.select('venus', 'uranus')\n >>> s4 is s3\n False\n >>> list(s4)\n [, ]\n >>> s4.keys()\n ['venus', 'uranus']\n\nOr the other way around some components of a collection::\n\n >>> s5 = s3.omit('sun', 'moon')\n >>> s5 is s3\n False\n >>> list(s5)\n [, ,\n , ]\n\n\nSorting components in a collection\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe Collection sort call works as the standard python list's one::\n\n >>> s5.sort()\n >>> print list(s5)\n [, , ,\n ]\n\n\nWe can use the standard arguments (cmp, key and reverse)::\n\n >>> s5.sort(reverse=True)\n >>> print list(s5)\n [, , ,\n ]\n\n >>> s5.sort(reverse=True, key=lambda el: el.identifier[-1:])\n >>> print list(s5)\n [, , ,\n ]\n\n >>> def myLengthSort(a1, a2):\n ... return cmp(len(a1), len(a2))\n\n >>> s5.sort(reverse=True, key=lambda el: el.identifier, cmp=myLengthSort)\n >>> print list(s5)\n [, , ,\n ]\n\nThe collection can be reversed too, as standard lists::\n\n >>> s5.reverse()\n >>> print list(s5)\n [, , ,\n ]\n\n\nIt is possible to order the components of a Collection using\na given list of ids and the `sort_components` cmp function::\n\n >>> from dolmen.collection import sort_components\n\n >>> s5.sort(sort_components(['uranus', 'venus', 'jupiter']))\n >>> print list(s5)\n [, , ,\n ]\n\nThe keys are sorted in the process::\n\n >>> print s5.keys()\n ['uranus', 'venus', 'jupiter', 'saturn']\n\nSuccessive sortings will leave unspecified fields at their relative places::\n\n >>> s5.sort(sort_components(['saturn', 'uranus']))\n >>> print list(s5)\n [, , ,\n ]\n\nWe can also revert the sorting, as the standard python behavior::\n\n >>> s5.sort(sort_components(['uranus', 'venus']), reverse=True)\n >>> print list(s5)\n [, , ,\n ]\n\nErrors are raised if the provided list is malformed or smaller than 2\nelements::\n\n >>> s5.sort(sort_components(['uranus']))\n Traceback (most recent call last):\n ...\n ValueError: Please provide a list of, at least, two component identifiers.\n\n >>> s5.sort(sort_components('something'))\n Traceback (most recent call last):\n ...\n ValueError: Please provide a valid list or tuple of component identifiers.\n\n\nThe behavior, if unknow ids are provided, is unchanged::\n\n >>> s5.sort(sort_components(['venus', 'uranus', 'cardassia', 'bajor']))\n >>> print list(s5)\n [, , ,\n ]\n\n\nParameters on collections\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can provides extra parameters on collections that will be set as\nattributes on the object::\n\n >>> s6 = Collection(s2, name=u'me', city=u'rotterdam')\n >>> s6\n \n >>> list(s6)\n [, ]\n >>> s6.name\n u'me'\n >>> s6.city\n u'rotterdam'\n\nThose attributes are kept if you use the operations ``select``,\n``omit`` or ``copy``::\n\n >>> s6copy = s6.copy()\n >>> s6copy.name\n u'me'\n >>> s6copy.city\n u'rotterdam'\n\n >>> s6omit = s6.omit('jupiter')\n >>> s6omit.name\n u'me'\n >>> s6omit.city\n u'rotterdam'\n\n >>> s6select = s6.select('jupiter')\n >>> s6select.name\n u'me'\n >>> s6select.city\n u'rotterdam'\n\n\nChanges\n=======\n\n0.3 (2011-06-13)\n----------------\n\n* Added behavior to the collection allowing the override or ignore of the\n components.\n\n\n0.2 (2011-04-14)\n----------------\n\n* Updated components names for entry points.\n\n\n0.1 (2011-04-13)\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": "http://pypi.python.org/pypi/dolmen.collection", "keywords": "collection library", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "dolmen.collection", "package_url": "https://pypi.org/project/dolmen.collection/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dolmen.collection/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/dolmen.collection" }, "release_url": "https://pypi.org/project/dolmen.collection/0.3/", "requires_dist": null, "requires_python": null, "summary": "Collection of named entities", "version": "0.3" }, "last_serial": 791329, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "8891f3bad8ab88c0c05822acb2d11f59", "sha256": "bc76a1f9181d4551ddc820d9949cd8c4f6124e53faa0c88324e462be9bc4f5d2" }, "downloads": -1, "filename": "dolmen.collection-0.1.tar.gz", "has_sig": false, "md5_digest": "8891f3bad8ab88c0c05822acb2d11f59", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8223, "upload_time": "2011-04-13T17:47:57", "url": "https://files.pythonhosted.org/packages/b1/d7/cf13f86095bd0959d4bb00f05553a9439d19331b5bfe50a14b9739c3cd37/dolmen.collection-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "96878e8ffe67cdc1e07e4e8992697f15", "sha256": "2c3d68ef2f5387dd2b22cbd2b3aef4425e4c54b8621f9af5cd92a2eb493fd5f0" }, "downloads": -1, "filename": "dolmen.collection-0.2.tar.gz", "has_sig": false, "md5_digest": "96878e8ffe67cdc1e07e4e8992697f15", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9551, "upload_time": "2011-04-14T11:33:24", "url": "https://files.pythonhosted.org/packages/1e/a3/038f14953cb1017b66521fb6267a0a5eee23c83fdb1526caf904220bd88c/dolmen.collection-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "8a2843e7d84a98cfc74ab32cb8144b5b", "sha256": "ae426143248c5ab582e235694d74e97cbf3ed1a9ef5f8606a2851e0c495cd070" }, "downloads": -1, "filename": "dolmen.collection-0.3.tar.gz", "has_sig": false, "md5_digest": "8a2843e7d84a98cfc74ab32cb8144b5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10335, "upload_time": "2011-06-13T17:47:35", "url": "https://files.pythonhosted.org/packages/0e/a5/5ae5dd0a69bf7b0ddca0170e7d44992fb39e54f2a6ed049f1882eb8fd85e/dolmen.collection-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a2843e7d84a98cfc74ab32cb8144b5b", "sha256": "ae426143248c5ab582e235694d74e97cbf3ed1a9ef5f8606a2851e0c495cd070" }, "downloads": -1, "filename": "dolmen.collection-0.3.tar.gz", "has_sig": false, "md5_digest": "8a2843e7d84a98cfc74ab32cb8144b5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10335, "upload_time": "2011-06-13T17:47:35", "url": "https://files.pythonhosted.org/packages/0e/a5/5ae5dd0a69bf7b0ddca0170e7d44992fb39e54f2a6ed049f1882eb8fd85e/dolmen.collection-0.3.tar.gz" } ] }