[mod_python] HTML::Mason ported to Python

mike bayer mike_mp at zzzcomputing.com
Mon Aug 30 12:17:56 EDT 2004

hey there -

Currently, the ApacheRequestImpl object doesnt take an optional out_buffer
argument, which would override the normal usage of the mod_python request
as its out_buffer.  But it should; so I will add this today.  In that
case, you can call it, from within your own mod_python request handler,

  buffer = StringIO.StringIO()
  myghty.ApacheHandler.handle(req, out_buffer = buffer)
  string = buffer.getvalue()

In the meantime, assuming you want your myghty template to have the full
HTTP environment you've configured, here's the hack to get around it:

   # initialize configuration variables
   myghty.ApacheHandler.init_conf(req, require_directories = True)

   # make your own request_impl
   request_impl = myghty.ApacheHandler.ApacheRequestImpl(req,

   buffer = StringIO.StringIO()

   # set its outbuffer
   request_impl.out_buffer = buffer

   myghty.ApacheHandler.handle(req, request_impl = request_impl)

   string = buffer.getvalue()

Or you could also just use Interpreter directly, if the http configuration
is not so important.  You can make the %ARGS hash out of the mod_python
request using myghty.ApacheHandler.make_request_args(req) and send the
resulting dictionary object to the interpreter execute() method as the
"request_args" parameter.

Feel free to use the sourceforge BBS for Myghty questions:


- mike

> Mike--
> Is there a way to get the results of an ApacheHandler.handle call as a
> string (or to a file buffer, like the out_buffer argument for
> Interpreter objects)?
> -Ross
> On Wed, 25 Aug 2004 01:04:35 -0400 (EDT), mike bayer
> <mike_mp at zzzcomputing.com> wrote:
>> hi all -
>> Ive done just what the subject says, for those of you unfamiliar with
>> HTML::Mason its a pretty popular templating package for the mod_perl
>> environment, used by sites like amazon.com and salon.com.  in
>> traditional
>> "pick a name that has a 'y' in it" fashion I have called it Myghty.
>> the application supports everything Mason does, including subcomponents,
>> methods, page inheritance, mod_python/CGI connectors, etc., with the
>> exception of caching, which is an upcoming feature.  Plus it has some
>> extra features designed to make life in a python multithreaded
>> environment
>> easier, if you are running under the worker MPM.   The code is 50% taken
>> from Mason and 50% custom, although the general architecture is mostly
>> the
>> same.
>> Anyway, ive gotten it running standalone, with mod_python 2.7/3.1, with
>> both the worker and prefork MPMs, and with the CGI handler, and it seems
>> to work pretty well.  docs need some editing but content-wise are fairly
>> close to complete.  I am hoping its something people will find useful
>> once
>> it is road-tested a little more, and also that some folks on here might
>> want to help me test it out a little as I am sure the outside world will
>> find tons of little issues I haven't come across yet.
>> check it out at :   http://myghty.sourceforge.net/
>> - mike
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list