~ubuntu-branches/ubuntu/dapper/libapache2-mod-python/dapper

« back to all changes in this revision

Viewing changes to doc-html/hand-pub-alg-trav.html

  • Committer: Bazaar Package Importer
  • Author(s): Thom May
  • Date: 2004-09-06 20:27:57 UTC
  • Revision ID: james.westby@ubuntu.com-20040906202757-yzpyu1bcabgpjtiu
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 
2
<html>
 
3
<head>
 
4
<title>6.1.2.1 Traversal</title>
 
5
<META NAME="description" CONTENT="6.1.2.1 Traversal">
 
6
<META NAME="keywords" CONTENT="modpython">
 
7
<META NAME="resource-type" CONTENT="document">
 
8
<META NAME="distribution" CONTENT="global">
 
9
<link rel="STYLESHEET" href="modpython.css">
 
10
<link rel="first" href="modpython.html">
 
11
<link rel="contents" href="contents.html" title="Contents">
 
12
<link rel="index" href="genindex.html" title="Index">
 
13
<LINK REL="next" href="hand-pub-alg-args.html">
 
14
<LINK REL="previous" href="hand-pub-alg.html">
 
15
<LINK REL="up" href="hand-pub-alg.html">
 
16
<LINK REL="next" href="hand-pub-alg-args.html">
 
17
</head>
 
18
<body>
 
19
<DIV CLASS="navigation">
 
20
<table align="center" width="100%" cellpadding="0" cellspacing="2">
 
21
<tr>
 
22
<td><A href="hand-pub-alg.html"><img src="icons/previous.gif"
 
23
  border="0" height="32"
 
24
  alt="Previous Page" width="32"></A></td>
 
25
<td><A href="hand-pub-alg.html"><img src="icons/up.gif"
 
26
  border="0" height="32"
 
27
  alt="Up One Level" width="32"></A></td>
 
28
<td><A href="hand-pub-alg-args.html"><img src="icons/next.gif"
 
29
  border="0" height="32"
 
30
  alt="Next Page" width="32"></A></td>
 
31
<td align="center" width="100%">Mod_python Manual</td>
 
32
<td><A href="contents.html"><img src="icons/contents.gif"
 
33
  border="0" height="32"
 
34
  alt="Contents" width="32"></A></td>
 
35
<td><img src="icons/blank.gif"
 
36
  border="0" height="32"
 
37
  alt="" width="32"></td>
 
38
<td><A href="genindex.html"><img src="icons/index.gif"
 
39
  border="0" height="32"
 
40
  alt="Index" width="32"></A></td>
 
41
</tr></table>
 
42
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
 
43
<b class="navlabel">Up:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
 
44
<b class="navlabel">Next:</b> <a class="sectref" href="hand-pub-alg-args.html">6.1.2.2 Argument Matching and</A>
 
45
<br><hr>
 
46
</DIV>
 
47
<!--End of Navigation Panel-->
 
48
 
 
49
<H3><A NAME="SECTION008121000000000000000">&nbsp;</A>
 
50
<BR>
 
51
6.1.2.1 Traversal
 
52
</H3>
 
53
 
 
54
<P>
 
55
The Publisher handler locates and imports the module specified in the
 
56
URI. The module location is determined from the <tt class="class">req.filename</tt>
 
57
attribute. Before importing, the file extension, if any, is
 
58
discarded. 
 
59
 
 
60
<P>
 
61
If <tt class="class">req.filename</tt> is empty, the module name defaults to
 
62
"<tt class="samp">index</tt>".
 
63
 
 
64
<P>
 
65
Once module is imported, the remaining part of the URI up to the
 
66
beginning of any query data (a.k.a. PATH_INFO) is used to find an
 
67
object within the module. The Publisher handler <i class="dfn">traverses</i> the 
 
68
path, one element at a time from left to right, mapping the elements
 
69
to Python object within the module.
 
70
 
 
71
<P>
 
72
If no path_info was given in the URL, the Publisher handler will use
 
73
the default value of "<tt class="samp">index</tt>". If the last element is an object inside
 
74
a module, and the one immediately preceding it is a directory
 
75
(i.e. no module name is given), then the module name will also default
 
76
to "<tt class="samp">index</tt>".
 
77
 
 
78
<P>
 
79
The traversal will stop and <tt class="constant">HTTP_NOT_FOUND</tt> will be returned to
 
80
the client if:
 
81
 
 
82
<P>
 
83
 
 
84
<UL>
 
85
<LI>Any of the traversed object's names begin with an underscore
 
86
  ("<tt class="samp">_</tt>"). Use underscores to protect objects that should not be
 
87
  accessible from the web.
 
88
 
 
89
<P>
 
90
</LI>
 
91
<LI>A module is encountered. Published objects cannot be modules for
 
92
  security reasons.
 
93
 
 
94
<P>
 
95
</LI>
 
96
</UL>
 
97
 
 
98
<P>
 
99
If an object in the path could not be found, <tt class="constant">HTTP_NOT_FOUND</tt>
 
100
is returned to the client.
 
101
 
 
102
<P>
 
103
For example, given the following configuration:
 
104
 
 
105
<P>
 
106
<dl><dd><pre class="verbatim">
 
107
  DocumentRoot /some/dir
 
108
 
 
109
  &lt;Directory /some/dir&gt;
 
110
  SetHandler mod_python
 
111
  PythonHandler mod_python.publisher
 
112
  &lt;/Directory&gt;
 
113
</pre></dl>
 
114
 
 
115
<P>
 
116
And the following <span class="file">/some/dir/index.py</span> file:
 
117
 
 
118
<P>
 
119
<dl><dd><pre class="verbatim">
 
120
  def index(req):
 
121
 
 
122
  return "We are in index()"
 
123
 
 
124
  def hello(req):
 
125
 
 
126
  return "We are in hello()"
 
127
</pre></dl>
 
128
 
 
129
<P>
 
130
Then:
 
131
 
 
132
<P>
 
133
http://www.somehost/index/index will return "<tt class="samp">We are in index()</tt>"
 
134
<P>
 
135
http://www.somehost/index/ will return "<tt class="samp">We are in index()</tt>"
 
136
<P>
 
137
http://www.somehost/index/hello will return "<tt class="samp">We are in hello()</tt>"
 
138
<P>
 
139
http://www.somehost/hello will return "<tt class="samp">We are in hello()</tt>"
 
140
<P>
 
141
http://www.somehost/spam will return "<tt class="samp">404 Not Found</tt>"
 
142
<P>
 
143
 
 
144
<DIV CLASS="navigation">
 
145
<p><hr>
 
146
<table align="center" width="100%" cellpadding="0" cellspacing="2">
 
147
<tr>
 
148
<td><A href="hand-pub-alg.html"><img src="icons/previous.gif"
 
149
  border="0" height="32"
 
150
  alt="Previous Page" width="32"></A></td>
 
151
<td><A href="hand-pub-alg.html"><img src="icons/up.gif"
 
152
  border="0" height="32"
 
153
  alt="Up One Level" width="32"></A></td>
 
154
<td><A href="hand-pub-alg-args.html"><img src="icons/next.gif"
 
155
  border="0" height="32"
 
156
  alt="Next Page" width="32"></A></td>
 
157
<td align="center" width="100%">Mod_python Manual</td>
 
158
<td><A href="contents.html"><img src="icons/contents.gif"
 
159
  border="0" height="32"
 
160
  alt="Contents" width="32"></A></td>
 
161
<td><img src="icons/blank.gif"
 
162
  border="0" height="32"
 
163
  alt="" width="32"></td>
 
164
<td><A href="genindex.html"><img src="icons/index.gif"
 
165
  border="0" height="32"
 
166
  alt="Index" width="32"></A></td>
 
167
</tr></table>
 
168
<b class="navlabel">Previous:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
 
169
<b class="navlabel">Up:</b> <a class="sectref" href="hand-pub-alg.html">6.1.2 The Publishing Algorithm</A>
 
170
<b class="navlabel">Next:</b> <a class="sectref" href="hand-pub-alg-args.html">6.1.2.2 Argument Matching and</A>
 
171
<hr>
 
172
<span class="release-info">Release 3.1.3, documentation updated on February 17, 2004.</span>
 
173
</DIV>
 
174
<!--End of Navigation Panel-->
 
175
 
 
176
</BODY>
 
177
</HTML>