forked from grisha/mod_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodpython5.tex
More file actions
708 lines (571 loc) · 29.9 KB
/
Copy pathmodpython5.tex
File metadata and controls
708 lines (571 loc) · 29.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
\chapter{Apache Configuration Directives\label{directives}}
\section{Request Handlers\label{dir-handlers}}
\subsection{Python*Handler Directive Syntax\label{dir-handlers-syn}}
\index{Python*Handler Syntax}
All request handler directives have the following syntax:
\code{Python*Handler \emph{handler [handler ...] [ | .ext [.ext ...] ] } }
Where \var{handler} is a callable object that accepts a single
argument - request object, and \var{.ext} is a file extension.
Multiple handlers can be specified on a single line, in which case
they will be called sequentially, from left to right. Same handler
directives can be specified multiple times as well, with the same
result - all handlers listed will be executed sequentially, from first
to last. If any handler in the sequence returns a value other than
\code{apache.OK}, then execution of all subsequent handlers is aborted.
The list of handlers can optionally be followed by a \code{|} followed
by one or more file extensions. This would restrict the execution of
the handler to those file extensions only. This feature only works for
handlers executed after the trans phase.
A \emph{handler} has the following syntax:
\code{module[::object]}
Where \var{module} can be a full module name (package dot notation is
accepted), and the optional \var{object} is the name of an object
inside the module.
Object can also contain dots, in which case it will be resolved from
left to right. During resolution, if mod_python encounters an object
of type \code{<class>}, it will try instantiating it passing it a single
argument, a request object.
If no object is specified, then it will default to the directive of
the handler, all lower case, with the word \samp{python}
removed. E.g. the default object for PythonAuthenHandler would be
authenhandler.
Example:
\begin{verbatim}
PythonAuthzHandler mypackage.mymodule::checkallowed
\end{verbatim}
For more information on handlers, see Overview of a Handler.
Side note: The \samp{::} was chosen for performance reasons. In order for
Python to use objects inside modules, the modules first need to be
imported. Having the separator as simply a \samp{.}, would considerably
complicate process of sequentially evaluating every word to determine
whether it is a package, module, class etc. Using the (admittedly
un-Python-like) \samp{::} takes the time consuming work of figuring out
where the module part ends and the object inside of it begins away
from mod_python resulting in a modest performance gain.
\subsection{PythonPostReadRequestHandler\label{dir-handlers-prrh}}
\index{PythonPostReadRequestHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This handler is called after the request has been read but before any
other phases have been processed. This is useful to make decisions
based upon the input header fields.
\begin{notice}
When this phase of the request is processed, the URI has not yet
been translated into a path name, therefore this directive could never
be executed by Apache if it could specified within \code{<Directory>},
\code{<Location>}, \code{<File>} directives or in an \file{.htaccess}
file. The only place this directive is allowed is the main
configuration file, and the code for it will execute in the main
interpreter. And because this phase happens before any identification
of the type of content being requested is done (i.e. is this a python
program or a gif?), the python routine specified with this handler
will be called for \emph{ALL} requests on this server (not just python
programs), which is an important consideration if performance is a
priority.
\end{notice}
\indexii{phase}{order} The handlers below are documented in order in
which phases are processed by Apache.
\subsection{PythonTransHandler\label{dir-handlers-th}}
\index{PythonTransHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This handler gives allows for an opportunity to translate the URI into
an actual filename, before the server's default rules (Alias
directives and the like) are followed.
\begin{notice}
At the time when this phase of the request is being processed, the
URI has not been translated into a path name, therefore this
directive will never be executed by Apache if specified within
\code{<Directory>}, \code{<Location>}, \code{<File>} directives or
in an \file{.htaccess} file. The only place this can be specified is
the main configuration file, and the code for it will execute in the
main interpreter.
\end{notice}
\subsection{PythonHeaderParserHandler\label{dir-handlers-hph}}
\index{PythonHeaderParserHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This handler is called to give the module a chance to look at the
request headers and take any appropriate specific actions early in the
processing sequence.
\subsection{PythonInitHandler\label{dir-handlers-pih}}
\index{PythonInitHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This handler is the first handler called in the request processing
phases that is allowed both inside and outside \file{.htaccess} and
directory.
This handler is actually an alias to two different handlers. When
specified in the main config file outside any directory tags, it is an
alias to \code{PostReadRequestHandler}. When specified inside directory
(where \code{PostReadRequestHandler} is not allowed), it aliases to
\code{PythonHeaderParserHandler}.
\emph{(This idea was borrowed from mod_perl)}
\subsection{PythonAccessHandler\label{dir-handlers-ach}}
\index{PythonAccessHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This routine is called to check for any module-specific restrictions
placed upon the requested resource.
For example, this can be used to restrict access by IP number. To do
so, you would return \code{HTTP_FORBIDDEN} or some such to indicate
that access is not allowed.
\subsection{PythonAuthenHandler\label{dir-handlers-auh}}
\index{PythonAuthenHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This routine is called to check the authentication information sent
with the request (such as looking up the user in a database and
verifying that the [encrypted] password sent matches the one in the
database).
To obtain the username, use \code{req.user}. To obtain the password
entered by the user, use the \code{req.get_basic_auth_pw()} function.
A return of \code{apache.OK} means the authentication succeeded. A
return of \code{apache.HTTP_UNAUTHORIZED} with most browser will bring
up the password dialog box again. A return of
\code{apache.HTTP_FORBIDDEN} will usually show the error on the
browser and not bring up the password dialog
\code{again. HTTP_FORBIDDEN} should be used when authentication
succeeded, but the user is not permitted to access a particular URL.
An example authentication handler might look like this:
\begin{verbatim}
def authenhandler(req):
pw = req.get_basic_auth_pw()
user = req.user
if user == "spam" and pw == "eggs":
return apache.OK
else:
return apache.HTTP_UNAUTHORIZED
\end{verbatim}
\begin{notice}
\code{req.get_basic_auth_pw()} must be called prior to using the
\code{req.user} value. Apache makes no attempt to decode the
authentication information unless \code{req.get_basic_auth_pw()} is called.
\end{notice}
\subsection{PythonAuthzHandler\label{dir-handlers-auzh}}
\index{PythonAuthzHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This handler runs after AuthenHandler and is intended for checking
whether a user is allowed to access a particular resource. But more
often than not it is done right in the AuthenHandler.
\subsection{PythonTypeHandler\label{dir-handlers-tph}}
\index{PythonTypeHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This routine is called to determine and/or set the various document
type information bits, like Content-type (via \code{r->content_type}),
language, et cetera.
\subsection{PythonFixupHandler\label{dir-handlers-fuh}}
\index{PythonFixupHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This routine is called to perform any module-specific fixing of header
fields, et cetera. It is invoked just before any content-handler.
\subsection{PythonHandler\label{dir-handlers-ph}}
\index{PythonHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This is the main request handler. Many applications will only provide
this one handler.
\subsection{PythonLogHandler\label{dir-handlers-plh}}
\index{PythonLogHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This routine is called to perform any module-specific logging
activities.
\subsection{PythonCleanupHandler\label{dir-handlers-pch}}
\index{PythonCleanupHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
\emph{Python*Handler Syntax}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
This is the very last handler, called just before the request object
is destroyed by Apache.
Unlike all the other handlers, the return value of this handler is
ignored. Any errors will be logged to the error log, but will not be
sent to the client, even if PythonDebug is On.
This handler is not a valid argument to the \code{rec.add_handler()}
function. For dynamic clean up registration, use
\code{req.register_cleanup()}.
Once cleanups have started, it is not possible to register more of
them. Therefore, \code{req.register_cleanup()} has no effect within this
handler.
Cleanups registered with this directive will execute \emph{after} cleanups
registered with \code{req.register_cleanup()}.
\section{Filters\label{dir-filter}}
\subsection{PythonInputFilter\label{dir-filter-if}}
\index{PythonInputFilter}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonInputFilter handler name\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Registers an input filter \var{handler} under name
\var{name}. \var{Handler} is a module name optionally followed
\code{::} and a callable object name. If callable object name is
omitted, it will default to \samp{inputfilter}. \var{Name} is the name under
which the filter is registered, by convention filter names are usually
in all caps.
To activate the filter, use the \code{AddInputFilter} directive.
\subsection{PythonOutputFilter\label{dir-filter-of}}
\index{PythonOutputFilter}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonOutputFilter handler name\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Registers an output filter \var{handler} under name
\var{name}. \var{Handler} is a module name optionally followed
\code{::} and a callable object name. If callable object name is
omitted, it will default to \samp{outputfilter}. \var{Name} is the name under
which the filter is registered, by convention filter names are usually
in all caps.
To activate the filter, use the \code{AddOutputFilter} directive.
\section{Connection Handler\label{dir-conn}}
\subsection{PythonConnectionHandler\label{dir-conn-ch}}
\index{PythonConnectionHandler}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonConnectionHandler handler\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Specifies that the connection should be handled with \var{handler}
connection handler. \var{Handler} will be passed a single argument -
the connection object.
\var{Handler} is a module name optionally followed \code{::} and a
callable object name. If callable object name is omitted, it will
default to \samp{connectionhandler}.
\section{Other Directives\label{dir-other}}
\subsection{PythonEnablePdb\label{dir-other-epd}}
\index{PythonEnablePdb}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonEnablePdb \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonEnablePdb Off\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
When On, mod_python will execute the handler functions within the
Python debugger pdb using the \code{pdb.runcall()} function.
Because pdb is an interactive tool, start httpd from the command line
with the -DONE_PROCESS option when using this directive. As soon as
your handler code is entered, you will see a Pdb prompt allowing you
to step through the code and examine variables.
\subsection{PythonDebug\label{dir-other-pd}}
\index{PythonDebug}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonDebug \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonDebug Off\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Normally, the traceback output resulting from uncaught Python errors
is sent to the error log. With PythonDebug On directive specified, the
output will be sent to the client (as well as the log), except when
the error is \exception{IOError} while writing, in which case it will go
to the error log.
This directive is very useful during the development process. It is
recommended that you do not use it production environment as it may
reveal to the client unintended, possibly sensitive security
information.
\subsection{PythonImport\label{dir-other-pimp}}
\index{PythonImport}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonImport \emph{module} \emph{interpreter_name}\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Tells the server to import the Python module module at process startup
under the specified interpreter name. This is useful for
initialization tasks that could be time consuming and should not be
done at the request processing time, e.g. initializing a database
connection.
The import takes place at child process initialization, so the module
will actually be imported once for every child process spawned.
\begin{notice}
At the time when the import takes place, the configuration is not
completely read yet, so all other directives, including
PythonInterpreter have no effect on the behavior of modules imported
by this directive. Because of this limitation, the interpreter must
be specified explicitly, and must match the name under which
subsequent requests relying on this operation will execute. If you
are not sure under what interpreter name a request is running,
examine the \member{interpreter} member of the request object.
\end{notice}
See also Multiple Interpreters.
\subsection{PythonInterpPerDirectory\label{dir-other-ipd}}
\index{PythonInterpPerDirectory}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonInterpPerDirectory \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonInterpPerDirectory Off\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Instructs mod_python to name subinterpreters using the directory of
the file in the request (\code{req.filename}) rather than the the
server name. This means that scripts in different directories will
execute in different subinterpreters as opposed to the default policy
where scripts in the same virtual server execute in the same
subinterpreter, even if they are in different directories.
For example, assume there is a
\file{/directory/subdirectory}. \file{/directory} has an .htaccess
file with a PythonHandler directive. \file{/directory/subdirectory}
doesn't have an .htaccess. By default, scripts in /directory and
\file{/directory/subdirectory} would execute in the same interpreter assuming
both directories are accessed via the same virtual server. With
PythonInterpPerDirectory, there would be two different interpreters,
one for each directory.
\begin{notice}
In early phases of the request prior to the URI translation
(PostReadRequestHandler and TransHandler) the path is not yet known
because the URI has not been translated. During those phases and
with PythonInterpPerDirectory on, all python code gets executed in
the main interpreter. This may not be exactly what you want, but
unfortunately there is no way around this.
\end{notice}
\begin{seealso}
\seetitle[pyapi-interps.html]{Section \ref{pyapi-interps} Multiple Interpreters}
{for more information}
\end{seealso}
\subsection{PythonInterpPerDirective\label{dir-other-ipdv}}
\index{PythonPythonInterpPerDirective}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonInterpPerDirective \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonInterpPerDirective Off\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Instructs mod_python to name subinterpreters using the directory in
which the Python*Handler directive currently in effect was
encountered.
For example, assume there is a
\file{/directory/subdirectory}. \file{/directory} has an .htaccess
file with a PythonHandler directive. \file{/directory/subdirectory}
has another \file{.htaccess} file with another PythonHandler. By
default, scripts in \file{/directory} and
\file{/directory/subdirectory} would execute in the same interpreter
assuming both directories are in the same virtual server. With
PythonInterpPerDirective, there would be two different interpreters,
one for each directive.
\begin{seealso}
\seetitle[pyapi-interps.html]{Section \ref{pyapi-interps} Multiple Interpreters}
{for more information}
\end{seealso}
\subsection{PythonInterpreter\label{dir-other-pi}}
\index{PythonInterpreter}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonInterpreter name \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Forces mod_python to use interpreter named \emph{name}, overriding the
default behaviour or behaviour dictated by
\citetitle[dir-other-ipd.html]{\code{PythonInterpPerDirectory}} or
\citetitle[dir-other-ipdv.html]{\code{PythonInterpPerDirective}} directive.
This directive can be used to force execution that would normally
occur in different subinterpreters to run in the same one. When
specified in the DocumentRoot, it forces the whole server to run in one
subinterpreter.
\begin{seealso}
\seetitle[pyapi-interps.html]{Section \ref{pyapi-interps} Multiple Interpreters}
{for more information}
\end{seealso}
\subsection{PythonHandlerModule\label{dir-other-phm}}
\index{PythonHandlerModule}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonHandlerModule module \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
PythonHandlerModule can be used an alternative to Python*Handler
directives. The module specified in this handler will be searched for
existence of functions matching the default handler function names,
and if a function is found, it will be executed.
For example, instead of:
\begin{verbatim}
PythonAuthenHandler mymodule
PythonHandler mymodule
PythonLogHandler mymodule
\end{verbatim}
one can simply say
\begin{verbatim}
PythonHandlerModule mymodule
\end{verbatim}
\subsection{PythonAutoReload\label{dir-other-par}}
\index{PythonAutoReload}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonAutoReload \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonAutoReload On\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
If set to Off, instructs mod_python not to check the modification date
of the module file.
By default, mod_python checks the time-stamp of the file and reloads
the module if the module's file modification date is later than the
last import or reload. This way changed modules get automatically
reimported, eliminating the need to restart the server for every
change.
Disabling autoreload is useful in production environment where the
modules do not change; it will save some processing time and give a
small performance gain.
\subsection{PythonOptimize\label{dir-other-pomz}}
\index{PythonOptimize}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonOptimize \{On, Off\} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Default]{Default:}
PythonOptimize Off\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Enables Python optimization. Same as the Python \programopt{-O} option.
\subsection{PythonOption\label{dir-other-po}}
\index{PythonOption}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonOption key [value] \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
Assigns a key value pair to a table that can be later retrieved by the
\code{req.get_options()} function. This is useful to pass information
between the apache configuration files (\file{httpd.conf},
\file{.htaccess}, etc) and the Python programs. If the value is omitted or empty (\code{""}),
then the key is removed from the local configuration.
\subsection{PythonPath\label{dir-other-pp}}
\index{PythonPath}
\strong{\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Syntax]{Syntax:}}
PythonPath \emph{path} \\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Context]{Context:}
server config, virtual host, directory, htaccess\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Override]{Override:}
not None\\
\citetitle[http://httpd.apache.org/docs-2.0/mod/directive-dict.html#Module]{Module:}
mod_python.c
PythonPath directive sets the PythonPath. The path must be specified
in Python list notation, e.g.
\begin{verbatim}
PythonPath "['/usr/local/lib/python2.0', '/usr/local/lib/site_python', '/some/other/place']"
\end{verbatim}
The path specified in this directive will replace the path, not add to
it. However, because the value of the directive is evaled, to append a
directory to the path, one can specify something like
\begin{verbatim}
PythonPath "sys.path+['/mydir']"
\end{verbatim}
Mod_python tries to minimize the number of evals associated with the
PythonPath directive because evals are slow and can negatively impact
performance, especially when the directive is specified in an
\file{.htaccess} file which gets parsed at every hit. Mod_python will
remember the arguments to the PythonPath directive in the un-evaled
form, and before evaling the value it will compare it to the
remembered value. If the value is the same, no action is
taken. Because of this, you should not rely on the directive as a way
to restore the pythonpath to some value if your code changes it.
\begin{notice}
This directive should not be used as a security measure since the
Python path is easily manipulated from within the scripts.
\end{notice}