Package aquarium :: Package util :: Module InternalLibrary :: Class InternalLibrary
[show private | hide private]
[frames | no frames]

Class InternalLibrary

AquariumClass --+
                |
               InternalLibrary


This is the "standard library" for Aquarium's structure.


Method Summary
  aquariumFactory(self, moduleName, *args, **kargs)
Dynamically import and instantiate a class from Aquarium.
  call(self, moduleName, *args, **kargs)
This is a convenience method for aquariumFactory().__call__().
  forward(self, screen, *args, **kargs)
Forward processing to a new screen.
  htmlEntities(self, s)
Return s after "HTML encoding" it (i.e.
  inverseExtend(self, boundMethod, *args, **kargs)
Iterate downward through a hierarchy calling a method at each step.
  javaScriptEscape(self, s, htmlent)
Prepare s for use in a JavaScript quoted string.
  javaScriptQuote(self, s, htmlent)
Escape s and wrap it in single quotes.
  redirect(self, url, httpResponse)
Do an HTTP redirect.
  redirectSeeOther(self, screen, *args, **kargs)
Do an HTTP redirect using HTTPResponses.SEE_OTHER.
  redirectTemporary(self, screen, *args, **kargs)
Do an HTTP redirect using HTTPResponses.TEMPORARY_REDIRECT.
  validModuleName(self, name)
This is an alias for validModuleName.
    Inherited from AquariumClass
  __init__(self, ctx)
Set a reference to ctx.

Method Details

aquariumFactory(self, moduleName, *args, **kargs)

Dynamically import and instantiate a class from Aquarium.

This works for templates too. In fact, this method will automatically compile templates as necessary. Because it's difficult to distinguish a compiled template from a normal Python module, you should not create both a template and a normal Python module with the same name (excluding the extension) in the same directory as many bad things can happen.

I will also recursively compile base templates if you're real nice to me and use lines that look like:

#extends aquarium.foo.Bar

Otherwise, this is a very difficult thing to do. In fact, I'll go so far as to raise an exception if you try to extend something without using a module name that starts with "aquarium." (i.e. a module name that isn't fully specified).

moduleName
This is the name of the module relative to the aquarium package (e.g. screen.MyScreen).
*args, **kargs
These will be passed to the class's constructor. self._ctx will always be added to the front of *args unless you specify the keyword parameter aquariumFactoryNoContext=1 (which will be removed).

call(self, moduleName, *args, **kargs)

This is a convenience method for aquariumFactory().__call__().

moduleName
This is the name of the module relative to the aquarium package (e.g. screen.MyScreen).
*args, **kargs
These will be passed to __call__.

If you need to pass additional arguments to aquariumFactory or if you need to call some other method than __call__, don't use this method.

forward(self, screen, *args, **kargs)

Forward processing to a new screen. This method does not return.

Generate a Forward exception which aquarium.util.Aquarium.screenLoop class is prepared to catch.

screen
This is the module name of the screen relative to the screen directory.
*args, **kargs
The arguments to pass to the screen's __call__ method.

htmlEntities(self, s)

Return s after "HTML encoding" it (i.e. & -> &, etc.).

I'm leaving this here just in case I have to do charset specific entity encodings.

inverseExtend(self, boundMethod, *args, **kargs)

Iterate downward through a hierarchy calling a method at each step.

In a sense, this is like the object oriented concept of extending a method, except the parent class wraps the child class instead of the other way around. This method was inspired by Perl's Mason.

Just as with extending a method, you can pass whatever arguments you want to "super" (although here you're passing those arguments to the subclass via callNext) and you can return whatever you want (the highest level method returns to the actual caller).

If an instance has multiple superclasses, only the first is considered.

boundMethod
This is the bound method of the object you're interested in.
*args, **kargs
The arguments and keyword arguments to pass to the top-level method.

You can call this method via something like this:

inverseExtend(object.method, myArg, myOtherArg)

When calling the method at each step, I'll call it like this:

Class.method(object, callNext, *args, **kargs)

However, the lowest level class's method has no callNext parameter, since it has no one else to call:

Class.method(object, *args, **kargs)

In the method:

callNext(*args, **kargs)

should be called when it is time to transfer control to the subclass. This may even be in the middle of the method. Naturally, you don't have to pass *args, **kargs, but a common idiom is for the parent class to just receive *args and **kargs and pass them on unmodified.

javaScriptEscape(self, s, htmlent=True)

Prepare s for use in a JavaScript quoted string.

Both " and ' are escaped, so you can use the return value in either single or double quotes.

Test cases:

[('', '\b'),   # backspace
 (' ', '\t'),   # horizontal tab
 ('
', 'n'), # line feed (new line)
(' ', 'v'), # vertical tab (' ', 'f'), # form feed ('
', 'r'), # carriage return
('"', '"'), # double quote ("'", "'"), # single quote ('', '\')] # backslash

javaScriptQuote(self, s, htmlent=True)

Escape s and wrap it in single quotes.

redirect(self, url, httpResponse=307)

Do an HTTP redirect. This method does not return.

url
The URL to redirect the user to.
httpResponse
The HTTP response code. See aquarium.util.HTTPResponses.

Use this method if you must redirect to a url not on this site. In most cases, you'll want redirectSeeOther instead.

(This works by doing a forward to aquarium.screen.redirect.)

redirectSeeOther(self, screen, *args, **kargs)

Do an HTTP redirect using HTTPResponses.SEE_OTHER.

This is a convenience method for:

import HTTPResponses
url = ctx.url.screen(screen, *args, **kargs)
ctx.iLib.redirect(url, HTTPResponses.SEE_OTHER)

This method does not return.

Sometimes you have a form (e.g. a login form), and after the user submits the form, you redirect him to some other screen within the site. That's what the HTTP response "303 See Other" is made for, and hence, that's what this method is made for.

redirectTemporary(self, screen, *args, **kargs)

Do an HTTP redirect using HTTPResponses.TEMPORARY_REDIRECT.

This is a convenience method for:

import HTTPResponses
url = ctx.url.screen(screen, *args, **kargs)
ctx.iLib.redirect(url, HTTPResponses.TEMPORARY_REDIRECT)

This method does not return.

Use this method instead of redirectSeeOther if you want to use a TEMPORARY_REDIRECT instead of a SEE_OTHER redirect. In most cases, you'll want redirectSeeOther instead.

validModuleName(self, name)

This is an alias for validModuleName.


Generated by Epydoc 2.1 on Mon Jan 1 16:34:19 2007 http://epydoc.sf.net