Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython

spats is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
 
Links
License
LGPL
Dependencies

Quick Overview

Spats or Simple PAge Template Server is an attempt to make a simple little Page Template Server that can be used by everyone. Basically the idea is simple, allow you to serve out a Page Template back to a http request. It subclass all the Python standard library HTTP servers to do this.

You can also have Python Scripts which are for the more advanced logic of serving out bits and peices.

Dependencies

SimpleTAL, although we might need to make a more complicated one soon to deal with i18n. SimpleTAL can be found here:

System Message: WARNING/2 (<string>, line 19)

Literal block expected; none found.

http://www.owlfish.com/software/simpleTAL/

Optional Dependencies

wxembed: Using a wxPython to embed the server and IE win to make it look like an application. Requires wx.

mfcembed: Using a win32ui native wrapper to embed the server and IE win to make it look like an application. A better choice for Windows users. Requires pywin32.

taskbar: Makes a little windows taskbar icon. Again only for Windows and requires pywin32.

browser: Just runs in the command line and fires up a browser. No dependencies for this one ;)

Detailed Overview
What is spats?

A SimplePAgeTemplateServer, credit goes to Leo for the name. Basically a way to make a web server, quickly and simply to serve dynamic stuff back to the server.

What does it do?

Serves compiled page templates back to the user. That's all really, basically it takes the file on the file system and serves it back. If that file happens to be a page template it compiles it with simpletal and then spits it back to the user.

It's not a CGI server (it doesn't serve Python scripts back).

It's not Zope, it doesn't do any of that stuff Zope does. It's simple.

It does GET and HEAD, that's it.

It does not make good cups of tea.

Using

See example.py

Make a directory and put a start.py, that reads:

System Message: WARNING/2 (<string>, line 70)

Literal block expected; none found.

from spats import SimplePageTemplateServer SimplePageTemplateServer.start()

This won't do much however, you need to tell it where to read HTML from. So you can pass a config dictionary variable through of all the possible values.

So make a directory called say html or pt. Stick a PageTemplate, called say index.pt in there. Now pass that directory through and you are on your way:

System Message: WARNING/2 (<string>, line 81)

Literal block expected; none found.

from spats import SimplePageTemplateServer config = {"html_dir":"html"} SimplePageTemplateServer.start(config)

See SimplePageTemplateServer.py for a commented list of variables.

Scripts

Pass through a scripts_dir value in the config, and everything in that dir that: ends in .py and contains a __main__ method will be compiled into the scripts context.

So you can then access in TAL scripts/foo where foo is your script. This will call the __call__ function.

Note: in a script the context will be assigned to the script, this is the context variable in TAL so you can access all TAL variables in the script. See some examples in the reports site.

You do not serve scripts directly, you serve PageTemplates that call scripts.

SimpleTal

This is rather quirky if you are used to Zope TAL, but you should get there quickly. Main quirks:

  • elements have to be closed <p tal:content="foo" /> must be ``<p

    System Message: WARNING/2 (<string>, line 110); backlink

    Inline literal start-string without end-string.

System Message: WARNING/2 (<string>, line 111)

Bullet list ends without a blank line; unexpected unindent.

tal:content="foo"></p>``

  • the context is different because we build that ourselves and it can

System Message: WARNING/2 (<string>, line 114)

Bullet list ends without a blank line; unexpected unindent.

be tricky

  • attributes errors fail silently which is kinda nice but confusing
But it doesn't do...?

So add it dude, its only a 200 line module. But keep it simple please, or goal is to be able to throw together things simply and quickly not rebuild Zope.

Change history

0.1 (2008-12-10)

  • Initial release as a Python egg [sidnei].
Contributors
  • Andy McKay
  • Mark Hammond
  • Neil Kandalgoankar
Download

Subscribe to package updates

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.