RE: [Templates] Using Toolkit w/python
[prev]
[thread]
[next]
[Date index for 2004/08/10]
On Tue, 10 Aug 2004, Thomas, Mark - BLS CTR wrote:
> > The idea is interesting, but aren't there many security concerns in
> > offering a cgi that executes foreign code?
>
> What I mentioned is not CGI. It's also not executing "foreign" code--it
> would set up to process only files under your control.
I think that it is much easier to use a pipe or a fifo, but I do not know
the windows world.
Is this what you meant?
------------------------------- cut process.pl ---------------------------
#!/usr/bin/perl
use Net::HTTPServer;
use Template;
use strict;
#setup template
my $config={
EVAL_PERL => 0, # evaluate Perl code blocks
};
my $template = Template->new($config);
#start http server
my $server = new Net::HTTPServer(port=>5000, docroot=>`pwd`);
$server->RegisterURL("/process",\&go);
my $port=$server->Start();
print "I'm running on port $port\n";
$server->Process();
sub go {
my $env = shift; # hash reference
my $templ=$env->{template};
my $res="";
$template->process(\$templ,$env,\$res);
return ['200', {}, $res];
}
--------------------------- /cut -------------------------
and
perl process.pl
mozilla http://locahost:5000/process?template=x:[%x%]&x=3
otherwise, I would suggest sending data and template to a pipe or fifo in
yaml or xml format, and get back the interpolated data.
hoping that this is python:
v = {
template : 'the value of x is [%x%]',
vars: {
x : 3,
},
}
v_str = yaml.dump(v)
send v_str to a perl program, or dump to a file and call the perl program:
---------------------------- cut --------------------------
#!/usr/bin/perl
use Template;
use YAML;
undef $/;
$str = <>;
#setup template
my $config={
EVAL_PERL => 0, # evaluate Perl code blocks
};
my $template = Template->new($config);
$v = YAML::Load($str);
$tmpl=$v->{template};
$template->process(\$tmpl, $v->{vars}, \$out);
print $out;
---------------------------- /cut ----------------------------
--
Franco Bagnoli (franchino) <bagnoli@xxx.xxxxx.xx>
virtual location: Dipartimento di Energetica "S. Stecco"
ultra-virtual affiliation: Centro Dinamiche Complesse (CSDC-Firenze)
real location: Dip. Matematica Applicata "G. Sansone", Universita' Firenze,
Via S. Marta, 3 I-50139 Firenze, Italy. Tel. +39 0554796422, fax: +39 055471787
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates