RE: [Templates] Using Toolkit w/python

[prev] [thread] [next] [Date index for 2004/08/10]

From: Franco Bagnoli
Subject: RE: [Templates] Using Toolkit w/python
Date: 16:08 on 10 Aug 2004
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

[Templates] Using Toolkit w/python
Tim Johnson 20:15 on 07 Aug 2004

Re: [Templates] Using Toolkit w/python
Eric Sammer 20:18 on 07 Aug 2004

RE: [Templates] Using Toolkit w/python
Thomas, Mark - BLS CTR 14:16 on 09 Aug 2004

Re: [Templates] Using Toolkit w/python
Darren Chamberlain 15:24 on 09 Aug 2004

Re: [Templates] Using Toolkit w/python
Tim Johnson 16:37 on 09 Aug 2004

RE: [Templates] Using Toolkit w/python
Thomas, Mark - BLS CTR 17:11 on 09 Aug 2004

RE: [Templates] Using Toolkit w/python
Franco Bagnoli 06:59 on 10 Aug 2004

Re: [Templates] Using Toolkit w/python
Darren Chamberlain 12:31 on 13 Aug 2004

[Templates] Parrot (was Using Toolkit w/python)
Tim Johnson 16:14 on 19 Aug 2004

RE: [Templates] Using Toolkit w/python
Thomas, Mark - BLS CTR 13:17 on 10 Aug 2004

RE: [Templates] Using Toolkit w/python
Franco Bagnoli 16:08 on 10 Aug 2004

Re: [Templates] Using Toolkit w/python
Tim Johnson 17:39 on 10 Aug 2004

RE: [Templates] Using Toolkit w/python
Thomas, Mark - BLS CTR 17:35 on 10 Aug 2004

Generated at 08:56 on 15 Mar 2005 by mariachi v0.52