You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by gr...@apache.org on 2003/07/25 07:07:58 UTC
cvs commit: httpd-python/src _pspmodule.c psp_parser.c psp_parser.l
grisha 2003/07/24 22:07:58
Modified: Doc modpython6.tex modpython4.tex
lib/python/mod_python psp.py
src _pspmodule.c psp_parser.c psp_parser.l
Log:
Added a source listing option to psp (see docs). also fixed couple of
psp bugs.
Revision Changes Path
1.15 +12 -2 httpd-python/Doc/modpython6.tex
Index: modpython6.tex
===================================================================
RCS file: /home/cvs/httpd-python/Doc/modpython6.tex,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- modpython6.tex 30 Jun 2003 19:52:58 -0000 1.14
+++ modpython6.tex 25 Jul 2003 05:07:57 -0000 1.15
@@ -266,11 +266,10 @@
\section{PSP Handler\label{hand-psp}}
-
\index{PSP}
PSP handler is a handler that processes documents using the
-\code{mod_python.psp} module. For more details on the PSP syntax, see
+\code{mod_python._psp} module. For more details on the PSP syntax, see
Section \ref{pyapi-psp}.
To use it, simply add this to your httpd configuration:
@@ -279,6 +278,17 @@
AddHandler python-program .psp
PythonHandler mod_python.psp
\end{verbatim}
+
+If \code{PythonDebug} server configuration is \code{On}, then by
+appending an underscore (\samp{_}) to the end of the url you can get a
+nice side-by-side listing of original PSP code and resulting Python
+code generated by the \code{psp} module. This is very useful for
+debugging.
+
+\begin{notice}
+Leaving debug on in a production environment will allow remote users
+to display source code of your PSP pages!
+\end{notice}
\section{CGI Handler\label{hand-cgi}}
1.41 +9 -9 httpd-python/Doc/modpython4.tex
Index: modpython4.tex
===================================================================
RCS file: /home/cvs/httpd-python/Doc/modpython4.tex,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- modpython4.tex 24 Jul 2003 20:51:08 -0000 1.40
+++ modpython4.tex 25 Jul 2003 05:07:57 -0000 1.41
@@ -1586,10 +1586,10 @@
\class{Cookie}.
\begin{notice}
- Always check the type of the object returned by
- \method{SignedCookie.parse()} is an instance of \class{Cookie}
- (as oppsed to \class{SignedCookie}), the signature verification
- failed:
+ Always check the types of objects returned by
+ \method{SignedCookie.parse()}.If it is an instance of
+ \class{Cookie} (as oppsed to \class{SignedCookie}), the
+ signature verification has failed:
\begin{verbatim}
# assume spam is supposed to be a signed cookie
if type(spam) is not Cookie.SignedCookie:
@@ -1692,22 +1692,22 @@
return apache.OK
\end{verbatim}
-\section{\module{psp} -- Python Server Pages\label{pyapi-psp}}
-\declaremodule[psp]{extension}{psp}
+\section{\module{_psp} -- Python Server Pages\label{pyapi-psp}}
+\declaremodule[psp]{extension}{_psp}
\modulesynopsis{Python Server Pages}
\moduleauthor{Gregory Trubetskoy}{grisha@modpython.org}
-The \module{psp} module provides a way to convert text documents
+The \module{_psp} module provides a way to convert text documents
(including, but not limited to HTML documents) containing Python code
embedded in special brackets into pure Python code suitable for
execution within a mod_python handler, thereby providing a versatile
mechanism for delivering dynamic content in a style similar to similar
to ASP, JSP and others.
-The parser used by \module{psp} is written in C (genrated using flex)
+The parser used by \module{_psp} is written in C (genrated using flex)
and is therefore very fast.
-Unlike other mod_python modules, \module{psp} is written in such a way
+Unlike other mod_python modules, \module{_psp} is written in such a way
that it can be imported outside of the Apache httpd process, e.g. in
stand-alone command-line programs.
1.9 +51 -4 httpd-python/lib/python/mod_python/psp.py
Index: psp.py
===================================================================
RCS file: /home/cvs/httpd-python/lib/python/mod_python/psp.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- psp.py 13 Jun 2003 02:36:23 -0000 1.8
+++ psp.py 25 Jul 2003 05:07:57 -0000 1.9
@@ -69,6 +69,7 @@
import os
import marshal
import new
+from cgi import escape
def parse(filename):
@@ -124,14 +125,60 @@
source = _psp.parse(filename)
return compile(source, filename, "exec")
+def display_code(req):
+ """
+ Display a niceliy HTML-formatted side-by-side of
+ what PSP generated next to orinial code
+ """
+
+ source = open(req.filename[:-1]).read().splitlines()
+ pycode = _psp.parse(req.filename[:-1]).splitlines()
+
+ source = [s.rstrip() for s in source]
+ pycode = [s.rstrip() for s in pycode]
+
+ req.write("<table>\n<tr>")
+ for s in ("", " PSP-produced Python Code:",
+ " %s:" % req.filename[:-1]):
+ req.write("<td><tt>%s</tt></td>" % s)
+ req.write("</tr>\n")
+
+ n = 1
+ for line in pycode:
+ req.write("<tr>")
+ left = escape(line).replace("\t", " "*4).replace(" ", " ")
+ right = escape(source[n-1]).replace("\t", " "*4).replace(" ", " ")
+ for s in ("%d. " % n,
+ "<font color=blue>%s</font>" % left,
+ " <font color=green>%s</font>" % right):
+ req.write("<td><tt>%s</tt></td>" % s)
+ req.write("</tr>\n")
+
+ n += 1
+ req.write("</table>\n")
-def handler(req):
+ return apache.OK
- code = load_file(req.filename)
+def run_psp(req):
- req.content_type = "text/html"
+ code = load_file(req.filename)
# give it it's own locals
exec code in globals(), {"req":req}
return apache.OK
+
+def handler(req):
+
+ config = req.get_config()
+ debug = config.has_key("PythonDebug")
+
+ req.content_type = "text/html"
+
+ if debug and req.filename[-1] == "_":
+ return display_code(req)
+ else:
+ return run_psp(req)
+
+
+
1.4 +5 -2 httpd-python/src/_pspmodule.c
Index: _pspmodule.c
===================================================================
RCS file: /home/cvs/httpd-python/src/_pspmodule.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- _pspmodule.c 30 May 2003 04:37:09 -0000 1.3
+++ _pspmodule.c 25 Jul 2003 05:07:57 -0000 1.4
@@ -133,7 +133,10 @@
Py_END_ALLOW_THREADS
- code = PyString_FromString(parser->pycode.blob);
+ if (parser->pycode.blob)
+ code = PyString_FromString(parser->pycode.blob);
+ else
+ code = PyString_FromString("");
psp_parser_cleanup(parser);
return code;
1.11 +2 -2 httpd-python/src/psp_parser.c
Index: psp_parser.c
===================================================================
RCS file: /home/cvs/httpd-python/src/psp_parser.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- psp_parser.c 24 Jul 2003 17:59:34 -0000 1.10
+++ psp_parser.c 25 Jul 2003 05:07:57 -0000 1.11
@@ -859,7 +859,7 @@
YY_RULE_SETUP
#line 107 "psp_parser.l"
{
- psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\"\"\")"));
+ psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\"\"\");"));
CLEAR_WHITESPACE(&PSP_PG(whitespace));
PSP_PG(seen_newline) = 0;
BEGIN PYCODE;
1.11 +2 -2 httpd-python/src/psp_parser.l
Index: psp_parser.l
===================================================================
RCS file: /home/cvs/httpd-python/src/psp_parser.l,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- psp_parser.l 24 Jul 2003 17:59:34 -0000 1.10
+++ psp_parser.l 25 Jul 2003 05:07:57 -0000 1.11
@@ -105,7 +105,7 @@
}
<TEXT>"<%" {
- psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\"\"\")"));
+ psp_string_appendl(&PSP_PG(pycode), STATIC_STR("\"\"\");"));
CLEAR_WHITESPACE(&PSP_PG(whitespace));
PSP_PG(seen_newline) = 0;
BEGIN PYCODE;