summaryrefslogtreecommitdiff
path: root/docs/tutorials/lxmlgraph/step02/myapp/models.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-05-01 10:26:57 +0000
committerChris McDonough <chrism@agendaless.com>2009-05-01 10:26:57 +0000
commitba9b0e647bff1bf0c437ab204ddf11783ed698f8 (patch)
tree1952ebfdc40ae71a3bc54eb10a92a0fe1e8273ec /docs/tutorials/lxmlgraph/step02/myapp/models.py
parentbc0698e1ac67106346d8c006bddcb38370f7c16b (diff)
downloadpyramid-ba9b0e647bff1bf0c437ab204ddf11783ed698f8.tar.gz
pyramid-ba9b0e647bff1bf0c437ab204ddf11783ed698f8.tar.bz2
pyramid-ba9b0e647bff1bf0c437ab204ddf11783ed698f8.zip
Merge "c-free" branch to trunk.
Diffstat (limited to 'docs/tutorials/lxmlgraph/step02/myapp/models.py')
-rw-r--r--docs/tutorials/lxmlgraph/step02/myapp/models.py42
1 files changed, 0 insertions, 42 deletions
diff --git a/docs/tutorials/lxmlgraph/step02/myapp/models.py b/docs/tutorials/lxmlgraph/step02/myapp/models.py
deleted file mode 100644
index 1d93ccdd0..000000000
--- a/docs/tutorials/lxmlgraph/step02/myapp/models.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import os
-
-from zope.interface import implements
-from zope.interface import Attribute
-from zope.interface import Interface
-from lxml import etree
-
-class IMyModel(Interface):
- __name__ = Attribute('Name of the model instance')
-
-class BfgElement(etree.ElementBase):
- """Handle access control and getitem behavior"""
-
- implements(IMyModel)
-
- @property
- def __name__(self):
- return self.xpath("@name")[0]
-
- def __getitem__(self, child_name):
- xp = "*[@name='%s']" % child_name
- matches = self.xpath(xp)
- if len(matches) == 0:
- raise KeyError('No child found for %s' % child_name)
- elif len(matches) > 1:
- raise KeyError('More than one child for %s' % child_name)
- else:
- return matches[0]
-
-def get_root(environ):
- # Setup the custom parser with our BfgElement behavior
- parser_lookup = etree.ElementDefaultClassLookup(element=BfgElement)
- parser = etree.XMLParser()
- parser.set_element_class_lookup(parser_lookup)
-
- # Now load the XML file
- here = os.path.join(os.path.dirname(__file__))
- samplemodel = os.path.join(here, 'samplemodel.xml')
- xmlstring = open(samplemodel).read()
- root = etree.XML(xmlstring, parser)
-
- return root