PyEmb (version 1.1)
index
PyEmb.py

Yet another templating module with support for embedded Python code.
 
See the end of the module source code and the _test() function for
example usage.
 
Usage as a script:
    PyEmb.py infile[.pye] [outfile]
 
    Processes infile and writes output to stdout or outfile if given.
 
Usage as a CGI script:
    See documentation for the _do_cgi() function.

 
Modules
            
StringIO
os
re
sys

 
Classes
            
EmbeddedScript
EmbeddedPython
SpecialHTML
exceptions.Exception
Error
ParseError

 
class EmbeddedPython(EmbeddedScript)
       
  
__init__(self, template=None) from EmbeddedScript
__str__(self) from EmbeddedScript
_mk_env(self)
_parse(self, source) from EmbeddedScript
_process(self, s, env)
_strip_left(self, s)
_subst(self, source=None) from EmbeddedScript
set_template(self, template)
write(self, file=None) from EmbeddedScript

 
class EmbeddedScript
       
  
__init__(self, template=None)
__str__(self)
_mk_env(self)
_parse(self, source)
_process(self, s, env)
_subst(self, source=None)
set_template(self, template)
write(self, file=None)

 
class Error(exceptions.Exception)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class ParseError(Error)
       
  
__getitem__(...) from exceptions.Exception
__init__(...) from exceptions.Exception
__str__(...) from exceptions.Exception

 
class SpecialHTML(EmbeddedPython)
      # an example of how easy you can change the tags that enclose the script area
 
  
__init__(self, template=None) from EmbeddedScript
__str__(self) from EmbeddedScript
_mk_env(self) from EmbeddedPython
_parse(self, source) from EmbeddedScript
_process(self, s, env) from EmbeddedPython
_strip_left(self, s) from EmbeddedPython
_subst(self, source=None) from EmbeddedScript
set_template(self, template) from EmbeddedPython
write(self, file=None) from EmbeddedScript

 
Functions
            
_do_cgi()
CGI support. Put out HTTP header and processed document to stdout.
 
The name of the template file is taken from the environment variable
PATH_TRANSLATED, which should contain the real path of of the template
file on the server file system. Here's how to set up Apache, so that
you can directly serve template files (with the extension .pye) and
process them on-the-fly:
 
- Add the following to your 'httpd.conf' or '.htaccess' file:
 
  AddHandler embedded-python .pye
  Action embedded-python /cgi-bin/PyEmb.py
  AddType text/x-pye .pye
 
- Install this module in your cgi-bin directory and make it executable.
- Restart Apache if necessary.
_test()
Module test function.
compare_s2f(s, f2)
Helper to compare a string to a file, return 0 if they are equal.
include(fn)

 
Data
             PRINTECHO = 1
__all__ = ['Error', 'ParseError', 'EmbeddedScript', 'EmbeddedPython', 'SpecialHTML']
__author__ = 'Christopher Arndt <chris.arndt@web.de>'
__file__ = './PyEmb.py'
__name__ = 'PyEmb'
__version__ = '1.1'

 
Author
             Christopher Arndt <chris.arndt@web.de>