summaryrefslogtreecommitdiff
path: root/docs/tutorials/lxmlgraph/step02.rst
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2008-07-28 05:31:47 +0000
committerChris McDonough <chrism@agendaless.com>2008-07-28 05:31:47 +0000
commit178623bbd8e9aab75b6206ef69f67b62edb3d12e (patch)
tree2442c1d41bdb13a41e4ab841fddcc091d5804ca2 /docs/tutorials/lxmlgraph/step02.rst
parent96e65d8e6d47a1b806c4d281e6890f77f86407c3 (diff)
downloadpyramid-178623bbd8e9aab75b6206ef69f67b62edb3d12e.tar.gz
pyramid-178623bbd8e9aab75b6206ef69f67b62edb3d12e.tar.bz2
pyramid-178623bbd8e9aab75b6206ef69f67b62edb3d12e.zip
Tweaks.
Diffstat (limited to 'docs/tutorials/lxmlgraph/step02.rst')
-rw-r--r--docs/tutorials/lxmlgraph/step02.rst39
1 files changed, 20 insertions, 19 deletions
diff --git a/docs/tutorials/lxmlgraph/step02.rst b/docs/tutorials/lxmlgraph/step02.rst
index 94aca07e4..1dc1ebcd3 100644
--- a/docs/tutorials/lxmlgraph/step02.rst
+++ b/docs/tutorials/lxmlgraph/step02.rst
@@ -6,7 +6,7 @@ We now have a project named ``lxmlgraph``. It contains a *package*
(also) named ``lxmlgraph``.
In this step we will add an XML document to the *package* as our model
-data. We will leverage the following ``repoze.bfg`` machinery:
+data. We will leverage the following :mod:`repoze.bfg` machinery:
- Model data with interfaces that define "types"
@@ -14,11 +14,11 @@ data. We will leverage the following ``repoze.bfg`` machinery:
Our application will need to do these things:
- - Use :term:`lxml` Element classes to inject ``repoze.bfg`` behavior into
- ``lxml`` nodes
+ - Use :term:`lxml` Element classes to inject :mod:`repoze.bfg`
+ behavior into ``lxml`` nodes
- - That model class needs to implement the ``repoze.bfg`` publishing
- contract
+ - That model class needs to implement the :mod:`repoze.bfg`
+ publishing contract
All of the below filenames are relative to the ``lxmlgraph`` *package*
rather than the *project*.
@@ -40,18 +40,17 @@ your package:
#. In lines 3-4, the ``<site>`` contains 2 top-level children: a and
b. These are provided as an element name ``<document>``. This,
- also, is meaningless as far as ``repoze.bfg`` is concerned.
+ also, is meaningless as far as :mod:`repoze.bfg` is concerned.
However, this is where you compose the information model you are
publishing.
The only special constraint is that an XML node that wants to be
-"found" by ``repoze.bfg`` in during traversal *must* have a ``name``
-attribute. (The use of ``@name`` corresponds to ``__name__`` in the
-``repoze.bfg`` sense of ``repoze.bfg`` :term:`location` ). Each hop
-in the URL tries to grab a child with an attribute matching the next
-hop. Also, the value of the ``@name`` should be unique in its
-containing node.
-
+"found" by :mod:`repoze.bfg` in during traversal *must* have a
+``name`` attribute. (The use of ``@name`` corresponds to ``__name__``
+in the :mod:`repoze.bfg` sense of :term:`location` ). Each hop in the
+URL tries to grab a child with an attribute matching the next hop.
+Also, the value of the ``@name`` should be unique in its containing
+node.
Module ``models.py``
------------------------------
@@ -64,7 +63,7 @@ class with the parser. Replace the contents of the autogenerated
.. literalinclude:: step02/myapp/models.py
:linenos:
-#. Line 4 imports ``lxml``.
+#. Line 4 imports :term:`lxml`.
#. Line 9 creates the custom class we are going to use to extend
etree.ElementBase. The `<lxml website
@@ -75,20 +74,20 @@ class with the parser. Replace the contents of the autogenerated
certain content type (interface.) In our case, instances will be
XML nodes.
-#. ``repoze.bfg`` has a "protocol" where model data should have an
+#. :mod:`repoze.bfg` has a protocol where model data should have an
``__name__`` attribute. Lines 14-16 implement this by grabbing the
``@name`` attribute of the current node.
-#. URL traversal in ``repoze.bfg`` works via the ``__getitem__``
+#. URL traversal in :mod:`repoze.bfg` works via the ``__getitem__``
protocol. Thus, we need a method that implements this. Lines
18-26 use XPath to look for a direct child that has an ``@name``
matching the item name that's being traversed to. If it finds it,
return it. If not, or if more than one is found, raise an error.
#. As before, ``get_root`` is the function that is expected to return
- the top of the model. In lines 30+ we do the ``lxml`` magic to get the
- custom Python class registered. We then load some XML and return
- the top of the tree.
+ the top of the model. In lines 30+ we do the :term:`lxml` magic to
+ get the custom Python class registered. We then load some XML and
+ return the top of the tree.
Module ``views.py``
-----------------------------
@@ -124,7 +123,9 @@ It will listen on port 5432. We can use these URLs to browse the
model graph and see results::
http://localhost:5432/a (Hello to document from a @ /a)
+
http://localhost:5432/b (Hello to document from b @ /b)
+
http://localhost:5432/c (Not Found)
In this case, each request grabs a node in the XML and uses it as the