{ "info": { "author": "Matt Good", "author_email": "matt@matt-good.net", "bugtrack_url": null, "classifiers": [], "description": "======\r\njprops\r\n======\r\n\r\nParser for `Java .properties files `_.\r\n\r\nSupports Python 2.6, 2.7, and 3.3+\r\n\r\nInstallation\r\n============\r\n\r\nUse pip to install jprops from PyPI::\r\n\r\n pip install jprops\r\n\r\nUsage\r\n=====\r\n\r\nReading properties\r\n------------------\r\n\r\nUse ``jprops.load_properties`` to read a properties file and return a normal\r\nPython ``dict``::\r\n\r\n import jprops\r\n with open('mine.properties') as fp:\r\n properties = jprops.load_properties(fp)\r\n\r\nYou can provide a custom \"mapping\" to load the properties into a different data\r\nstrucuture. For example, if you would like to keep the properties in the same\r\norder they originally appeared, you can use an \"ordered dict\", such as\r\n``collections.OrderedDict``. The \"mapping\" can be any type or function that\r\naccepts an iterable of (key, value) pairs::\r\n\r\n import collections\r\n with open('mine.properties') as fp:\r\n properties = jprops.load_properties(fp, collections.OrderedDict)\r\n\r\n``load_properties`` is just a wrapper to ``iter_properties``, which you can use\r\ndirectly if you want to process the properties lazily without loading them all\r\ninto a data structure::\r\n\r\n with open('mine.properties') as fp:\r\n for key, value in jprops.iter_properties(fp):\r\n if key.startswith('foo'):\r\n print key, value\r\n\r\nWriting properties\r\n------------------\r\n\r\nUse ``jprops.store_properties`` to write a ``dict``, dict-like object, or any\r\niterable of (key, value) pairs to a file::\r\n\r\n x = {'y': '1', 'z': '2'}\r\n with open('out.properties', 'w') as fp:\r\n jprops.store_properties(fp, x)\r\n\r\nBy default jprops follows the Java convention of writing a timestamp comment to\r\nthe beginning of the file, like::\r\n\r\n #Thu Oct 06 19:08:50 EDT 2011\r\n y=1\r\n z=2\r\n\r\nYou can suppress writing the timestamp comment by passing ``timestamp=False``.\r\n\r\nYou can provide a custom header comment that appears before the timestamp.\r\nMulti-line comments are handled appropriately, continuing the comment across\r\nlines::\r\n\r\n jprops.store_properties(fp, {'x': '1'}, comment='Hello\\nworld!')\r\n\r\n::\r\n\r\n #Hello\r\n #world!\r\n #Thu Oct 06 19:17:21 EDT 2011\r\n x=1\r\n\r\nYou can also use ``write_comment`` and ``write_property`` for finer-grained\r\ncontrol over writing a properties file::\r\n\r\n with open('out.properties', 'w') as fp:\r\n jprops.write_comment(fp, 'the hostname:')\r\n jprops.write_property(fp, 'host', 'localhost')\r\n jprops.write_comment(fp, 'the port number:')\r\n jprops.write_property(fp, 'port', '443')\r\n\r\n::\r\n\r\n #the hostname:\r\n host=localhost\r\n #the port number:\r\n port=443\r\n\r\nComments\r\n--------\r\n\r\nBy default, comments in the input will be ignored, but they can be included by\r\n``iter_properties`` by passing ``comments=True``. The comments will be included\r\nwith ``jprops.COMMENT`` as a sentinal value in place of the key::\r\n\r\n with open('in.properties') as fp:\r\n props = list(jprops.iter_properties(fp, comments=True))\r\n for k, v in props:\r\n if k is jprops.COMMENT:\r\n print 'comment:', v\r\n\r\n``jprops`` doesn't include any special data structures for preserving comments,\r\nbut you can manipulate the properties before writing them back out. For example\r\nthis is one simple pattern for altering properties while writing the ouput::\r\n\r\n updates = {'one': '1', 'two': '2', 'to_remove': None}\r\n\r\n with open('out.properties', 'w') as fp:\r\n for key, value in props:\r\n # updates.pop will return and remove the value for the key, or return\r\n # the original `value` if it doesn't exist\r\n value = updates.pop(key, value)\r\n # skip keys set to `None` in `updates`\r\n if value is not None:\r\n # write_property handles jprops.COMMENT as the key so you don't have to\r\n # check whether to use write_comment\r\n jprops.write_property(fp, key, value)\r\n # since the existing keys have already been popped, use store_properties\r\n # to write the remaining updates\r\n jprops.store_properties(fp, updates, timestamp=False)\r\n\r\nFile encodings and Unicode\r\n--------------------------\r\n\r\nFiles opened in binary mode such as ``open(filename, 'rb')`` or\r\n``open(filename, 'wb')`` will use the ``latin-1`` encoding and escape unicode\r\ncharacters in the format ``\\uffff`` for compatibility with the Java\r\n``Properties`` byte stream encoding.\r\n\r\nStarting with version 2.0, files opened with other text encodings are also\r\nsupported::\r\n\r\n with io.open('sample.properties', encoding='utf-8') as fp:\r\n props = jprops.load_properties(fp)\r\n\r\nThis works with the built-in ``open`` function, ``codecs.open``, or ``io.open``.\r\nOther file-like objects that extend ``io.TextIOBase`` or have a non-empty\r\n``encoding`` property will be read or written as unicode text values, otherwise\r\nthey will be considered binary and read or written as ``latin-1`` encoded bytes.\r\n\r\nAuthors\r\n=======\r\n\r\nMatt Good (matt@matt-good.net)\r\n\r\n\r\nChanges\r\n=======\r\n\r\n2.0.2 (2017-04-21)\r\n------------------\r\n\r\n* Bump version in setup.py before release\r\n\r\n2.0.1 (unreleased)\r\n------------------\r\n\r\n* Fix over-escaping in values\r\n\r\n2.0 (2017-04-08)\r\n----------------\r\n\r\n* Support files opened with text encodings\r\n* Nice repr for ``jprops.COMMENT``\r\n\r\n1.0 (2013-06-12)\r\n----------------\r\n\r\n* Python 3.3 support\r\n* More informative error when trying to write a non-string value\r\n\r\n0.2 (2012-05-02)\r\n----------------\r\n\r\n* Handle Windows or Mac line endings\r\n\r\n\r\n0.1 (2011-10-07)\r\n----------------\r\n\r\nInitial release.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/mgood/jprops/", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "jprops", "package_url": "https://pypi.org/project/jprops/", "platform": "any", "project_url": "https://pypi.org/project/jprops/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/mgood/jprops/" }, "release_url": "https://pypi.org/project/jprops/2.0.2/", "requires_dist": null, "requires_python": null, "summary": "Parser for Java .properties files", "version": "2.0.2" }, "last_serial": 2821206, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "0962b2b406b5bc47aa8259d7dac30b2d", "sha256": "3488bf067a1228a18941033cc3cf695313da8a721168292a69897801f3b0c633" }, "downloads": -1, "filename": "jprops-0.1.tar.gz", "has_sig": false, "md5_digest": "0962b2b406b5bc47aa8259d7dac30b2d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2691, "upload_time": "2011-10-07T01:42:30", "url": "https://files.pythonhosted.org/packages/77/f8/c8fb331785237d41ebdfcdb7f2c171da8ac81d6d02cf3bc0f885039b54cb/jprops-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "47c245dc38138b46eadd7665c3b2e1bb", "sha256": "b5ee802421edeaaeffd95afb8d9230e7137bdacb7034ca5e636e49ae6fba1d11" }, "downloads": -1, "filename": "jprops-0.2.tar.gz", "has_sig": false, "md5_digest": "47c245dc38138b46eadd7665c3b2e1bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4000, "upload_time": "2012-05-02T19:36:09", "url": "https://files.pythonhosted.org/packages/ed/f2/b52419d9b7ee348a2b0e968f9b7ce630a6e9d6446e92055c31a550fbf08c/jprops-0.2.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "d150084738d03d8046418a0f79879821", "sha256": "53d17b2c0181fe6128904ddb81fcb1d600f0adb16d4c5aba39ff21ca6d9b995e" }, "downloads": -1, "filename": "jprops-1.0.tar.gz", "has_sig": false, "md5_digest": "d150084738d03d8046418a0f79879821", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4721, "upload_time": "2013-06-12T15:33:25", "url": "https://files.pythonhosted.org/packages/1f/57/42e0088e3607b2d157bb039ba5c19536010f3d505871573cb28020e1e1d6/jprops-1.0.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "1123c1d5db1dfc137f531100aec1c627", "sha256": "014304cab8af993bc0f1295ef8fd04f5c8e4d2f84c753b1618ce68587724ee80" }, "downloads": -1, "filename": "jprops-2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1123c1d5db1dfc137f531100aec1c627", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 8938, "upload_time": "2017-04-09T23:42:48", "url": "https://files.pythonhosted.org/packages/d1/2d/d450a89ed426db031aeeb1c227bf14dc090bd2e060522477a9b4edc9e1ae/jprops-2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d079e96fdc0759a49b762d1f0b0aa1eb", "sha256": "f30463dca91edd7b6fd37d279cc03809dd4557ba98d50f5f6635eeb46e886ead" }, "downloads": -1, "filename": "jprops-2.0.tar.gz", "has_sig": false, "md5_digest": "d079e96fdc0759a49b762d1f0b0aa1eb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6217, "upload_time": "2017-04-09T23:42:47", "url": "https://files.pythonhosted.org/packages/f8/ca/4e701a77aa1be1ed280783e9f500f333038dc395afbca053326e41386136/jprops-2.0.tar.gz" } ], "2.0.2": [ { "comment_text": "", "digests": { "md5": "6ca5d00262568360668dd01c8b354616", "sha256": "f6be13f0bbc3ca6f7175d74ec8f9f17a4f33a6874473733591c6551d272186a0" }, "downloads": -1, "filename": "jprops-2.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6ca5d00262568360668dd01c8b354616", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9072, "upload_time": "2017-04-22T04:41:03", "url": "https://files.pythonhosted.org/packages/d0/57/cb7364a3c3140091de3fffc6b91f7a638c7aeccabeef9b3f6e418a545d5b/jprops-2.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7771d024444fafc3514e6bc037c35467", "sha256": "d297231833b6cd0a3f982a48fe148a7f9817f2895661743d166b267e4d3d5b2c" }, "downloads": -1, "filename": "jprops-2.0.2.tar.gz", "has_sig": false, "md5_digest": "7771d024444fafc3514e6bc037c35467", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6277, "upload_time": "2017-04-22T04:41:00", "url": "https://files.pythonhosted.org/packages/0d/d6/0a18082cc3349128c1979c747e772b97e38f827b838bb8be2a5f48dbe0dc/jprops-2.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6ca5d00262568360668dd01c8b354616", "sha256": "f6be13f0bbc3ca6f7175d74ec8f9f17a4f33a6874473733591c6551d272186a0" }, "downloads": -1, "filename": "jprops-2.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6ca5d00262568360668dd01c8b354616", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 9072, "upload_time": "2017-04-22T04:41:03", "url": "https://files.pythonhosted.org/packages/d0/57/cb7364a3c3140091de3fffc6b91f7a638c7aeccabeef9b3f6e418a545d5b/jprops-2.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7771d024444fafc3514e6bc037c35467", "sha256": "d297231833b6cd0a3f982a48fe148a7f9817f2895661743d166b267e4d3d5b2c" }, "downloads": -1, "filename": "jprops-2.0.2.tar.gz", "has_sig": false, "md5_digest": "7771d024444fafc3514e6bc037c35467", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6277, "upload_time": "2017-04-22T04:41:00", "url": "https://files.pythonhosted.org/packages/0d/d6/0a18082cc3349128c1979c747e772b97e38f827b838bb8be2a5f48dbe0dc/jprops-2.0.2.tar.gz" } ] }