{ "info": { "author": "Thomas Berdy", "author_email": "thomas.berdy@outlook.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Linguistic" ], "description": "# Encoding Tools\n\n[![pipeline status](https://gitlab.kozlek.net/open-source/encoding_tools/badges/dev/pipeline.svg)](https://github.com/Tberdy/encoding_tools)\n[![coverage report](https://gitlab.kozlek.net/open-source/encoding_tools/badges/dev/coverage.svg)](https://github.com/Tberdy/encoding_tools)\n[![PyPI - Python Version](https://img.shields.io/badge/Python-3.6%2C%203.7-blue.svg)](https://docs.python.org/3/whatsnew/3.7.html)\n\n\nThis module aims to provide a wrapper to deal with encoding in Python.\n\n## Features\n### Encode str to bytes\n\n```python\nfrom encoding_tools import TheSoCalledGreatEncoder\n\nencoder = TheSoCalledGreatEncoder()\nencoder.load_str('hell\u00f2')\nencoder.encode('latin-1')\n\nencoded_string = encoder.encoded_data\n```\n\nYes, this is a much complicated than a simple `'hell\u00f2'.encode('latin-1')`, but it deals with encoding errors.\nBy default, it will fallback to ASCII if an error is encountered.\n\n```python\nfrom encoding_tools import TheSoCalledGreatEncoder\n\nencoder = TheSoCalledGreatEncoder()\nencoder.load_str('c\u0153ur') # \u0153 is not supported by latin-1\nencoder.encode('latin-1')\n\nencoded_string = encoder.encoded_data # equals to b'coeur' \n```\n\nIf you want to force ASCII conversion, you can do it by specifying `force_ascii=True` when\ncalling `.encode()`.\n\n### Decode bytes to str\n\n```python\nfrom encoding_tools import TheSoCalledGreatEncoder, GuessEncodingFailedException\n\nencoder = TheSoCalledGreatEncoder()\nencoder.load_bytes(b'hell\\xf2')\ntry:\n encoder.decode()\nexcept GuessEncodingFailedException as e:\n # Deal with it\n raise ValueError('Wrong input...') from e\n\ndecoded_string = encoder.decoded_data # equals to 'hell\u00f2'\nencoding = encoder.encoding # equals to 'ISO-8859-1'\n```\n\nThe decoder will guess encoding for you using the great Chardet library. You can as well provide the encoding\nif you know when you load the data: `.load_bytes(b'hell\\xf2', encoding='latin-1')`\n\nTo change data encoding, proceed this way:\n```python\nfrom encoding_tools import TheSoCalledGreatEncoder, GuessEncodingFailedException\n\nencoder = TheSoCalledGreatEncoder()\nencoder.load_bytes(b'hell\\xf2') # latin-1\ntry:\n encoder.decode()\nexcept GuessEncodingFailedException as e:\n # Deal with it\n raise ValueError('Wrong input...') from e\n\nencoder.encode('utf-8')\n\nencoded_string = encoder.encoded_data # equals to b'hell\\xc3\\xb2'\nencoding = encoder.encoding # equals to 'utf-8'\n```\n\n## Roadmap\n* Deals with decoding errors\n* Support more encoding (test suite)\n\n\n", "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/Tberdy/encoding_tools", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "encoding-tools", "package_url": "https://pypi.org/project/encoding-tools/", "platform": "", "project_url": "https://pypi.org/project/encoding-tools/", "project_urls": { "Homepage": "https://github.com/Tberdy/encoding_tools" }, "release_url": "https://pypi.org/project/encoding-tools/0.0.3/", "requires_dist": [ "chardet", "Unidecode" ], "requires_python": "", "summary": "A package to deal with encoding.", "version": "0.0.3" }, "last_serial": 4164955, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "3aa31c93f821f75828c8a839bc5b941e", "sha256": "51eeddb3e28844bcc8d99781faffb6986fab6c9b57284b07c37b7286469b35da" }, "downloads": -1, "filename": "encoding_tools-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "3aa31c93f821f75828c8a839bc5b941e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3984, "upload_time": "2018-08-12T22:49:59", "url": "https://files.pythonhosted.org/packages/a9/34/fc57185aeb9446b9ff54e37e81f0751c7282b9e9e86eca45d0634c3a9ced/encoding_tools-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "227f995768789de011cbee1807fbdf6b", "sha256": "283867cc7ec8273986c7f9c1bbf62a1598d216db413a0d8c589854f1c84df33a" }, "downloads": -1, "filename": "encoding_tools-0.0.2.tar.gz", "has_sig": false, "md5_digest": "227f995768789de011cbee1807fbdf6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3187, "upload_time": "2018-08-12T22:50:00", "url": "https://files.pythonhosted.org/packages/61/51/67435ab7922e8a5151a7bc7276c880abb1b35393b8771037e547ab9bd720/encoding_tools-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "b6143558d393cbe2be2963654aeaae7b", "sha256": "7a54385750b1610d71ab16e706905bcd3abb334537da16586b748ac3326cd4f6" }, "downloads": -1, "filename": "encoding_tools-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "b6143558d393cbe2be2963654aeaae7b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3979, "upload_time": "2018-08-13T12:23:46", "url": "https://files.pythonhosted.org/packages/b7/12/c0a77cd173766f90dd21f3267c145480074a59e8f43614334b1f98dda709/encoding_tools-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f32207cb7c49f2feea8489006f0eaaeb", "sha256": "0d2fd169266044dca39310a753f0c9dd8c82ff6c38102e1e5cbf7c96a135aac4" }, "downloads": -1, "filename": "encoding_tools-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f32207cb7c49f2feea8489006f0eaaeb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3178, "upload_time": "2018-08-13T12:23:47", "url": "https://files.pythonhosted.org/packages/46/11/1846b95662b0723016d99db9da18fdd302313ecb71695b856d62a5cf8807/encoding_tools-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b6143558d393cbe2be2963654aeaae7b", "sha256": "7a54385750b1610d71ab16e706905bcd3abb334537da16586b748ac3326cd4f6" }, "downloads": -1, "filename": "encoding_tools-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "b6143558d393cbe2be2963654aeaae7b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3979, "upload_time": "2018-08-13T12:23:46", "url": "https://files.pythonhosted.org/packages/b7/12/c0a77cd173766f90dd21f3267c145480074a59e8f43614334b1f98dda709/encoding_tools-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f32207cb7c49f2feea8489006f0eaaeb", "sha256": "0d2fd169266044dca39310a753f0c9dd8c82ff6c38102e1e5cbf7c96a135aac4" }, "downloads": -1, "filename": "encoding_tools-0.0.3.tar.gz", "has_sig": false, "md5_digest": "f32207cb7c49f2feea8489006f0eaaeb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3178, "upload_time": "2018-08-13T12:23:47", "url": "https://files.pythonhosted.org/packages/46/11/1846b95662b0723016d99db9da18fdd302313ecb71695b856d62a5cf8807/encoding_tools-0.0.3.tar.gz" } ] }