3.5 The mode Object

Websites and web applications go through a life-cycle involving development, debugging, staging, and deployment. It is often desirable to alter behavior throughout the application based on the current stage in this life-cycle, for example, to use a different database connection string in deployment than in development or staging.

httpy models this common requirement via a mode singleton, which has the following members:

IS_DEVELOPMENT
IS_DEBUGGING
IS_STAGING
IS_DEPLOYMENT
These constants are boolean values based on the current mode, and only one will be True at any given time. Abbrevations and alternate casings are allowed; e.g., IS_DEV and is_develo are both aliases for IS_DEVELOPMENT. IS_DE is an AttributeError, however.

__repr__( )
Returns the current mode as a lowercase string. This will always be one of development, debugging, staging, or deployment.

__str__( )
Alias for __repr__.

default
Contains the default mode as a lowercase string. Out of the box, this is development.

httpy's current mode is determined by the environment variable HTTPY_MODE. Since the mode of an application instance is generally only defined at start-up, this API is intended to be read-only. However, mode checks the environment on each call or attribute access, so if you must change the mode on the fly, you can.

Other parts of the httpy package alter their behavior according to the current mode. Here is a reference:

development
Internal server errors generate a traceback in the browser.

On Unix systems, the StandAlone coupler monitors the filesystem counterparts of all loaded modules, and restarts itself if the modification time of any of these files changes.

debugging
Equivalent to development. Additionally, non-Response Exceptions trigger post-mortem debugging via pdb.

staging
Equivalent to deployment.

deployment
The Static responder supports the 304 Not Modified response.

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