quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sterling Hughes <sterl...@bumblebury.com>
Subject Talking About PSP: Interface
Date Thu, 10 Apr 2003 18:34:23 GMT

PSP in its current iteration exists merely to rewrite HTML into python
via a small lexer.  That's nice, fine and dandy, but I want it to do
more.  These are just my ideas on the subject, I'm really interested to
hear what other people think of this.  I should note that all ideas in
this section are user-space improvements to the PSP module.  That means
if you won't/don't use PSP, this won't have any impact on how you do
scripting with mod_python.

My first thoughts are to mimick the Apache::ASP api from Perl
(http://www.apache-asp.org/objects.html), and to take a little from PHP
where it makes sense.  This is just to get the ball rolling, of course
since this is Python, and not Perl, ASP or PHP, we have to make it our
own.  However, these projects have gotten at least somethings right, so
there is no reason to shy away from their functionality if it makes

I'll start out the conversation by listing the different objects

response : contains methods and information regarding the data sent to 
           the user

response.write(string data):  Write data to the browser
response.flush(void):  Flush the data buffer to the user
response.set_header(string name, string value):  Set a Header Value
response.set_cookie(string name, cookie value): Set a cookie 
response.redirect(string location):  Send the user to a new location
response.end(void):  Send the response, and exit the script

request : contains information about a request
request.get_var([string name]): Returns the form object corresponding to
                             name, if name is not giving, it returns a
                             list of form objects.
request.get_cookie(string name): Return the cookie object associated 
                                 with name
request.get_file(string fname):  Return a file object (file upload).
request.get_method(void): Return the request method, GET, POST, PUT..
request.get_apache(void): Get the mod_python request object

server : contains information about the server

server is an overloaded object providing access to subprocess_env.

cookie : contains information about a cookie
cookie.expiry = when the cookie expires
cookie.domain = domain of the cookie
cookie.value = value associated with the cookie
cookie.name  = name of the cookie
cookie.path = path of the cookie
cookie.secure = whether or not the cookie should only be relegated to 
                secure connections

form : contains information about a form variable
form.type: The type of variable (GET, POST, etc.)
form.value: Variable value
form.name: Variable name

file : contains information about a file upload (should this be
       file_upload to avoid conflicts?
file.name: Filename
file.tmp_file:  Temporary file name

session : This relays information about the current session to the user

Session variables are set via overloaded properties.

session.start(): Start a session and send the headers
session.register_handlers(dict handlers): Register session handlers to
                                          manage actions
session.lock([string name]): Lock the session, mark it read-only
session.unlock([string name]): Unlock the session, mark it writable
session.get_id(): Get the session id
session.set_id(string id): Set the session id
session.encode(string data): Encrypt session data using standard 
                             encryption functions
session.decode(string data): Decrypt session data using standard 
                             encryption functions.
session.remove(string var):  Remove a variable from the current session
session.set_option(string name, object value): Set an option in the
                                               session backend.
session.get_option(string name): Get an option from the session backend
session.get_cookie(void): Gets the session cookie object
session.clear():  Clear the session

auth : http authentication handling

auth.username: The HTTP username
auth.password: Get the HTTP password
auth.method: The method of authentication used
auth.realm: authentication realm
auth.deny(): Deny access to the current page

psp :  Main namespace, along with some utility functions

psp.parse(string filename): Parse a .psp file and return the code 
psp.execute(codeobject file[, dict args]): Execute a parsed code object
psp.include(string file[, dict args]): Parse and execute a code 
                                       object, returning it into the 
                                       given context

Same set of methods for normal python files that don't need to be
written, ie parse_py(), execute_py() and include_py().

PSP files should also be allowed as two types.  One type that includes a
rewriter (<% %>), and one that just has the psp environment available. 
These are just some preliminary thoughts to get the conversation started
about the interfaces, I'm really interested in hearing other ideas, and
what you think of my current design.

"Whether you think you can or think you can't -- you are right." 
    - Henry Ford

View raw message