{
"info": {
"author": "Martijn Faassen",
"author_email": "faassen@startifact.com",
"bugtrack_url": null,
"classifiers": [],
"description": "Classix\n*******\n\nIntroduction\n============\n\nClassix is a thin layer over lxml's `custom element classes`_\nfunctionality that lets you configure them declaratively. It uses\nMartian_ to accomplish this effect, but to you this should be an\nimplementation detail.\n\n.. _`custom element classes`: http://codespeak.net/lxml/element_classes.html\n\n.. _`Martian`: http://pypi.python.org/pypi/martian\n\nTo parse an XML document you need a parser. An `XMLParser`` can be\nconfigured with custom element classes that will be associated to the\nright elements in the XML document after parsing. This way you can\nenrich the content model of your XML document.\n\nThe approach\n============\n\nFirst we need to do the configuration for this package. This only needs to\nhappen once for this package. First, we need to set up a ``GrokkerRegistry``.\n\n >>> import martian\n >>> reg = martian.GrokkerRegistry()\n\nNow we can grok the grokkers in this package::\n\n >>> from classix import meta\n >>> reg.grok('meta', meta)\n True\n\nNow we can start using classix. You need to create an ``XMLParser``\nclass that you will associate your custom element classes with::\n\n >>> import classix\n >>> class MyParser(classix.XMLParser):\n ... pass\n\nLet's grok the parser::\n\n >>> reg.grok('MyParser', MyParser)\n True\n\nNow you can set up classes to associate with particular elements in particular\nnamespaces, for that parser::\n\n >>> XMLNS = 'http://ns.example.com'\n >>> class Test(classix.Element):\n ... classix.namespace(XMLNS)\n ... classix.parser(MyParser)\n ... \n ... def custom_method(self):\n ... return \"The custom method\"\n\nWe also need to grok this::\n\n >>> reg.grok('Test', Test)\n True\n\nNow that we have it all set up, we can initialize the parser::\n\n >>> parser = MyParser()\n\nLet's parse a bit of XML::\n\n >>> xml = '''\\\n ... \n ... '''\n >>> from lxml import etree\n >>> root = etree.XML(xml, parser)\n >>> root.custom_method()\n 'The custom method'\n\nNo namespace\n============\n\nSometimes you want to associate a class with an element in no\nnamespace at all. Do do this, you can set the namepace to None\nexplicitly::\n\n >>> reg = martian.GrokkerRegistry()\n >>> reg.grok('meta', meta)\n True\n\n >>> class MyParser(classix.XMLParser):\n ... pass\n >>> reg.grok('MyParser', MyParser)\n True\n >>> class Test(classix.Element):\n ... classix.namespace(None)\n ... classix.parser(MyParser)\n ... def custom_method(self):\n ... return 'The custom method for no namespace'\n >>> reg.grok('Test', Test)\n True\n >>> parser = MyParser()\n >>> no_ns_xml = '''\\\n ... \n ... '''\n >>> root = etree.XML(no_ns_xml, parser)\n >>> root.custom_method()\n 'The custom method for no namespace'\n\nWhen supplied with an element with a namespace, the ``Test`` class will\nnot be associated with that element::\n\n >>> root = etree.XML(xml, parser)\n >>> root.custom_method()\n Traceback (most recent call last):\n ...\n AttributeError: 'lxml.etree._Element' object has no attribute 'custom_method'\n\nNamespaces are assumed to be ``None`` if the ``classix.namespace``\ndirective isn't used at all::\n\n >>> class MyParser(classix.XMLParser):\n ... pass\n >>> reg.grok('MyParser', MyParser)\n True\n >>> class Test(classix.Element):\n ... classix.parser(MyParser)\n ... def custom_method(self):\n ... return 'The custom method for no namespace 2'\n >>> reg.grok('Test', Test)\n True\n >>> parser = MyParser()\n >>> no_ns_xml = '''\\\n ... \n ... '''\n >>> root = etree.XML(no_ns_xml, parser)\n >>> root.custom_method()\n 'The custom method for no namespace 2'\n\nNamespaces in parser\n====================\n\nAs a convenience, you can also configure the default namespace in the\nparser, as a fall-back so you don't have to specify it in all the\nelement classes::\n\n >>> reg = martian.GrokkerRegistry()\n >>> reg.grok('meta', meta)\n True\n\n >>> class MyParserWithNamespace(classix.XMLParser):\n ... classix.namespace(XMLNS)\n >>> reg.grok('MyParserWithNamespace', MyParserWithNamespace)\n True\n \n >>> class Test2(classix.Element):\n ... classix.parser(MyParserWithNamespace)\n ... classix.name('test') # also override name\n ... def custom_method(self):\n ... return \"Another custom method\"\n >>> reg.grok('Test2', Test2)\n True\n \n >>> parser_ns = MyParserWithNamespace()\n >>> root = etree.XML(xml, parser_ns)\n >>> root.custom_method()\n 'Another custom method'\n\nClassix changes\n***************\n\n0.5 (2008-07-07)\n================\n\n* Initial public release\n\n\nDownload\n********",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "UNKNOWN",
"keywords": null,
"license": "ZPL 2.1",
"maintainer": null,
"maintainer_email": null,
"name": "classix",
"package_url": "https://pypi.org/project/classix/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/classix/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "UNKNOWN"
},
"release_url": "https://pypi.org/project/classix/0.5/",
"requires_dist": null,
"requires_python": null,
"summary": "Declarative way to associate classes with lxml XML elements.",
"version": "0.5"
},
"last_serial": 713615,
"releases": {
"0.5": [
{
"comment_text": "",
"digests": {
"md5": "7d5fd66cc165e3e6c4935569d02bf977",
"sha256": "e0806f4968b9e6d8f6ddc198a5dd0c7c257151495af41d23e18f5ef0e17ca421"
},
"downloads": -1,
"filename": "classix-0.5.tar.gz",
"has_sig": false,
"md5_digest": "7d5fd66cc165e3e6c4935569d02bf977",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3895,
"upload_time": "2008-07-07T21:02:26",
"url": "https://files.pythonhosted.org/packages/a8/24/e79ce511815cedd55cb89f9c8208ee73bb04eb5029cb14d7c51ff3a6420e/classix-0.5.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "7d5fd66cc165e3e6c4935569d02bf977",
"sha256": "e0806f4968b9e6d8f6ddc198a5dd0c7c257151495af41d23e18f5ef0e17ca421"
},
"downloads": -1,
"filename": "classix-0.5.tar.gz",
"has_sig": false,
"md5_digest": "7d5fd66cc165e3e6c4935569d02bf977",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3895,
"upload_time": "2008-07-07T21:02:26",
"url": "https://files.pythonhosted.org/packages/a8/24/e79ce511815cedd55cb89f9c8208ee73bb04eb5029cb14d7c51ff3a6420e/classix-0.5.tar.gz"
}
]
}