{ "info": { "author": "David Garcia Garzon", "author_email": "voki@canvoki.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "yamlns.namespace\n================\n\n|Build Status|\n\nAn ordered dictionary whose values can be accessed either as items or as\nattributes, like in Javascript Objects but with Pythonic sugar and YAML\nI/O.\n\nIt also provides some goodies:\n\n- Direct mapping to YAML using ``dump()`` and ``load()`` methods.\n- There are several convenient variations from the YAML specs in the\n way value types are mapped between YAML and Python:\n\n - Inner YAML mappings (``dict``\\ s) are loaded as ``namespace``\\ s\n as well instead of Python ``dict``.\n - Namespaces preserve the insertion order, as they are based on\n ``odict``. This way the insertion order and the order in the\n original loaded file is preserved when stored.\n - YAML floats are loaded as ``Decimal`` and ``Decimal`` objects are\n stored as regular YAML floats. This avoids losing precision when\n succesive load/store cycles are alternated.\n - YAML dates are maped to an extension of ``datetime.date`` which\n provides output formats as attributes which are convenient to call\n in ``format`` templates.\n\n- Tools to ``format`` templates with complex namespace structures.\n\n - Given the attribute like access ``format`` templates result\n cleaner.\n - API to fill a ``format`` template like file with a YAML one.\n - API to extract an empty YAML scheletton given a template with\n substitutions.\n - Command line tool to make those two functions\n\nExample\n-------\n\n.. code:: python\n\n >>> from yamlns import namespace as ns\n >>> n = ns()\n >>> n.attribute1 = \"value1\"\n >>> ns['attribute2'] = \"value2\"\n >>> print(n.dump())\n attribute1: value1\n attribute2: value2\n\n >>> n.attribute2\n 'value2'\n >>> n['attribute1']\n 'value1'\n\n >>> n.update(ns.loads(\"\"\"\n ... attribute3: value3\n ... attribute4:\n ... attribute5: [ 4,3,2,value5 ] \n ... attribute6: 2015-09-23\n ... attribute7:\n ... - value7.1\n ... - value7.2\n ... \"\"\"))\n >>> n.attribute4.attribute5\n [4, 3, 2, 'value5']\n >>> n.attribute4.attribute6\n datetime.date(2015,9,23)\n >>> n.attribute7\n ['value7.1', 'value7.2']\n\nTemplating example:\n~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n >>> template = (\n ... \"{client.name} {client.midname[0]}. {client.surname} buys {item.name} \"\n ... \"by {item.price.amount:0.02f} {item.price.coin}.\"\n ... )\n ...\n >>> print(ns.fromTemplate(template).dump())\n client:\n name: ''\n midname: ''\n surname: ''\n item:\n name: ''\n price:\n amount: ''\n coin: ''\n\n >>> template.format(**ns.loads(\"\"\"\n client:\n name: 'John'\n midname: 'Archivald'\n surname: 'Doe'\n item:\n name: 'Apples'\n price:\n amount: 30\n coin: 'dollars'\n \"\"\"))\n John A. Doe buys Apples by 30.00 dollars.\n\nCommand line tools usage\n------------------------\n\n.. code:: bash\n\n nstemplate apply