{ "info": { "author": "Richard Jones", "author_email": "rjones@ekit-inc.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Code Generators", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Text Processing :: Markup :: HTML" ], "description": "Simple, elegant HTML, XHTML and XML generation.\n\nConstructing your HTML\n----------------------\n\nTo construct HTML start with an instance of ``html.HTML()``. Add\ntags by accessing the tag's attribute on that object. For example:\n\n>>> from html import HTML\n>>> h = HTML()\n>>> h.p('Hello, world!')\n>>> print(h)\n

Hello, world!

\n\nYou may supply a tag name and some text contents when creating a HTML\ninstance:\n\n>>> h = HTML('html', 'text')\n>>> print(h)\ntext\n\nYou may also append text content later using the tag's ``.text()`` method\nor using augmented addition ``+=``. Any HTML-specific characters (``<>&\"``)\nin the text will be escaped for HTML safety as appropriate unless\n``escape=False`` is passed. Each of the following examples uses a new\n``HTML`` instance:\n\n>>> p = h.p('hello world!\\n')\n>>> p.br\n>>> p.text('more → text', escape=False)\n>>> p += ' ... augmented'\n>>> h.p\n>>> print(h)\n

hello, world!
more → text ... augmented

\n

\n\nNote also that the top-level ``HTML`` object adds newlines between tags by\ndefault. Finally in the above you'll see an empty paragraph tag - tags with\nno contents get no closing tag.\n\nIf the tag should have sub-tags you have two options. You may either add\nthe sub-tags directly on the tag:\n\n>>> l = h.ol\n>>> l.li('item 1')\n>>> l.li.b('item 2 > 1')\n>>> print(h)\n

    \n
  1. item 1
  2. \n
  3. item 2 > 1
  4. \n
\n\nNote that the default behavior with lists (and tables) is to add newlines\nbetween sub-tags to generate a nicer output. You can also see in that\nexample the chaining of tags in ``l.li.b``.\n\nTag attributes may be passed in as well:\n\n>>> t = h.table(border='1')\n>>> for i in range(2):\n>>> r = t.tr\n>>> r.td('column 1')\n>>> r.td('column 2')\n>>> print(t)\n\n\n\n
column 1column 2
column 1column 2
\n\nA variation on the above is to use a tag as a context variable. The\nfollowing is functionally identical to the first list construction but\nwith a slightly different sytax emphasising the HTML structure:\n\n>>> with h.ol as l:\n... l.li('item 1')\n... l.li.b('item 2 > 1')\n\nYou may turn off/on adding newlines by passing ``newlines=False`` or\n``True`` to the tag (or ``HTML`` instance) at creation time:\n\n>>> l = h.ol(newlines=False)\n>>> l.li('item 1')\n>>> l.li('item 2')\n>>> print(h)\n
  1. item 1
  2. item 2
\n\nSince we can't use ``class`` as a keyword, the library recognises ``klass``\nas a substitute:\n\n>>> print(h.p(content, klass=\"styled\"))\n

content

\n\n\nUnicode\n-------\n\n``HTML`` will work with either regular strings **or** unicode strings, but\nnot **both at the same time**.\n\nObtain the final unicode string by calling ``unicode()`` on the ``HTML``\ninstance:\n\n>>> h = HTML()\n>>> h.p(u'Some Euro: \u20ac1.14')\n>>> unicode(h)\nu'

Some Euro: \u20ac1.14

'\n\nIf (under Python 2.x) you add non-unicode strings or attempt to get the\nresultant HTML source through any means other than ``unicode()`` then you\nwill most likely get one of the following errors raised:\n\nUnicodeDecodeError\n Probably means you've added non-unicode strings to your HTML.\nUnicodeEncodeError\n Probably means you're trying to get the resultant HTML using ``print``\n or ``str()`` (or ``%s``).\n\n\nHow generation works\n--------------------\n\nThe HTML document is generated when the ``HTML`` instance is \"stringified\".\nThis could be done either by invoking ``str()`` on it, or just printing it.\nIt may also be returned directly as the \"iterable content\" from a WSGI app\nfunction.\n\nYou may also render any tag or sub-tag at any time by stringifying it.\n\nTags with no contents (either text or sub-tags) will have no closing tag.\nThere is no \"special list\" of tags that must always have closing tags, so\nif you need to force a closing tag you'll need to provide some content,\neven if it's just a single space character.\n\nRendering doesn't affect the HTML document's state, so you can add to or\notherwise manipulate the HTML after you've stringified it.\n\n\nCreating XHTML\n--------------\n\nTo construct XHTML start with an instance of ``html.XHTML()`` and use it\nas you would an ``HTML`` instance. Empty elements will now be rendered\nwith the appropriate XHTML minimized tag syntax. For example:\n\n>>> from html import XHTML\n>>> h = XHTML()\n>>> h.p\n>>> h.br\n>>> print(h)\n

\n
\n\n\nCreating XML\n------------\n\nA slight tweak to the ``html.XHTML()`` implementation allows us to generate\narbitrary XML using ``html.XML()``:\n\n>>> from html import XML\n>>> h = XML('xml')\n>>> h.p\n>>> h.br('hi there')\n>>> print(h)\n\n

\n
hi there
\n\n\n\nTags with difficult names\n-------------------------\n\nIf your tag name isn't a valid Python identifier name, or if it's called\n\"text\" or \"raw_text\" you can add your tag slightly more manually:\n\n>>> from html import XML\n>>> h = XML('xml')\n>>> h += XML('some-tag', 'some text')\n>>> h += XML('text', 'some text')\n>>> print(h)\n\nsome text\nsome text\n\n\n\nVersion History (in Brief)\n--------------------------\n\n- 1.19 produce a universal wheel\n- 1.17 repackage it as \"pml\" since \"html\" clashes with the\n homonymous py3 stdlib module\n- 1.16 detect and raise a more useful error when some WSGI frameworks\n attempt to call HTML.read(). Also added ability to add new content using\n the += operator.\n- 1.15 fix Python 3 compatibility (unit tests)\n- 1.14 added plain XML support\n- 1.13 allow adding (X)HTML instances (tags) as new document content\n- 1.12 fix handling of XHTML empty tags when generating unicode\n output (thanks Carsten Eggers)\n- 1.11 remove setuptools dependency\n- 1.10 support plain ol' distutils again\n- 1.9 added unicode support for Python 2.x\n- 1.8 added Python 3 compatibility\n- 1.7 added Python 2.5 compatibility and escape argument to tag\n construction\n- 1.6 added .raw_text() and and WSGI compatibility\n- 1.5 added XHTML support\n- 1.3 added more documentation, more tests\n- 1.2 added special-case klass / class attribute\n- 1.1 added escaping control\n- 1.0 was the initial release\n\n----\n\nThis code is copyright 2009-2011 eKit.com Inc (http://www.ekit.com/)\nSee the end of the source file for the license of use.\nXHTML support was contributed by Michael Haubenwallner.\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/pml", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "pml", "package_url": "https://pypi.org/project/pml/", "platform": "", "project_url": "https://pypi.org/project/pml/", "project_urls": { "Homepage": "http://pypi.python.org/pypi/pml" }, "release_url": "https://pypi.org/project/pml/1.20/", "requires_dist": null, "requires_python": "", "summary": "simple, elegant HTML, XHTML and XML generation", "version": "1.20" }, "last_serial": 3973979, "releases": { "1.17": [ { "comment_text": "", "digests": { "md5": "633ca0bd96a82bf44eb86293f453ceb9", "sha256": "c1eef630011d740d377271ed5cc66e4f84766fe6accae5c17fcf01fb38b3af50" }, "downloads": -1, "filename": "pml-1.17-py3-none-any.whl", "has_sig": false, "md5_digest": "633ca0bd96a82bf44eb86293f453ceb9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12234, "upload_time": "2017-10-02T15:53:58", "url": "https://files.pythonhosted.org/packages/12/13/30a2d1a1966e2a8e9c4b494e7e2e456a4584cdc05f9d4b79b1577d2b030a/pml-1.17-py3-none-any.whl" } ], "1.18": [ { "comment_text": "", "digests": { "md5": "1a60e1e399a47b1a78fe65a2804bdd84", "sha256": "71b6fb03712d1d3d3f4dd0e82e7408c22c054325aff8231acefe3ff13d5250d2" }, "downloads": -1, "filename": "pml-1.18-py3-none-any.whl", "has_sig": false, "md5_digest": "1a60e1e399a47b1a78fe65a2804bdd84", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12054, "upload_time": "2017-10-30T15:13:00", "url": "https://files.pythonhosted.org/packages/5a/20/ce8d9bf5fa9eba7acb8c3cab81bd6177d239a447af56aaa35e8d77634f2e/pml-1.18-py3-none-any.whl" } ], "1.19": [ { "comment_text": "", "digests": { "md5": "1bcd86e985026fe5e2300cec055048e5", "sha256": "b4f320ad76ac721a1d3c80fc9a4199c675e0846e5a793c8b08d09158023633d0" }, "downloads": -1, "filename": "pml-1.19-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1bcd86e985026fe5e2300cec055048e5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 12115, "upload_time": "2017-11-14T11:11:26", "url": "https://files.pythonhosted.org/packages/1d/43/40580da5a88866e01fafef9cd940ce55128ff645e6531f926472163fd7f5/pml-1.19-py2.py3-none-any.whl" } ], "1.20": [ { "comment_text": "", "digests": { "md5": "dce48ba3f87e20daf12a79e8f787cfcb", "sha256": "5fea69795428e157ee10fab49f657a129a7b9179f01b970bc402fdf5380d3012" }, "downloads": -1, "filename": "pml-1.20-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dce48ba3f87e20daf12a79e8f787cfcb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8608, "upload_time": "2018-06-18T15:18:25", "url": "https://files.pythonhosted.org/packages/07/92/959bc42c97d8b085db9653324a977fdfde1c6ebcf51aa3b26452715b72b0/pml-1.20-py2.py3-none-any.whl" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "dce48ba3f87e20daf12a79e8f787cfcb", "sha256": "5fea69795428e157ee10fab49f657a129a7b9179f01b970bc402fdf5380d3012" }, "downloads": -1, "filename": "pml-1.20-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "dce48ba3f87e20daf12a79e8f787cfcb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8608, "upload_time": "2018-06-18T15:18:25", "url": "https://files.pythonhosted.org/packages/07/92/959bc42c97d8b085db9653324a977fdfde1c6ebcf51aa3b26452715b72b0/pml-1.20-py2.py3-none-any.whl" } ] }