{ "info": { "author": "Zope Corporation and Contributors", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Zope", "Framework :: Zope :: 3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP" ], "description": "This package provides simple sequence batching.\n\n\n======================\nDetailed Documentation\n======================\n\n\n\n.. contents::\n\nSimple Batching\n---------------\n\nThis module implements a simple batching mechanism that allows you to split a\nlarge sequence into smaller batches. Let's start by creating a simple list,\nwhich will be our full sequence:\n\nBatch on empty root:\n\n >>> from z3c.batching.batch import Batch\n >>> batch = Batch([], size=3)\n >>> len(batch)\n 0\n >>> bool(batch)\n False\n >>> batch.firstElement\n Traceback (most recent call last):\n ...\n IndexError: ...\n\n >>> batch.lastElement\n Traceback (most recent call last):\n ...\n IndexError: ...\n\n >>> batch[0]\n Traceback (most recent call last):\n ...\n IndexError: ...\n\n >>> batch.next is None\n True\n\n >>> batch.previous is None\n True\n\n\n >>> sequence = ['one', 'two', 'three', 'four', 'five', 'six', 'seven',\n ... 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen']\n\nWe can now create a batch for this sequence. Let's make our batch size 3:\n\n >>> batch = Batch(sequence, size=3)\n\nThe first argument to the batch is always the full sequence. If no start\nelement is specified, the batch starts at the first element:\n\n >>> list(batch)\n ['one', 'two', 'three']\n\nThe start index is commonly specified in the constructor though:\n\n >>> batch = Batch(sequence, start=6, size=3)\n >>> list(batch)\n ['seven', 'eight', 'nine']\n\nNote that the start is an index and starts at zero. If the start index is\ngreater than the largest index of the sequence, an index error is raised:\n\n >>> Batch(sequence, start=15, size=3)\n Traceback (most recent call last):\n ...\n IndexError: start index key out of range\n\nA batch implements the finite sequence interface and thus supports some\nstandard methods. For example, you can ask the batch for its length:\n\n >>> len(batch)\n 3\n\nNote that the length returns the true size of the batch, not the size we asked\nfor:\n\n >>> len(Batch(sequence, start=12, size=3))\n 1\n\nLike any sequence, a non-empty batch is true-ish in a boolean context:\n\n >>> bool(batch)\n True\n\nYou can also get an element by index, which is relative to the batch:\n\n >>> batch[0]\n 'seven'\n >>> batch[1]\n 'eight'\n >>> batch[2]\n 'nine'\n\nSlicing:\n\n >>> batch[:1]\n ['seven']\n\n >>> batch[1:2]\n ['eight']\n\n >>> batch[1:]\t\n ['eight', 'nine']\n\n >>> batch[:]\n ['seven', 'eight', 'nine']\n\n >>> batch[10:]\n []\n\n\nIf you ask for index that is out of range, an index error is raised:\n\n >>> batch[3]\n Traceback (most recent call last):\n ...\n IndexError: batch index out of range\n\nYou can also iterate through the batch:\n\n >>> iterator = iter(batch)\n >>> next(iterator)\n 'seven'\n >>> next(iterator)\n 'eight'\n >>> next(iterator)\n 'nine'\n\nBatch also implement some of IReadSequence interface:\n\n >>> 'eight' in batch\n True\n\n >>> 'ten' in batch\n False\n\n >>> batch == Batch(sequence, start=6, size=3)\n True\n\n >>> batch != Batch(sequence, start=6, size=3)\n False\n\n >>> batch != Batch(sequence, start=3, size=3)\n True\n\nBesides all of those common API methods, there are several properties that were\ndesigned to make your life simpler. The start and size are specified:\n\n >>> batch.start\n 6\n >>> batch.size\n 3\n\nThe end index of the batch is immediately computed:\n\n >>> batch.end\n 8\n\nThe UI often requires that the number of the batch and the total number of\nbatches is computed:\n\n >>> batch.number\n 3\n >>> batch.total\n 5\n\nYou can also ask for the next batch:\n\n >>> batch.next\n \n\nIf the current batch is the last one, the next batch is None:\n\n >>> Batch(sequence, start=12, size=3).next is None\n True\n\nThe previous batch shows the previous batch:\n\n >>> batch.previous\n \n\nIf the current batch is the first one, the previous batch is None:\n\n >>> Batch(sequence, start=0, size=3).previous is None\n True\n\nThe final two properties deal with the elements within the batch. They ask for\nthe first and last element of the batch:\n\n >>> batch.firstElement\n 'seven'\n\n >>> batch.lastElement\n 'nine'\n\n\nTotal batches:\n\n >>> batch = Batch(sequence[:-1], size=3)\n >>> batch.total\n 4\n\nWe can have access to all batches:\n\n >>> len(batch.batches)\n 4\n\n >>> batch.batches[0]\n \n\n >>> batch.batches[3]\n \n\n >>> batch.batches[4]\n Traceback (most recent call last):\n ...\n IndexError: ...\n\n >>> batch.batches[-1]\n \n\n >>> batch.batches[-2]\n \n\nSlicing:\n\n >>> batch.batches[:1]\n []\n\n >>> batch.batches[:]\n [, , , ]\n\n >>> batch.batches[1:2]\n []\n\n >>> batch.batches[1:]\n [, , ]\n\n >>> batch.batches[10:]\n []\n\n >>> batch.batches[2:50]\n [, ]\n\nBatch neighbourhood of a large batch list\n-----------------------------------------\n\nWhen the full list of batches is too large to be displayed in a user interface,\nwe want to display only a subset of all the batches.\nA helper function is provided for that purpose:\n\nFirst build a large sequence of batches (or anything else):\n\n >>> batches = range(100)\n\nThen extract only the first and last items, as well as the neighbourhood of the\n46th item (index = 45). We want 3 neighbours at the left, 5 at the right:\n\n >>> from z3c.batching.batch import first_neighbours_last\n >>> first_neighbours_last(batches, 45, 3, 5)\n [0, None, 42, 43, 44, 45, 46, 47, 48, 49, 50, None, 99]\n\n'None' can be used to display a separator in a user interface (see z3c.table) \n\n\n\nSubset Batching\n---------------\n\n >>> from z3c.batching.subset import SubsetBatch\n\nSometimes (for performance reasons), even though the user needs\na batched UI, we want to limit the computation to the\nsubset of values actually shown to the user.\n\nBecause we initialize the batch with a subset of data, we also\nneed to provide explicitly the length of the full data set.\n\nLet's create a subset of data::\n\n >>> data = range(20, 30)\n\nWe use it as part of a longer data set::\n\n >>> batch = SubsetBatch(data, length=50, start=20, size=10)\n\nFull API check::\n\n >>> batch.firstElement\n 20\n >>> batch.lastElement\n 29\n >>> batch.index\n 2\n >>> batch.number\n 3\n >>> batch.total\n 5\n >>> batch[2]\n 22\n >>> len(batch)\n 10\n >>> batch[-1] == batch.lastElement\n True\n >>> [item for item in batch]\n [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]\n\n >>> batch.next\n \n >>> batch.previous\n \n >>> batch.next.previous == batch\n True\n >>> 22 in batch\n True\n >>> 10 in batch\n False\n >>> batch[5:8]\n [25, 26, 27]\n\nYou have seen above that the contiguous batches are instances of\nthe ``EmptyBatch`` class. As those instances hold no data, we raise errors to ensure that no batch provider tries to display item data::\n\n >>> empty = batch.next\n >>> empty\n \n >>> empty.firstElement\n Traceback (most recent call last):\n ...\n ValueError: EmptyBatch holds no item\n >>> empty.lastElement\n Traceback (most recent call last):\n ...\n ValueError: EmptyBatch holds no item\n >>> empty[0]\n Traceback (most recent call last):\n ...\n ValueError: EmptyBatch holds no item\n >>> [item for item in empty]\n Traceback (most recent call last):\n ...\n ValueError: EmptyBatch holds no item\n\n\n=======\nCHANGES\n=======\n\n2.2 (2018-10-20)\n----------------\n\n- Add support for Python 3.6, 3.7 and PyPy3.\n\n- Drop support for Python 2.6 and 3.3.\n\n\n2.1.0 (2016-06-05)\n------------------\n\n- Support Python 3.3 through 3.5.\n\n\n2.0.1 (2015-11-09)\n------------------\n\n- Standardize namespace __init__\n\n2.0.0 (2013-02-25)\n------------------\n\n- New feature: Subset batch.\n Sometimes (for performance reasons), even though the user needs\n a batched UI, we want to limit the computation to the\n subset of values actually shown to the user.\n\n- Register `batch.Batch` as named (``\"z3c.batching.batch\"``) factory.\n\n1.1.0 (2008-11-12)\n------------------\n\n- Added a function to build a small neighbourhood list of the current batch,\n from a large batch list. (extracted from z3c.table)\n\n- Really fixed the bug with batches slicing\n\n1.0.1 (2008-09-09)\n------------------\n\n- Fixed bug with batches slicing.\n\n\n1.0.0 (2008-02-18)\n------------------\n\n- Initial release.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/zopefoundation/z3c.batching", "keywords": "zope3 batching", "license": "ZPL 2.1", "maintainer": "", "maintainer_email": "", "name": "z3c.batching", "package_url": "https://pypi.org/project/z3c.batching/", "platform": "", "project_url": "https://pypi.org/project/z3c.batching/", "project_urls": { "Homepage": "https://github.com/zopefoundation/z3c.batching" }, "release_url": "https://pypi.org/project/z3c.batching/2.2/", "requires_dist": [ "setuptools", "zope.interface", "zope.schema" ], "requires_python": "", "summary": "List batching support", "version": "2.2" }, "last_serial": 4396562, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "e6fef7b5eb8c94d230e0a0a2358b18c1", "sha256": "8d1b00653ae235bfa10a94bf7412b723f25fcb1e5b319fc162124323e7917178" }, "downloads": -1, "filename": "z3c.batching-1.0.0.tar.gz", "has_sig": false, "md5_digest": "e6fef7b5eb8c94d230e0a0a2358b18c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7429, "upload_time": "2008-02-18T10:16:35", "url": "https://files.pythonhosted.org/packages/90/c3/bf144b37a43e53df3947f859b57a841fdeba3422ea20506f50f7b830f41e/z3c.batching-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d69d9d131f1cf368d56b6c560fd46886", "sha256": "091c5341733b052432371f0ae0c42ffc70cd0b76e213894b694a7a28133a1c79" }, "downloads": -1, "filename": "z3c.batching-1.0.1.tar.gz", "has_sig": false, "md5_digest": "d69d9d131f1cf368d56b6c560fd46886", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7637, "upload_time": "2008-09-09T10:35:38", "url": "https://files.pythonhosted.org/packages/a0/e1/fc80356c0d16c74dd179e8ed3fbf3803e8fed24bb91a69120292115e7a08/z3c.batching-1.0.1.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "d1dc834781d228127ca6d15301757863", "sha256": "a40bebf6a3faec64921f94c583b4fc330b3d8e50e875abd0a8697fef25c281f6" }, "downloads": -1, "filename": "z3c.batching-1.1.0.tar.gz", "has_sig": false, "md5_digest": "d1dc834781d228127ca6d15301757863", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8467, "upload_time": "2008-10-12T14:50:08", "url": "https://files.pythonhosted.org/packages/19/b2/8e5286b1198c3c2a9f967dfaf83d6daf8d0f974f249a0cea0860eba11305/z3c.batching-1.1.0.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "a19e3c152574e056dae613bc4ae0f225", "sha256": "8f3fbffef321988600c2b90c30aa17c1e54ee8166d032ec05049964398b40af2" }, "downloads": -1, "filename": "z3c.batching-2.0.0.zip", "has_sig": false, "md5_digest": "a19e3c152574e056dae613bc4ae0f225", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22500, "upload_time": "2013-02-25T12:27:24", "url": "https://files.pythonhosted.org/packages/b5/06/2477e7b253fcde3f7920f2aa08567f7e46d8cd3e0026189623cad69d9a4d/z3c.batching-2.0.0.zip" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "777a04877168814c779877ad5db9b827", "sha256": "e0d6a5f2ebde561856d0344bb94de43259f3013d869783415199334daf3ed53a" }, "downloads": -1, "filename": "z3c.batching-2.0.1.tar.gz", "has_sig": false, "md5_digest": "777a04877168814c779877ad5db9b827", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15469, "upload_time": "2015-11-09T16:31:17", "url": "https://files.pythonhosted.org/packages/58/d3/171ca0d3741eba55e493aeecef9673a9c1de920ef2a3c4fbfa2a6cca817c/z3c.batching-2.0.1.tar.gz" } ], "2.1.0": [ { "comment_text": "", "digests": { "md5": "ca22e482a8009b80bcd08cd20766b4da", "sha256": "24a99badd21ced028cd37fac258466721a3170e1c4ed9ccd3276b5c737642bda" }, "downloads": -1, "filename": "z3c.batching-2.1.0.tar.gz", "has_sig": false, "md5_digest": "ca22e482a8009b80bcd08cd20766b4da", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16175, "upload_time": "2016-06-05T08:55:15", "url": "https://files.pythonhosted.org/packages/a7/98/26875d5a32b153e39dd480fb2a204f0cd9f7746ed57905f7ed76d9b7bf21/z3c.batching-2.1.0.tar.gz" } ], "2.2": [ { "comment_text": "", "digests": { "md5": "029e9bc286704a246ae4a79950b0354c", "sha256": "0290bc5914ecbebf58a793edf6c45a49aac9a44e448f52d002a815834ca38ade" }, "downloads": -1, "filename": "z3c.batching-2.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "029e9bc286704a246ae4a79950b0354c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17367, "upload_time": "2018-10-20T05:45:04", "url": "https://files.pythonhosted.org/packages/b0/5b/17a628a0744b4471f1bfdddf25538e17efebca40dffbe187b222537c018c/z3c.batching-2.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f58c8578df2a3d5aaff536b65f754cf2", "sha256": "9ad3b9851efc28ae62758d1092a217d3dc54920cbcf7e7ecd837277b2e8e94fa" }, "downloads": -1, "filename": "z3c.batching-2.2.tar.gz", "has_sig": false, "md5_digest": "f58c8578df2a3d5aaff536b65f754cf2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15671, "upload_time": "2018-10-20T05:45:06", "url": "https://files.pythonhosted.org/packages/e2/c9/46fb0930c55156329fa1c883bae15907194263057037f8f5efb7bd8dafeb/z3c.batching-2.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "029e9bc286704a246ae4a79950b0354c", "sha256": "0290bc5914ecbebf58a793edf6c45a49aac9a44e448f52d002a815834ca38ade" }, "downloads": -1, "filename": "z3c.batching-2.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "029e9bc286704a246ae4a79950b0354c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17367, "upload_time": "2018-10-20T05:45:04", "url": "https://files.pythonhosted.org/packages/b0/5b/17a628a0744b4471f1bfdddf25538e17efebca40dffbe187b222537c018c/z3c.batching-2.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f58c8578df2a3d5aaff536b65f754cf2", "sha256": "9ad3b9851efc28ae62758d1092a217d3dc54920cbcf7e7ecd837277b2e8e94fa" }, "downloads": -1, "filename": "z3c.batching-2.2.tar.gz", "has_sig": false, "md5_digest": "f58c8578df2a3d5aaff536b65f754cf2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15671, "upload_time": "2018-10-20T05:45:06", "url": "https://files.pythonhosted.org/packages/e2/c9/46fb0930c55156329fa1c883bae15907194263057037f8f5efb7bd8dafeb/z3c.batching-2.2.tar.gz" } ] }