next up previous Python Library Reference contents modules index

wpre - Introduction

Wpre (Write Preprocessor) is a system that has been designed to support easy preprocessing of text, which is needed when working with HTML and XML
documents on the web. Wpre has been named after a different tool which was written by Thomas Christopher in the late 1980's and early 1990's to facilitate code generation in compilers. We will probably undergo a name change soon, since this tool differs a great deal from the needs and philosophy of the original tool. Nonetheless, this version is a way of paying homage to a tool that has proven to be very useful for compiler development. Amazingly, the ideas are still useful today.

Let us consider the problem of generating HTML in a typical script, say, one that is written in Python:

print '<html>'
print '<title>',docTitle,'</title>'

[a bunch of other print statements mixed with code]

print '</html>'

In this case, the value of the docTitle string will be placed in between the appropriate HTML tags. Clearly, for creating highly intricate and complicated web pages that rely on dynamic content, direct including of HTML tags within the script makes management and programming a nightmare. There are a number of major disadvantages of embedding HTML in the source code itself:


Wpre was designed with the hope of overcoming all of these problems and limitations. Instead of embedding HTML tags and fragments in your document, Wpre allows you to define the HTML document and make use of a special "variable definition" syntax to place variables in the text. Then you can bind variables in your program to achieve the same results.

Consider the revised example using the Wpre model. First, we create and HTML document that contains all of the HTML tags. We also embed inside the HTML document the variable information using a special syntax. Both the docTitle and company strings are flagged with the ` character. These items will be replaced with there value by the Wpre system.

<html><title>`docTitle</title>

<h1>Welcome to `company's home page.</h1>

</html>

If within the script the variables docTitle and company were set to "Happy Days" and "Tools of Computing", respectively, the following transformation could be performed:
<html><title>Happy Days</title>

<h1>Welcome to Tools of Computing's home page</h1>

</html>

This is the core capability of Wpre. You have a document with references to variables. These variables correspond to variables in your Python (or other language in the future) program and are bound to form a concrete document. It is much like having a "language preprocessor" as you find in the C language but is extremely lightweight and adheres to a very well defined task.


next up previous Python Library Reference contents modules index

Send comments on this document to pshafae@leibniz.jhpc.cs.depaul.edu

Copyright(C) Java and High-Performance Computing Laboratory (JHPC) at DePaul University Chicago
Documentation template borrowed from python.org