[ http://issues.apache.org/jira/browse/MODPYTHON-104?page=all ]
Graham Dumpleton updated MODPYTHON-104: --------------------------------------- Attachment: grahamd_20060126_1_mod_include.diff Attached "grahamd_20060126_1_mod_include.diff". This includes patch for adding SSI support for Python. Note that line numbers will probably not match subversion head at this time as I have a lot of other code changes in my local mod_python version. Thus, have generated context diffs, and you will need to look out at how code fits into surrounding code. What the patch implements is the ability to do stuff like the following in files for which the builtin "INCLUDES" output filter of Apache is enabled. Typically this is for .shtml files but it can be enabled explicitly for other files as well. <!--#python exec=" from mod_python import apache import cgi import sys parts = apache.import_module('parts') def _escape(object): return cgi.escape(str(object)) "--> <html> <body> <pre> <!--#python eval="_escape(str(globals().keys()))"--> <!--#python eval="_escape(str(locals().keys()))"--> <!--#python exec=" print >> filter for key in filter.req.subprocess_env: print >> filter, _escape((key, filter.req.subprocess_env[key])) "--> <!--#python eval="parts.content()"--> </pre> </body> </html> One can use either "eval" or "exec". If using "exec", Python code can't have leading indent for first line. Ie., code must be left justified, with indents only used for blocks of code where appropriate. Variables created or modules imported in any code section are accessible to later code sections in that page. Ie., globals/locals are preserved across code sections. Note that the changes don't do anything special as far as escaping content which may be included in sections of HTML, or in URLs or as values to attributes of HTML elements. It is expected that user do this appropriate for context. Note also that nothing special is done about Unicode strings. One might consider doing what mod_python.publisher does in 3.2.6 for Unicode strings, but that can only be done for result of an "eval". In line with how CGI "exec" and mod_perl work, Python code will not be run if "IncludesNOEXEC" option is set. > Allow Python code callouts with mod_include (SSI). > -------------------------------------------------- > > Key: MODPYTHON-104 > URL: http://issues.apache.org/jira/browse/MODPYTHON-104 > Project: mod_python > Type: New Feature > Components: core > Reporter: Graham Dumpleton > Fix For: 3.3 > Attachments: grahamd_20060126_1_mod_include.diff > > The mod_include module supporting server side includes (SSI), provides a > means of registering new element tags which trigger callouts to other code in > separate Apache modules. This is used for example in mod_perl to allow Perl > language code to be used with server side includes: > <!--#perl sub="MySSI::remote_host" --> > <!--#perl arg="Hello" arg="SSI" arg="World" > sub="sub { > my($r, @args) = @_; > print qq(@args); > }" > --> > An equivalent feature for Python was previously asked about on the mailing > list back in 2004: > http://www.modpython.org/pipermail/mod_python/2004-January/014832.html > Since it seems entirely reasonable that such integration of mod_python and > mod_include would be possible, thought it would be good to log it as a > possible new feature. > Because of SSI's support for basic conditionals, includes and other callout > mechanisms, would be a good quick and dirty way of doing templating without > having to resort to PSP, or other high level templating systems. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira