{ "info": { "author": "Xian Zheng", "author_email": "714186139@qq.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# sine.utils\n\nthe set of common tools\n\n## tools\n\n### Class EventManager\n\nprovide event sending and listening.\nuse a hashable key to identify an event.\n\n```python\ndef f(key, data):\n print data\n\nmanager = EventManager()\nmanager.start() # start listen\n\nmanager.addListener(key='evnet_key', listener=f)\n\nmanager.sendEvent(key='evnet_key', 'print hello')\n\n\n# other methods\nmanager.removeListener(key='evnet_key', f)\nmanager.stop() # stop listen\nmanager.clear() # clear event\n```\n\n### Class Path\n\nconvenient to join file path in a chain manner:\n\n```python\ns = Path('.')\ns = s.join('a', 'b').join('..')\n# s == 'a'\n```\n\nit uses `os.path.join` and always normalizes the path with `os.path.normpath` \nbecause `os.path.join` join the `'a', '..'` to `'a/..'`\n\n### Module properties\n\nread/write .properties file in line-oriented format \n`key=value` per line *through function*.\n\n*the code refers to `java.util.Properties` in Java 1.6.*\n\n#### Common Usage\n\n* file I/O:\n\n ```python\n # input\n properties = load(file)\n # or update existing dictionary\n load(file, properties)\n\n # output\n store(file, properties)\n ```\n\n* custom input: \n `class LineReader` read in one key-value data. It skips all comment lines, \n blank lines, leading whitespace, and processes multi-line data. \n `loadSingle(string)` read each piece of data given above to key-value. \n\n ```python\n for line in LineReader(file): # each key-value line has no line seperator\n key, value = loadSingle(line)\n # do something\n ```\n\n* custom output: \n `storeComments(writable, comments, linesep=os.linesep))` \n write comment (accept multi-line), can specify the line terminator. \n `storeSingle(writable, key, value, sep='=', linesep=os.linesep)` \n write one key-value, can specify the seperator and the line terminator. \n\n ```python\n storeComments(file, 'this is a comment')\n storeSingle(file, 'key', 'value')\n ```\n\n#### File Format\n\nnormally each line is comment line or a key-value pair.\n\nmain features:\n\n* seperate key and value by one of `=`, `:`, ` `, `\\t`\n* ignore whitespaces leading in a line or around `=` or `:`\n* comment line begin with `#` or `!`\n* escape unicode by `\\uxxxx`\n* escape special characters by adding `\\`\n\nothers:\n\n* data line ends with `\\` discard the line break\n\ndifferences with Java:\n\n* store method will not write datetime comment\n\n### Thread classes\n\n```python\ndef func(a, b, stop_event):\n while 1:\n if stop_event.is_set():\n break\n # do your work\n\nthread = StoppableThread(target=func, args=('a', 'b'))\nthread.start()\n# ...\nthread.stop(-1) # stop and join forever\n# thread.stopped() == True\n\n\nthread = ReStartableThread(target=func, args=('a', 'b'), event_name='stop_event') # can specify the parameter's name\nthread.start()\n# ...\nthread.stop(1) # stop and join for 1 second\n# ...\nthread.start()\n# ...\nthread.stop()\nthread.join()\n# ...\n```\n\n### sine.storage\n\n#### Brief\n\nprovide simple reliable persistence for string data base on a string key.\n\ndata changes will append to the file like logging while update.\ndata are store in **csv** format.\nyou can compress the data anytime reliably.\n\n#### Examples\n\n```python\n# common use\nstorage = getStorage('./data.csv')\nauthor = storage.setdefault('author', 'sine')\nstorage['author'] = 'Sine'\ndel storage['author']\n\nfor k in storage.keys():\n print(k, storage[k])\n\n# compress data\nstorage.compress()\n```\n\n## Change Log\n\n### v0.1.0, 2019-7-21\n\ncollect from exist package:\n\n* sine.path-v0.1.3\n* sine.threads-v0.1.7\n* sine.event-v0.0.2\n* sine.properties-v0.1.1\n\nand the new 'storage'.\n\nnews:\n\n* EventManager: change arguments passing, include the key (just like calling the sendEvent)\n* threads: fix about args appending", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/SineObama/", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "sine.utils", "package_url": "https://pypi.org/project/sine.utils/", "platform": "", "project_url": "https://pypi.org/project/sine.utils/", "project_urls": { "Homepage": "https://github.com/SineObama/" }, "release_url": "https://pypi.org/project/sine.utils/0.1.0/", "requires_dist": null, "requires_python": ">=3.6.0", "summary": "the set of common tools", "version": "0.1.0" }, "last_serial": 5562472, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "0ba6476eabffe8eec861647254416e28", "sha256": "c17a5ebf33153981a517b599da784e29d21d4d779b3f18c4bea6b201fe6e29ae" }, "downloads": -1, "filename": "sine.utils-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0ba6476eabffe8eec861647254416e28", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 22186, "upload_time": "2019-07-21T05:26:06", "url": "https://files.pythonhosted.org/packages/64/9f/1a6c1ecec15da9a19028cadc9f42423a66afe272ed493d6bb38d8f09d595/sine.utils-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0ba6476eabffe8eec861647254416e28", "sha256": "c17a5ebf33153981a517b599da784e29d21d4d779b3f18c4bea6b201fe6e29ae" }, "downloads": -1, "filename": "sine.utils-0.1.0.tar.gz", "has_sig": false, "md5_digest": "0ba6476eabffe8eec861647254416e28", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 22186, "upload_time": "2019-07-21T05:26:06", "url": "https://files.pythonhosted.org/packages/64/9f/1a6c1ecec15da9a19028cadc9f42423a66afe272ed493d6bb38d8f09d595/sine.utils-0.1.0.tar.gz" } ] }