3.6 Utilities

The httpy.utils subpackage collects several tools which may be of value to those building web applications with httpy. The translate function is actually used by httpy's own Static and Multiple responders. The parse_* functions are not used in the base package, but even the simplest web applications will need these or similar methods to extract application state from the Request object.

parse_body( request)
Given a Request instance, returns an instance of the standard library's cgi.FieldStorage class representing the request body.

parse_cookie( request)
Given a Request instance, returns an instance of the standard library's Cookie.SimpleCookie class representing the request's cookie.

parse_query( request)
Given a Request instance, returns an instance of the standard library's cgi.FieldStorage class representing the request's querystring.

translate( uri_path, fs_root[, defaults][, raw])
Translates a URI path to the filesystem.

uri_path is the path component of a Request-URI (i.e., Request.path). fs_root is the filesystem path of the directory in which the URI path should be rooted. defaults, if given, is a sequence of names that should be considered default resources. If not given, defaults is empty. If raw is given and it evaluates to True, then translate() ignores defaults and performs no validation. If raw is False, then validation proceeds according to this rubric:

  1. If the translated path points to a directory, then the URI must end with a slash, or 301 Moved Permanently is raised.

  2. If the translated path points to a directory, and no default resource is named or available, then 403 Forbidden is raised.

  3. If the translated path does not point to a directory, then it must point to a valid file, or 404 Not Found is raised.

translate() returns the filesystem path of the requested resource.

httpy is Zeta software. It is copyright © 2006 by Chad Whitacre, and is offered free of charge, warranty, and restrictions.