API Reference

This docs are generated from the docstirngs. Apart from that, feel free to study source code directly.

rainfall.web

class rainfall.web.Application(handlers, settings=None)

The core class that is used to create and start server

Parameters:
  • handlers – dict with url keys and HTTPHandler instance values
  • settings

    dict of app settings, defaults are settings = {

    ‘host’: ‘127.0.0.1’, ‘port’: 8888, ‘logfile_path’: None, ‘template_path’: None,

    }

Example:

app = Application({
    '/': HelloHandler(),
})
app.run()
run(process_queue=None, greeting=True)

Starts server on host and port given in settings, adds Ctrl-C signal handler.

Parameters:
  • process_queue – SimpleQueue, used by testing framework
  • greeting – bool, wheather to print to strout or not
class rainfall.web.HTTPHandler

Used by HTTPServer to react for some url pattern.

All handling happens in handle method.

handle(request, **kwargs)

May be an asyncio.coroutine or a regular function

Parameters:
Return type:

str (may be rendered with self.render()) or rainfall.http.HTTPError

render(template_name, **kwargs)

Uses jinja2 to render a template

Parameters:
  • template_name – what file to render
  • kwargs – arguments to pass to jinja’s render
Return type:

rendered string

class rainfall.web.HTTPServer

Http server itself, uses asyncio.Protocol. Not meant to be created manually, but by rainfall.web.Application class.

rainfall.http

exception rainfall.http.HTTPError(code=500, *args, **kwargs)

Representes different http errors that you can return in handlers.

Parameters:code – http error code
class rainfall.http.HTTPRequest(raw)

Rainfall implementation of the http request.

Parameters:raw – raw text of full http request
GET
Return type:dict, GET arguments
POST
Return type:dict, POST arguments
body
Return type:str, http body
headers
Return type:dict, http headers
method
Return type:str, http method
path
Return type:str, http url
class rainfall.http.HTTPResponse(body='', code=200)

Rainfall implementation of the http response.

Parameters:
  • body – response body
  • code – response code
  • additional_headers
compose()

Composes http response from code, headers and body

Return type:str, composed http response

rainfall.unittest

class rainfall.unittest.RainfallTestCase(methodName='runTest')

Use it for your rainfall test cases. In setUp rainfall server is starting in the separate Process.

You are required to specify an app variable for tests. E.g.

from example import my_first_app


class HTTPTestCase(RainfallTestCase):
    app = my_first_app

    def test_basic(self):
        r = self.client.query('/')
        self.assertEqual(r.status, 200)
        self.assertEqual(r.body, 'Hello!')

Inside you can use TestClient’s instance via self.client

class rainfall.unittest.TestClient(host, port)

Helper to make request to the rainfall app. Created automatically by RainfallTestCase.

query(url, method='GET', params=None, headers={})

Run a query using url and method. Returns response object with status, reason, body

Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.