{
"info": {
"author": "Sam et Max",
"author_email": "lesametlemax@gmail.com",
"bugtrack_url": null,
"classifiers": [
"Intended Audience :: Information Technology",
"License :: OSI Approved :: zlib/libpng License",
"Natural Language :: English",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7"
],
"description": "*************************************************************\nA collection of gagdets that makes Python even more powerful\n*************************************************************\n\nThere is not real structure for this lib, it's just a bunch of snippets I put together because I use them often.\n\nNot all of them are documented here, few of them have tests, it's zlib licence, you know the drill...\n\n\nTo timestamp\n=============\n\ndatetime.fromtimestamp exists but not the other away around, and it's not likely to change anytime soon (see: http://bugs.python.org/issue2736). In the meantime::\n\n >>> from datetime import datetime\n >>> to_timestamp(datetime(2000, 1, 1, 2, 1, 1))\n 946692061\n >>> datetime.fromtimestamp(946688461) # tu as cod\u00e9 celle l\u00e0 et pas l'autre connard !\n datetime.datetime(2000, 1, 1, 2, 1, 1)\n\n\nGet this nest value or a default\n=================================\n\nDon't::\n\n try:\n res = data['key'][0]['other key'][1]\n except (KeyError, IndexError):\n res = \"value\"\n\n\nDo::\n\n get(data, 'key', 0, 'other key, 1, default=\"value\")\n\n\nFor attributes::\n\n devise = attr(car, 'insurance', 'expiration_date', 'timezone')\n\n\nIteration tools missing in itertools\n===================================================================================\n\n\nIteration by chunk or with a sliding window::\n\n >>> for chunk in chunks(l, 3):\n ... print list(chunk)\n ...\n [0, 1, 2]\n [3, 4, 5]\n [6, 7, 8]\n [9]\n >>> for slide in window(l, 3):\n ... print list(slide)\n ...\n [0, 1, 2]\n [1, 2, 3]\n [2, 3, 4]\n [3, 4, 5]\n [4, 5, 6]\n [5, 6, 7]\n [6, 7, 8]\n [7, 8, 9]\n\n\nGet the first element an any iterable (not just indexable) or the first one to be True::\n\n >>> first(xrange(10))\n 0\n >>> first_true(xrange(10))\n 1\n >>> first([], default=\"What the one thing we say to the God of Death ?\")\n 'What the one thing we say to the God of Death ?'\n\nSorted Set\n===================================================================================\n\nSlow but useful data structure::\n\n >>> for x in sset((3, 2, 2, 2, 1, 2)):\n ... print x\n ...\n 3\n 2\n 1\n\n\nDictionaries one liners\n===================================================================================\n\n\nI wish + was overloaded for dicts::\n\n >>> dmerge({\"a\": 1, \"b\": 2}, {\"b\": 2, \"c\": 3})\n {'a': 1, 'c': 3, 'b': 2}\n\n\nSometimes you do not want to simply overwrite the values inside the original dict, but merge them in custom fashion::\n\n >>> def my_merge(v1, v2):\n ... if isinstance(v1, dict) and isinstance(v2, dict):\n ... return dmerge(v1, v2)\n ... return v2\n >>> dmerge({\"a\": 1, \"b\": {'ok': 5}}, {\"b\": {'ko': 5 }, \"c\": 3}, my_merge)\n {'a': 1, 'c': 3, 'b': {'ko': 5, 'ok': 5}}\n\nOriginal dicts are not modified, but this will modify them::\n\n >>> from batbelt.structs import rename\n >>> rename({\"a\": 1, \"b\": 2})\n >>> rename({\"a\": 1, \"b\": 2}, 'b', 'z')\n {u'a': 1, u'z': 2}\n\n(not thread safe).\n\nTwited but satisfying::\n\n >>> from batbelt.structs import unpack\n >>> dct = {'a': 2, 'b': 4, 'z': 42}\n >>> a, b, c = unpack(dct, 'a', 'b', 'c', default=1)\n >>> a\n 2\n >>> b\n 4\n >>> c\n 1\n\n\nString tools\n===================================================================================\n\nThe mandatory \"slufigy\"::\n\n >>> slugify(u\"H\u00e9lo Whorde\")\n helo-whorde\n\nYou get better slugification if you install the `unidecode` lib, but it's optional. You can specify `separator` if you don't like `-` or call directly `normalize()` (the underlying function) if you wish more control.\n\nThe module also feature html_escape/unescape that is not useless and json_dumps/loads that understand datetime by default. Look at the source for these, I'm lazy (PL for documentation are welcome).\n\nThere is also a poor man template system using the `format()` string method on a file content. No loop, but still nice for quick and dirty file generation :\n\n from batbelt.strings import render\n\n render('stuff.conf.tpl', {\"var\": \"value\"}, \"/etc/stuff.conf\")\n\n\nImport this\n===================================================================================\n\n\n`__import__` is weird. Let's abstract that ::\n\n TaClasse = import_from_path('foo.bar.TaClasse')\n ton_obj = TaClasse()\n\n\nCatpure prints\n===================================================================================\n\n\nA context manager to deal with this libs that print the result instead of returning it :\n\n\n >>> with capture_ouput() as (stdout, stderr):\n ... print \"hello\",\n ...\n >>> print stdout.read()\n hello\n >>> stdout.close()\n\n\nCreate a decorator that accept arguments\n===================================================================================\n\n\nI never remember how to do this. And I don't have to anymore.\n\nFirst, write the decorator::\n\n # all arguments after 'func' are your decorator argument\n @decorator_with_args()\n def your_decorator(func, arg1, arg2=None):\n\n if arg1:\n # do stuff here\n\n # do your usual decorator jimbo jumbo, wrapping, calling, returning...\n def wrapper():\n return func(arg2)\n\n\n return wrapper\n\n\n\nEnjoy :\n\n @your_decorator(False, 1)\n def hop(un_arg):\n # do stuff in the decorated function\n\n\n\nAdd a any directory to the PYTHON PATH\n===========================================\n\nAccepts shell variables and relative paths :\n\n from batbelt.utils import add_to_pythonpath\n add_to_pythonpath(\"~/..\")\n\nYou can (and probably wants) specify a starting point if you pass a relative path. The default starting point is the result is `os.getcwd()` while you probably wants the directory containing you script. To to so, pass `__file__`:\n\n add_to_pythonpath(\"../..\", starting_point=__file__)\n\n`starting_point` can be a file path (basename will be stripped) or a directory name. If will be from there that the reltive path will be calculated.\n\nYou can also choose where in the `sys.path` list the your path will be added by passing `insertion_index`, which default to the after the last existing item.\n\n\nPoor man task queue\n===================================================================================================\n\n\nYou don't always need the guaranty of a big lib, you just need a little worker to do the job outside of the main thread::\n\n\n\n from batbelt.parallel import worker\n\n @worker()\n def task(arg):\n arg = arg + 10\n return arg\n\n\n # start the worker\n process = task.start()\n\n # send tasks\n for x in range(10):\n process.put(x)\n\n # (optionaly) get results\n for x in range(10):\n print process.get()\n\n ## 10\n ## 11\n ## 12\n ## 13\n ## 14\n ## 15\n ## 16\n ## 17\n ## 18\n ## 19\n\n # stop the worker\n process.stop()\n\nLe worker use subprocess by default, but if you prefer threads: `@worker(method=\"tread\")`.\n\nIf you look for it in the source code, you'll see goodies such as Singletong, Null Pattern implementation and other things you don't use that often.",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/sametmax/Bat-belt",
"keywords": null,
"license": "UNKNOWN",
"maintainer": null,
"maintainer_email": null,
"name": "batbelt",
"package_url": "https://pypi.org/project/batbelt/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/batbelt/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/sametmax/Bat-belt"
},
"release_url": "https://pypi.org/project/batbelt/0.5.2/",
"requires_dist": null,
"requires_python": null,
"summary": "A collection of gagdets that makes Python even more powerful.",
"version": "0.5.2"
},
"last_serial": 927439,
"releases": {
"0.1": [
{
"comment_text": "",
"digests": {
"md5": "c37f238b050c1a52cbdc45e943cb6a08",
"sha256": "1fc20c6916eb362e003d48ecc9b62dcddb32d0cc7b9945098f8c3e593638be39"
},
"downloads": -1,
"filename": "batbelt-0.1.tar.gz",
"has_sig": false,
"md5_digest": "c37f238b050c1a52cbdc45e943cb6a08",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3464,
"upload_time": "2012-10-14T23:13:57",
"url": "https://files.pythonhosted.org/packages/56/87/f667e541c6bae63ecf441934c9fffb33cc3f486c97eee814714d87a0b8ed/batbelt-0.1.tar.gz"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "d607ae155661887ccac3ebd9c7373046",
"sha256": "dc99f88c63fea9bdbfa0a1cfa843a8053d12352f7158c35b317fe98c4a6116f0"
},
"downloads": -1,
"filename": "batbelt-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "d607ae155661887ccac3ebd9c7373046",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5180,
"upload_time": "2012-10-16T22:33:18",
"url": "https://files.pythonhosted.org/packages/35/e3/4ebe3f760078a627947a536b0d3e0b498c0219cae109bb7069670c50757b/batbelt-0.1.1.tar.gz"
}
],
"0.2": [
{
"comment_text": "",
"digests": {
"md5": "06867320066110a3a30c07c1ec06727f",
"sha256": "af642a5b2344f89e024556a73cb37ef6c53f431edc458d2c88dacc71ba1a18da"
},
"downloads": -1,
"filename": "batbelt-0.2.tar.gz",
"has_sig": false,
"md5_digest": "06867320066110a3a30c07c1ec06727f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6629,
"upload_time": "2012-12-02T16:15:37",
"url": "https://files.pythonhosted.org/packages/21/e3/9dc40acb8902ec0ff94e56e3e32baf357324d4a364779732afe827a450a9/batbelt-0.2.tar.gz"
}
],
"0.3": [
{
"comment_text": "",
"digests": {
"md5": "8f94998aeebd62a66cc94b676288f0d0",
"sha256": "ce2467b8baca05172e1a8ae10ad8d3cfcaee40a88e13f6288a3361633996a8ca"
},
"downloads": -1,
"filename": "batbelt-0.3.tar.gz",
"has_sig": false,
"md5_digest": "8f94998aeebd62a66cc94b676288f0d0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8735,
"upload_time": "2012-12-06T13:04:16",
"url": "https://files.pythonhosted.org/packages/b1/94/faaa5ccdeaa44818cf59a1288c55a21e610da49a3018b722b63db841c551/batbelt-0.3.tar.gz"
}
],
"0.4": [
{
"comment_text": "",
"digests": {
"md5": "7a1a9e99e8f71df9656a3217e3ff3a20",
"sha256": "861aa84c0934cdad3aae965d61b91b83707c523294ca7fbb1f92c3ee5efe14f1"
},
"downloads": -1,
"filename": "batbelt-0.4.tar.gz",
"has_sig": false,
"md5_digest": "7a1a9e99e8f71df9656a3217e3ff3a20",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10497,
"upload_time": "2012-12-12T17:35:59",
"url": "https://files.pythonhosted.org/packages/07/32/58ef29ee798ea547bb07be6ff144f08f51bb203ddb2e111fa6f137a3ba26/batbelt-0.4.tar.gz"
}
],
"0.5": [
{
"comment_text": "",
"digests": {
"md5": "443c3b1a32fb6eba503ad4d6a4586689",
"sha256": "76602317d446081b33f313641d368ad12ddaa23b4c73de08ac24a2d1ce7e0a57"
},
"downloads": -1,
"filename": "batbelt-0.5.tar.gz",
"has_sig": false,
"md5_digest": "443c3b1a32fb6eba503ad4d6a4586689",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13773,
"upload_time": "2013-06-03T08:39:20",
"url": "https://files.pythonhosted.org/packages/a5/40/092900f663de477db88a01c93df810a0d743d5e87a2708f2afd1787124f8/batbelt-0.5.tar.gz"
}
],
"0.5.1": [
{
"comment_text": "",
"digests": {
"md5": "916e1fe8db5f618d2e44857b4b3ead26",
"sha256": "8edcae0689e3674b47537fac2eace0a234cc990aefd8ee46b61df76bd5b58b43"
},
"downloads": -1,
"filename": "batbelt-0.5.1.tar.gz",
"has_sig": false,
"md5_digest": "916e1fe8db5f618d2e44857b4b3ead26",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14848,
"upload_time": "2013-06-25T22:36:36",
"url": "https://files.pythonhosted.org/packages/77/82/2255cd4285702ab028e92c60b061866945f4c9ea0de74b2af95b9c639fb8/batbelt-0.5.1.tar.gz"
}
],
"0.5.2": [
{
"comment_text": "",
"digests": {
"md5": "4c3ef1ada2aaab801477970e72987643",
"sha256": "92fbb0c7a66ebe4b92670d535225ed5b5945d5d58a41f1004044ff8aa49e8828"
},
"downloads": -1,
"filename": "batbelt-0.5.2.tar.gz",
"has_sig": false,
"md5_digest": "4c3ef1ada2aaab801477970e72987643",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18287,
"upload_time": "2013-11-23T21:14:47",
"url": "https://files.pythonhosted.org/packages/8e/66/9861dd5778937f3cd93e5e4e7bc73e55b9482db67945a6fc76d3bb21794c/batbelt-0.5.2.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "4c3ef1ada2aaab801477970e72987643",
"sha256": "92fbb0c7a66ebe4b92670d535225ed5b5945d5d58a41f1004044ff8aa49e8828"
},
"downloads": -1,
"filename": "batbelt-0.5.2.tar.gz",
"has_sig": false,
"md5_digest": "4c3ef1ada2aaab801477970e72987643",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18287,
"upload_time": "2013-11-23T21:14:47",
"url": "https://files.pythonhosted.org/packages/8e/66/9861dd5778937f3cd93e5e4e7bc73e55b9482db67945a6fc76d3bb21794c/batbelt-0.5.2.tar.gz"
}
]
}