Updated: (MODPYTHON-104) Allow Python code callouts with
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Apache Server configuration support > Apache Mod-Python > Updated: (MODPYTHON-104) Allow Python code callouts with




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Updated: (MODPYTHON-104) Allow Python code callouts with  
Graham Dumpleton (JIRA)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-06 01:57 AM

[ http://issues.apache.org/jira/brows...ON-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 f
iles for which the builtin "INCLUDES" output filter of Apache is enabled. Ty
pically 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 inden
ts only used for blocks of code where appropriate. Variables created or modu
les imported in any code se
ction are accessible to later code sections in that page. Ie., globals/local
s are preserved across code sections.

Note that the changes don't do anything special as far as escaping content w
hich may be included in sections of HTML, or in URLs or as values to attribu
tes of HTML elements. It is expected that user do this appropriate for conte
xt.

Note also that nothing special is done about Unicode strings. One might cons
ider 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 i
f "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 use
d w
ith 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/...ary/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 poss
ible new feature.
> Because of SSI's support for basic conditionals, includes and other callout mechan
isms, would be a good quick and dirty way of doing templating without having to reso
rt to PSP, or other high level templating systems.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:16 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register