{ "info": { "author": "Robert Johansson", "author_email": "robertrockar@live.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Software Development" ], "description": "===========\npynetstring\n===========\nA module for encoding and decoding netstrings. See the definition of netstrings\nat https://cr.yp.to/proto/netstrings.txt.\n\nRequirements\n------------\nPynetstring is written for Python 3.\n\nUsage\n-----\n**Encoding**\n::\n\n netstring_bytes = pynetstring.encode('Hello')\n # Will give b'Hello'\n print(netstring_bytes)\n\n**Decoding**\n\nIn the simplest case, when we know for sure that the data we are trying to\ndecode ends on a netstring boundary we can simply do:\n::\n\n # data_list will be an list of bytes.\n decoded_list = pynetstring.decode('5:Hello,6:World!')\n # Will give [b'Hello', b'World!']\n print(decoded_list)\n\nIn many cases however, such when netstring data is transmitted over a network,\nthe chunks of data that arrive may not align to netstring boundaries.\nFor example a chunk of data may contain a netstring and then parts of the next.\nTo handle this, call Decoder.feed(), which will buffer and parse the data and \nemit decoded data as soon as it has been fully received.\n::\n\n decoder = pynetstring.Decoder()\n # Will give []\n print(decoder.feed('5:He'))\n # Will give [b'Hello', b'World!']\n print(decoder.feed('llo,6:World!,5:ag'))\n # Will give [b'again']\n print(decoder.feed('ain,'))\n\n\nThe receiving side could look something like this:\n::\n\n decoder = pynetstring.Decoder()\n\n def handle_network_data(data):\n decoded_list = decoder.feed(data)\n for item in decoded_list:\n print(item)\n\nData encoding\n-------------\nRegardless of the type of the data that is sent to encode(), it will always\nreturn binary data, i.e. python bytes. The data that is returned from decode()\nand Decoder.feed() will also be binary. This is because the decoder can not\nmake any assumptions on the encoding of the original data. If you know that \nthe data that comes in can be interpreted in a particular way or encoding, \ne.g. UTF-8, you have to explicitly do that conversion.\n::\n\n encoded = pynetstring.encode(u'Hello World!')\n # This will be \n print(type(encoded))\n decoded_list = pynetstring.decode(encoded)\n # This will be \n print(type(decoded_list[0]))\n # This will return the original unicode string u'Hello World!'\n print(decoded_list[0].decode('utf-8'))\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/rj79/pynetstring", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pynetstring", "package_url": "https://pypi.org/project/pynetstring/", "platform": "", "project_url": "https://pypi.org/project/pynetstring/", "project_urls": { "Homepage": "https://github.com/rj79/pynetstring" }, "release_url": "https://pypi.org/project/pynetstring/0.2/", "requires_dist": null, "requires_python": ">=3", "summary": "A module for encoding and decoding netstrings.", "version": "0.2" }, "last_serial": 5700237, "releases": { "0.1.dev2": [ { "comment_text": "", "digests": { "md5": "c8d3e5c7f9e56b613089d72c0ca1171f", "sha256": "275c078175d9bbbe4941d768219a37d95154ebb46af8163f0e3dcfb8ce486939" }, "downloads": -1, "filename": "pynetstring-0.1.dev2-py3-none-any.whl", "has_sig": false, "md5_digest": "c8d3e5c7f9e56b613089d72c0ca1171f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 5448, "upload_time": "2017-12-23T22:11:22", "url": "https://files.pythonhosted.org/packages/93/68/2bd5e7ebf0042ece3d4dccc49b5485d630d8db2a059d4aea3b2f74fbf3d5/pynetstring-0.1.dev2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0bc77346fef765ecc732f069a2d26d53", "sha256": "5572388dd28aae310ec1a4bac92d9097f26e4cd3962438daa9850106bb9ac970" }, "downloads": -1, "filename": "pynetstring-0.1.dev2.tar.gz", "has_sig": false, "md5_digest": "0bc77346fef765ecc732f069a2d26d53", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 4190, "upload_time": "2017-12-23T22:11:23", "url": "https://files.pythonhosted.org/packages/98/ed/7c1a3d9261c56f3160b1089c799cdd24688a6db98de406df87e75eb3fb85/pynetstring-0.1.dev2.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "a4c4b71fc9a7d6527c5fb1899f469f94", "sha256": "43afce7024697f0c541a321d26689bd57204506cf1f892c0696d70626c199ccb" }, "downloads": -1, "filename": "pynetstring-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a4c4b71fc9a7d6527c5fb1899f469f94", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 4509, "upload_time": "2019-08-19T20:41:09", "url": "https://files.pythonhosted.org/packages/fb/20/3b70fa224a7dc31a72f32446f59f1bae38ccb94272e711d93c8799ff756d/pynetstring-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9e6e3292b48f1a22c40e021ec27ea8ec", "sha256": "6ba299b7e6775904c38c726d27f1f29713c5b462b8500a726b4c92bdb121e2b4" }, "downloads": -1, "filename": "pynetstring-0.2.tar.gz", "has_sig": false, "md5_digest": "9e6e3292b48f1a22c40e021ec27ea8ec", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 4187, "upload_time": "2019-08-19T20:41:11", "url": "https://files.pythonhosted.org/packages/1c/14/75ee87d8281fd700afb7f582664678c46df24f0943d6b188eed953c6ea64/pynetstring-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a4c4b71fc9a7d6527c5fb1899f469f94", "sha256": "43afce7024697f0c541a321d26689bd57204506cf1f892c0696d70626c199ccb" }, "downloads": -1, "filename": "pynetstring-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "a4c4b71fc9a7d6527c5fb1899f469f94", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 4509, "upload_time": "2019-08-19T20:41:09", "url": "https://files.pythonhosted.org/packages/fb/20/3b70fa224a7dc31a72f32446f59f1bae38ccb94272e711d93c8799ff756d/pynetstring-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9e6e3292b48f1a22c40e021ec27ea8ec", "sha256": "6ba299b7e6775904c38c726d27f1f29713c5b462b8500a726b4c92bdb121e2b4" }, "downloads": -1, "filename": "pynetstring-0.2.tar.gz", "has_sig": false, "md5_digest": "9e6e3292b48f1a22c40e021ec27ea8ec", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 4187, "upload_time": "2019-08-19T20:41:11", "url": "https://files.pythonhosted.org/packages/1c/14/75ee87d8281fd700afb7f582664678c46df24f0943d6b188eed953c6ea64/pynetstring-0.2.tar.gz" } ] }