{ "info": { "author": "Cameron Simpson", "author_email": "cs@cskk.id.au", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "*Latest release 20191004*:\n@pfx_method: new optional `use_str` parameter to use str(self) instead of type(self).__name__; now requires @cs.deco.decorator\n\nDynamic message prefixes providing execution context.\n\nThe primary facility here is Pfx,\na context manager which maintains a per thread stack of context prefixes.\n\nUsage is like this:\n\n from cs.pfx import Pfx\n ...\n def parser(filename):\n with Pfx(\"parse(%r)\", filename):\n with open(filename) as f:\n for lineno, line in enumerate(f, 1):\n with Pfx(\"%d\", lineno) as P:\n if line_is_invalid(line):\n raise ValueError(\"problem!\")\n P.info(\"line = %r\", line)\n\nThis produces log messages like:\n\n datafile: 1: line = 'foo\\n'\n\nand exception messages like:\n\n datafile: 17: problem!\n\nwhich lets one put just the relevant complaint in exception and log\nmessages and get useful calling context on the output.\nThis does make for wordier logs and exceptions\nbut used with a little discretion produces far more debuggable results.\n\n## Function `gen(func)`\n\nDecorator for generators to manage the Pfx stack.\n\nBefore running the generator the current stack height is\nnoted. After yield, the stack above that height is trimmed\nand saved, and the value yielded. On recommencement the saved\nstack is reapplied to the current stack (which may have\nchanged) and the generator continued.\n\n## Class `Pfx`\n\nA context manager to maintain a per-thread stack of message prefixes.\n\n### Method `Pfx.__init__(self, mark, *args, **kwargs)`\n\nInitialise a new Pfx instance.\n\nParameters:\n* `mark`: message prefix string\n* `args`: if not empty, apply to the prefix string with `%`\n* `absolute`: optional keyword argument, default False. If\n true, this message forms the base of the message prefixes;\n existing prefixes will be suppressed.\n* `loggers`: which loggers should receive log messages.\n\n*Note*:\nthe `mark` and `args` are only combined if the `Pfx` instance gets used,\nfor example for logging or to annotate an exception.\nOtherwise, they are not combined.\nTherefore the values interpolated are as they are when the `Pfx` is used,\nnot necessarily as they were when the `Pfx` was created.\nIf `args` is subject to change and you require the original values,\napply them to `mark` immediately, for example:\n\n with Pfx('message %s ...' % (arg1, arg2, ...)):\n\nThis is a bit more expensive, and the common usage is:\n\n with Pfx('message %s ...', arg1, arg2, ...):\n\n## Function `pfx(func)`\n\nDecorator for functions that should run inside:\n\n with Pfx(func_name):\n\nUse:\n\n @pfx\n def f(...):\n\n## Function `pfx_iter(tag, iterable)`\n\nWrapper for iterables to prefix exceptions with `tag`.\n\n## Function `pfx_method(*da, **dkw)`\n\nDecorator to provide a `Pfx` context for an instance method prefixing\n*classname.methodname*\n(or *str(self).methodname* if `use_str` is true).\n\n## Class `PfxCallInfo`\n\nMRO: `Pfx` \nSubclass of Pfx to insert current function an caller into messages.\n\n## Function `pfxtag(tag, loggers=None)`\n\nDecorator for functions that should run inside:\n\n with Pfx(tag, loggers=loggers):\n\nUse:\n\n @pfxtag(tag)\n def f(...):\n\n## Function `PfxThread(target=None, **kw)`\n\nFactory function returning a Thread\nwhich presents the current prefix as context.\n\n## Function `prefix()`\n\nReturn the current Pfx prefix.\n\n## Function `PrePfx(tag, *args)`\n\nPush a temporary value for Pfx._state._ur_prefix to enloundenify messages.\n\n## Function `XP(msg, *args, **kwargs)`\n\nVariation on `cs.x.X`\nwhich prefixes the message with the current Pfx prefix.\n\n## Function `XX(prepfx, msg, *args, **kwargs)`\n\nTrite wrapper for `XP()` to transiently insert a leading prefix string.\n\nExample:\n\n XX(\"NOTE!\", \"some message\")\n\n\n\n# Release Log\n\n*Release 20191004*:\n@pfx_method: new optional `use_str` parameter to use str(self) instead of type(self).__name__; now requires @cs.deco.decorator\n\n*Release 20190905*:\nPfx.__exit__: simplify prefixify_exc() logic, prefixify all suitable attributes.\nNew @pfx_method decorator for instance methods.\n\n*Release 20190607*:\nPfx.__exit__ improved exception attribute handling.\n\n*Release 20190403*:\nDebugging aid: Pfx.umark: emit stack traceback on format conversion error.\n\n*Release 20190327*:\n@pfx: set __name__ on the wrapper function.\nBugfix some references to the internal prefixify function.\n\n*Release 20190324*:\nPfx.__exit__: apply the prefix to all the standard attributes where present, improves some message behaviour for some exception types.\n\n*Release 20181231*:\nBugfix for an infinite regress.\n\n*Release 20181109*:\nUpdate @contextmanager formalism to use try/finally for the cleanup phase.\nNew decorator @gen to manage Pfx state across generator iterations; pretty clunky.\nBetter fallback handling.\nSome docstring updates.\n\n*Release 20170910*:\nSlight linting.\n\n*Release 20170903.1*:\ncorrections to the module docstring\n\n*Release 20170903*:\nInitial release for PyPI.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/cameron_simpson/css/commits/all", "keywords": "python2,python3", "license": "GNU General Public License v3 or later (GPLv3+)", "maintainer": "", "maintainer_email": "", "name": "cs.pfx", "package_url": "https://pypi.org/project/cs.pfx/", "platform": "", "project_url": "https://pypi.org/project/cs.pfx/", "project_urls": { "Homepage": "https://bitbucket.org/cameron_simpson/css/commits/all" }, "release_url": "https://pypi.org/project/cs.pfx/20191004/", "requires_dist": null, "requires_python": "", "summary": "Easy context prefixes for messages.", "version": "20191004" }, "last_serial": 5927741, "releases": { "20170903": [ { "comment_text": "", "digests": { "md5": "20ede7c41e99ac903254dd12815af171", "sha256": "91ada24ecba2d40455d1e8bb06116372fd5ee5a7c8182ac358369df26ee2e576" }, "downloads": -1, "filename": "cs.pfx-20170903.tar.gz", "has_sig": false, "md5_digest": "20ede7c41e99ac903254dd12815af171", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4749, "upload_time": "2017-09-03T03:01:46", "url": "https://files.pythonhosted.org/packages/58/70/d950022630e60b58501e14f7d1200a9ded4518b088a3cab3c83e162df3ce/cs.pfx-20170903.tar.gz" } ], "20170903.1": [ { "comment_text": "", "digests": { "md5": "47f09a37cb69b6ef4042447d105f3f2d", "sha256": "a3c13c157d4841b21e380eb465e30b62f4a8b793b89fbb99d9a2b3bfc5a490db" }, "downloads": -1, "filename": "cs.pfx-20170903.1.tar.gz", "has_sig": false, "md5_digest": "47f09a37cb69b6ef4042447d105f3f2d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4748, "upload_time": "2017-09-03T09:15:42", "url": "https://files.pythonhosted.org/packages/05/fa/1f3a9f849b7b721cda6a470d847419b62400290d0748a00989f84a3f3e58/cs.pfx-20170903.1.tar.gz" } ], "20181109": [ { "comment_text": "", "digests": { "md5": "e4fd5cec3d4c81be1c34b93342265d74", "sha256": "8bfa0f396979e9b3440947f34fe9d654610a36874b35722b9dfd86b8c465546f" }, "downloads": -1, "filename": "cs.pfx-20181109.tar.gz", "has_sig": false, "md5_digest": "e4fd5cec3d4c81be1c34b93342265d74", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6026, "upload_time": "2018-11-09T01:26:37", "url": "https://files.pythonhosted.org/packages/2a/31/a7bf2db43b64ec3447cfdffd84097c4389033a5e665c24d9fe7443d1199a/cs.pfx-20181109.tar.gz" } ], "20181231": [ { "comment_text": "", "digests": { "md5": "7cc00dc91788a782c1cd1013b88e0af6", "sha256": "cf2983a2f93a193f7cad067b79476253f33ecca029dcc78447f7693a80950b03" }, "downloads": -1, "filename": "cs.pfx-20181231.tar.gz", "has_sig": false, "md5_digest": "7cc00dc91788a782c1cd1013b88e0af6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6146, "upload_time": "2018-12-31T10:33:25", "url": "https://files.pythonhosted.org/packages/65/f9/9ad509f5f7ffb10423b110bd486786a0c14b4e1ebf5ab4f904721f66a5c4/cs.pfx-20181231.tar.gz" } ], "20190324": [ { "comment_text": "", "digests": { "md5": "555ae864c6f8f2b924e444abd92f45ef", "sha256": "8eceea4dd7a2e1c660ad08141b56deaf443d82a4c2d9e29c7013338b9e355b69" }, "downloads": -1, "filename": "cs.pfx-20190324.tar.gz", "has_sig": false, "md5_digest": "555ae864c6f8f2b924e444abd92f45ef", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6319, "upload_time": "2019-03-23T22:12:38", "url": "https://files.pythonhosted.org/packages/ea/98/62b174c5e14ba5a91c30560ed35607390259206d84c29fcae47bcd0c8c7d/cs.pfx-20190324.tar.gz" } ], "20190327": [ { "comment_text": "", "digests": { "md5": "7ef912fdd98618a3784a54148c626bc5", "sha256": "5ee0e01ab4eb1f83a7c6c4e8484ec0c978e8c0d9059f48f731565c8d0d1580ab" }, "downloads": -1, "filename": "cs.pfx-20190327.tar.gz", "has_sig": false, "md5_digest": "7ef912fdd98618a3784a54148c626bc5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6338, "upload_time": "2019-03-27T04:40:49", "url": "https://files.pythonhosted.org/packages/ec/9d/f4aac9ea1ddecce8e21efd4cacbbcc90a0e2e42d2402c52d46f86e45b5a2/cs.pfx-20190327.tar.gz" } ], "20190403": [ { "comment_text": "", "digests": { "md5": "847d8f7d8dc968de5d9e32f130f805f2", "sha256": "05226f75137e8fc45b340a20f4f1e45dc0eb6f9a7023a83d0601e524331312a3" }, "downloads": -1, "filename": "cs.pfx-20190403.tar.gz", "has_sig": false, "md5_digest": "847d8f7d8dc968de5d9e32f130f805f2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6353, "upload_time": "2019-04-02T21:31:28", "url": "https://files.pythonhosted.org/packages/af/86/897207846e01d65aed8c4cb3985d0c1fe73648c223c455952d6d9e014a5a/cs.pfx-20190403.tar.gz" } ], "20190607": [ { "comment_text": "", "digests": { "md5": "368a4b52c09f9d8ffd53d1607f838c56", "sha256": "1b962c7ff861402688f45020fcc58c5757bd54eb5177912d50f34595746ac1cd" }, "downloads": -1, "filename": "cs.pfx-20190607.tar.gz", "has_sig": false, "md5_digest": "368a4b52c09f9d8ffd53d1607f838c56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7001, "upload_time": "2019-06-07T00:14:56", "url": "https://files.pythonhosted.org/packages/29/5e/25a8e8c4c0756e5d7adea64c55635dcbdf4b3b1da4ef0449786950a298ee/cs.pfx-20190607.tar.gz" } ], "20190905": [ { "comment_text": "", "digests": { "md5": "c96f95f04256dc8a63606c5b7633756c", "sha256": "e6bc56019e59f945d45ef42b007d43cba9fb2d687507757a84250f419970e280" }, "downloads": -1, "filename": "cs.pfx-20190905.tar.gz", "has_sig": false, "md5_digest": "c96f95f04256dc8a63606c5b7633756c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7855, "upload_time": "2019-09-05T03:04:19", "url": "https://files.pythonhosted.org/packages/bd/d8/ee920f5501670cf2dad19476595577a277ae4f48b681ab72c996bb2392bd/cs.pfx-20190905.tar.gz" } ], "20191004": [ { "comment_text": "", "digests": { "md5": "33155a4a1247deeb8c69a6f1c7f0d105", "sha256": "49270da9576e5c92fb71a5665f45eae48c43b67cc258a8902b1246fb5ee9effb" }, "downloads": -1, "filename": "cs.pfx-20191004.tar.gz", "has_sig": false, "md5_digest": "33155a4a1247deeb8c69a6f1c7f0d105", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8007, "upload_time": "2019-10-04T10:30:01", "url": "https://files.pythonhosted.org/packages/e6/f2/6699ab8cecf599208a4b9506733184f97992a3e552a6caeb5edaef671f89/cs.pfx-20191004.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "33155a4a1247deeb8c69a6f1c7f0d105", "sha256": "49270da9576e5c92fb71a5665f45eae48c43b67cc258a8902b1246fb5ee9effb" }, "downloads": -1, "filename": "cs.pfx-20191004.tar.gz", "has_sig": false, "md5_digest": "33155a4a1247deeb8c69a6f1c7f0d105", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8007, "upload_time": "2019-10-04T10:30:01", "url": "https://files.pythonhosted.org/packages/e6/f2/6699ab8cecf599208a4b9506733184f97992a3e552a6caeb5edaef671f89/cs.pfx-20191004.tar.gz" } ] }