<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF xmlns="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><Project><name>hexagonit.decorators</name>
<shortdesc>Collection of useful decorators for Zope development</shortdesc>
<description>****************************************
Collection of useful function decorators
****************************************

.. contents::

The package contains function decorators that help implementing
repetitive tasks. It is mostly oriented towards Zope development.

Change History
**************

0.2 (2007-09-05)
================

 - Fixed problem with methods not being passed parameters from the
   query string. When a view method was called directly using an URL
   the parameters from the query string were lost when a view method
   was decorated. The decorators now push back the query parameters
   into the method call.

0.1 (2007-08-31)
================

 - First public release.

Detailed Documentation
**********************

``browser`` module
==================

This module provides decorators that are useful with Zope 3 browser
views (also usable in Zope 2).

JSON decorator
==============

The JSON decorator uses simplejson_ to encode the return value of the
decorated function as JSON.

.. _simplejson: http://pypi.python.org/pypi/simplejson

    &gt;&gt;&gt; from hexagonit.decorators.browser import json

    &gt;&gt;&gt; @json
    ... def json_callback():
    ...     """JSON callback method."""
    ...     return {'bool' : (True, False) }
    &gt;&gt;&gt; json_callback()
    '{"bool": [true, false]}'

Any keyword arguments passed to the decorator will be passed on to the
``simplejson.dumps`` function.

    &gt;&gt;&gt; @json(sort_keys=True, ensure_ascii=False)
    ... def json_callback():
    ...     """JSON callback method."""
    ...     return {'foo' : None, 'bool' : (True, False), 'ints' : [1,2,3]}
    &gt;&gt;&gt; json_callback()
    u'{"bool": [true, false], "foo": null, "ints": [1, 2, 3]}'
    


HTTP cache disabling decorator
==============================

The ``nocache`` decorator is used for Zope 3 views and sets the
appropriate HTTP headers to disable caching for the results of the
decorated method.

    &gt;&gt;&gt; from hexagonit.decorators.browser import nocache

We'll demonstrate the use of the decorator with a dummy view object.

    &gt;&gt;&gt; class Dummy(object):pass
    &gt;&gt;&gt; class BrowserView(object):
    ...     """Dummy view class that fakes the ``request`` object."""
    ...     def __init__(self):
    ...         self.request = Dummy()
    ...         self.request.response = Dummy()
    ...         self.headers = []
    ...         self.request.response.setHeader = lambda header,value: self.headers.append('%s: %s' % (header, value))
    ...         
    ...     @nocache
    ...     def ajax_callback(self):
    ...         print '\n'.join(self.headers)

    &gt;&gt;&gt; view = BrowserView()
    &gt;&gt;&gt; view.ajax_callback()
    Pragma: no-cache
    Expires: Sat, 1 Jan 2000 00:00:00 GMT
    Cache-Control: no-cache, must-revalidate

It is also possible to use both the ``json`` decorator and the
``nocache`` decorator at the same time.

Download
***********************</description>
<homepage rdf:resource="http://pypi.python.org/pypi/hexagonit.decorators" />
<maintainer><foaf:Person><foaf:name>Kai Lautaportti</foaf:name>
<foaf:mbox_sha1sum>5344047993836064e4b50e6593617ab24cedebad</foaf:mbox_sha1sum></foaf:Person></maintainer>
<release><Version><revision>0.2</revision></Version></release>
</Project></rdf:RDF>