{ "info": { "author": "Patrick Maupin", "author_email": "pmaupin@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries" ], "description": "=========\nrsonlite\n=========\n\nVersion 0.1\n\nCopyright (c) 2012, Patrick Maupin\n\n\n.. contents::\n\nAbstract\n============\n\nrsonlite is the easiest way to create custom indented data file\nformats in Python. It is a single small module that can be shipped\nwith your application, or it can be easy-installed or pipped from PyPI.\n\nBackground\n=============\n\nThe `rson project`__ contains a parser that allows experimentation with\nvariations on readable file formats, and defines a base RSON profile that\nis a strict superset of JSON (properly subclassed, the RSON parser passes\nthe Python simplejson testsuite, which itself creates a superset of JSON).\n\n\n__ http://code.google.com/p/rson\n\nRSON was born out of frustration with the size and speed of the available\npure-Python YAML parsers at the time, and was designed with very similar\ngoals to YAML -- key to these formats is the use of indentation as syntax,\nremoval of unnecessary syntactical elements such as quotes whenever possible,\nthe ability to add comments, and the ability to use JSON as valid input.\n\nThe base RSON format definition was designed to be easily parseable from any\nlanguage, but the Python parser itself is both flexible and fast, allowing\nfor variant formats to be easily designed and tested. One such format is\nsomething that `easily round-trips to XML`__ and another format allows\n`macros and include processing`__.\n\n__ http://code.google.com/p/rson/source/browse/trunk/tools/testxml.py\n__ http://code.google.com/p/rson/source/browse/trunk/tools/rsonmac.py\n\nBut the flexibility comes at a price. There is more code, and the learning curve\nfor all the options is more steep than it would be if the parser was not that\nflexible, and the documentation -- well, it would take a long time to do a\ndecent job on properly documenting all the options, so that hasn't happened yet.\n\nrsonlite is a pared-down version of rson that primarily handles the semantics\nof the indentation, allowing client code to do higher-level parsing. Unlike\nJSON or base RSON, which distinguish between 'true', 'false', 'null', strings,\nand numbers, or simplejson, which adds 'Nan' and 'Infinity' to the mix, rsonlite\ndivides the world up into container nodes and leaf nodes, and every leaf node is\na string.\n\nIntroduction\n=============\n\nrsonlite is a Python library that makes it easy to build a file\nparser for declarative hierarchical data structures using indentation.\n(Spaces only -- tabs are not considered indentation.)\n\nSyntax\n--------\n\nThe only special characters are **#**, **=**, and indentation:\n\n Indentation\n Indentation denotes a key/value relationship. The\n value is indented from the key.\n\n =\n Denotes the start of a free-format string. These\n strings can contain '=' and '#' characters, and\n even be multi-line, but every line in the string\n must be indented past the initial equal sign.\n\n Note that, for multi-line strings, indentation is\n preserved but normalized such that at least one\n line starts in the left column. This allows for\n restructuredText or Python code, or even\n additional rsonlite to be parsed later, to exist\n inside multi-line strings.\n\n #\n Denotes the start of a line comment, when not\n inside a free-format string.\n\nObjects\n---------\n\nThe only Python objects resulting from parsing a file\nwith rsonlite.loads() are:\n\n strings\n free-format strings (described above) can\n contain any character, but the whitespace\n before/after the string may be stripped.\n\n Regular strings must fit on a single line and\n cannot contain '=' or '#' characters.\n\n Regular strings may be used as keys in key/value\n pairs, but free-format strings may not.\n\n tuple\n A key/value pair is a two-element tuple. The key is always\n a string. The value is always a list. (It was judged\n that the consistency of always having the value be a list\n was more useful than the shortcut of simply letting the\n value sometimes be a single string.)\n\n list\n The top level is a list, and the value element of every\n key/value pair tuple is also a list. Lists can contain\n strings and key/value pair tuples.\n\nrsonlite.simpleparse() leverages rsonlite.loads to return a data\nstructure with dictionaries. Ordered dictionaries are used if\nthey are available, otherwise standard dictionaries are used.\n\nlists are returned whereever dictionaries would not work or\nwould lose information.\n\nExceptions\n------------\n\nAs far as rsonlite is concerned, most input data is fine.\nThe main thing that makes it unhappy is indentation errors,\nand it will throw the Python IndentationError exception if\nit encounters an invalid indentation.\n\nExamples\n==========\n\nI have shamelessly stolen most of these examples from the \n`JSON example page`__, because JSON is an excellent\nthing to compare and contrast rsonlite against.\n\n__ http://json.org/example.html\n\nExample 1::\n\n >>> import rsonlite\n >>> jsonstr1 = '''\n ... {\n ... \"glossary\": {\n ... \"title\": \"example glossary\",\n ... \"GlossDiv\": {\n ... \"title\": \"S\",\n ... \"GlossList\": {\n ... \"GlossEntry\": {\n ... \"ID\": \"SGML\",\n ... \"SortAs\": \"SGML\",\n ... \"GlossTerm\": \"Standard Generalized Markup Language\",\n ... \"Acronym\": \"SGML\",\n ... \"Abbrev\": \"ISO 8879:1986\",\n ... \"GlossDef\": {\n ... \"para\": \"A meta-markup language\",\n ... \"GlossSeeAlso\": [\"GML\", \"XML\"]\n ... },\n ... \"GlossSee\": \"markup\"\n ... }\n ... }\n ... }\n ... }\n ... }\n ... '''\n >>>\n >>> rsonstr1 = '''\n ... glossary\n ... title = example glossary\n ... GlossDiv\n ... title = S\n ... GlossList\n ... GlossEntry\n ... ID = SGML\n ... SortAs = SGML\n ... GlossTerm = Standard Generalized Markup Language\n ... Acronym = SGML\n ... Abbrev = ISO 8879:1986\n ... GlossDef\n ... para = A meta-markup language\n ... GlossSeeAlso = [GML, XML]\n ... GlossSee = markup\n ... '''\n >>>\n >>> jsondata1 = eval(jsonstr1)\n >>> rsondata1 = rsonlite.simpleparse(rsonstr1)\n >>> jsondata1 == rsondata1\n True\n\nExample 2::\n\n >>> jsonstr2 = '''\n ... {\"menu\": {\n ... \"id\": \"file\",\n ... \"value\": \"File\",\n ... \"popup\": {\n ... \"menuitem\": [\n ... {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n ... {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n ... {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n ... ]\n ... }\n ... }}\n ... '''\n >>>\n >>> rsonstr2 = '''\n ... menu\n ... id = file\n ... value = File\n ... popup\n ... menuitem\n ... value = New\n ... onclick = CreateNewDoc()\n ... value = Open\n ... onclick = OpenDoc()\n ... value = Close\n ... onclick = CloseDoc()\n ... '''\n >>>\n >>> jsondata2 = eval(jsonstr2)\n >>> rsondata2 = rsonlite.simpleparse(rsonstr2)\n >>> jsondata2 == rsondata2\n True\n\nAPI\n====\n\nrsonlite.loads(source)\n------------------------\n\nThis is the primary interface. It returns a list of tuples,\nstrings, and lists, as defined in the introduction.\n\nrsonlite.dumps(data, indent=' ', initial_indent='')\n--------------------------------------------------------\n\nThis function takes data as returned from loads() and dumps it\nback out to a string. For example::\n\n >>> rsondata1 = rsonlite.loads(rsonstr1)\n >>> roundtrip = rsonlite.dumps(rsondata1, initial_indent=' ')\n >>> roundtrip == rsonstr1[1:] # Get past initial \\n\n True\n\n >>> rsondata2 = rsonlite.loads(rsonstr2)\n >>> roundtrip = rsonlite.dumps(rsondata2, initial_indent=' ')\n >>> roundtrip == rsonstr2[1:] # Get past initial \\n\n True\n\nrsonlite.pretty(data, indent=' ')\n---------------------------------------\n\nThis pretty-prints a data structure created by loads() for debugging.\nThe structure is accurate, yet quasi-readable::\n\n >>> data = rsonlite.loads(rsonstr2)\n >>> pretty = rsonlite.pretty(data)\n >>> print pretty,\n [\n ('menu', [\n ('id', ['file']),\n ('value', ['File']),\n ('popup', [\n ('menuitem', [\n ('value', ['New']),\n ('onclick', ['CreateNewDoc()']),\n ('value', ['Open']),\n ('onclick', ['OpenDoc()']),\n ('value', ['Close']),\n ('onclick', ['CloseDoc()']),\n ])\n ])\n ])\n ]\n >>> eval(pretty) == data\n True\n >>>\n\nrsonlite.simpleparse(source, stringparse=stringparse, stddict=stddict)\n------------------------------------------------------------------------\n\nThis is a convenience wrapper on loads for simple data structures, and\nalso provides an example client for loads. This is the interface that\nwas used in the JSON example section above. Parameters:\n\n source\n source may either be a string that is passed to loads, or a list,\n that is assumed to be the result of running loads on a string.\n\n stringparse\n stringparse is a function that accepts a (non-key) string, and\n returns a parsed value of the string. The default example stringparse\n in rsonlite will handle the JSON keywords true, false and null, and\n will also translate really simple arrays of strings, as shown\n in the [GML, XML] example above.\n\n stddict\n stddict defaults to collections.OrderedDict if available, or a regular\n dict if not. You may substitute a third-party OrderedDict if desired.\n\nTests\n=======\n\nEmpty input::\n\n >>> rsonlite.loads('') == rsonlite.loads(' \\n \\n \\n') == []\n True\n\nBad indentation::\n\n >>> rsonlite.loads('a\\n b\\n c')\n Traceback (most recent call last):\n File \"\", line 1, in \n rsonlite.loads('a\\n b\\n c')\n File \"/home/pat/projects/opensource/rson/lite/rsonlite.py\", line 179, in loads\n raise err\n IndentationError: unindent does not match any outer indentation level (, line 3)\n\nMultiline data, with special characters::\n\n >>> teststr = '''\n ... My key =\n ... This is indented #=\n ... This should be at the left edge ===#\n ... This is indented differently\n ... '''\n >>> test2 = '\\n'.join(x[6:] for x in teststr.splitlines()[2:])\n >>> rsonlite.loads(teststr) == [('My key', [test2])]\n True\n\n >>> teststr = '''\n ... My key = Something on the first line is at the left edge\n ... This is indented\n ... This should be at the left edge\n ... This is indented differently\n ... '''\n >>> test2 = teststr.split('=', 1)[1].strip().splitlines()\n >>> for i in range(1, len(test2)):\n ... test2[i] = test2[i][6:]\n >>> test2 = '\\n'.join(test2)\n >>> rsonlite.loads(teststr) == [('My key', [test2])]\n True\n\nComments and special string stuff::\n\n >>> test1 = '''\n ... a\n ... b = 1\n ... This is part of b's string\n ... c\n ... d = 2\n ... '''\n >>> test2 = '''\n ... # Comments can start anywhere outside a string\n ... a # Like here (but not below)\n ... b = 1\n ... This is part of b's string\n ... # This isn't in the string because it's far enough left\n ... # Any non-key string can start with '='\n ... = c\n ... # This isn't in the string because it's far enough left\n ... d = 2\n ... '''\n >>> rsonlite.loads(test1) == rsonlite.loads(test2)\n True", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://code.google.com/p/rson/", "keywords": "rson yaml configuration file", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "rsonlite", "package_url": "https://pypi.org/project/rsonlite/", "platform": "Independent", "project_url": "https://pypi.org/project/rsonlite/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://code.google.com/p/rson/" }, "release_url": "https://pypi.org/project/rsonlite/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "rsonlite -- extremely lightweight version of rson", "version": "0.1.0" }, "last_serial": 484241, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "4a761a43710d1c0a0cf633dcf18be94d", "sha256": "90b1ac46bef278f718e2767157a63191e2eb5560d918e3f12779ec4937e386c9" }, "downloads": -1, "filename": "rsonlite-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4a761a43710d1c0a0cf633dcf18be94d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9365, "upload_time": "2012-09-29T21:07:05", "url": "https://files.pythonhosted.org/packages/16/0e/9a4cb86dd5ec7ac103721ef5701a8d7a02c722d7325a4bf11185a81920af/rsonlite-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4a761a43710d1c0a0cf633dcf18be94d", "sha256": "90b1ac46bef278f718e2767157a63191e2eb5560d918e3f12779ec4937e386c9" }, "downloads": -1, "filename": "rsonlite-0.1.0.tar.gz", "has_sig": false, "md5_digest": "4a761a43710d1c0a0cf633dcf18be94d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9365, "upload_time": "2012-09-29T21:07:05", "url": "https://files.pythonhosted.org/packages/16/0e/9a4cb86dd5ec7ac103721ef5701a8d7a02c722d7325a4bf11185a81920af/rsonlite-0.1.0.tar.gz" } ] }