handler module

Handler of HTTP requasts and responses.

class handler.Request(environ={})

Bases: object

A class handling HTTP requests.

Methods

get(name) Get value of request.
has(name) Ask whether request has name.
get(name)

Get value of request.

Parameters:

name: str

key of the request

Returns:

str

the value of request

Raises:

KeyError

raises if request does not have element with name

has(name)

Ask whether request has name.

Parameters:

name: str

key of the request

Returns:

bool

class handler.Response(content_type='html', charset='utf-8')

Bases: object

The class handring Response of HTTP.

You can use this class by making instance of this class before sending Response.

Examples

  • JSON
>>> res = Response("json")
>>> res.set_body("{'exit_code' : 0}")
>>> print(res) 
  • HTML
>>> res = Response("html")
>>> res.set_body('''
...     <!DOCTYPE html>
...     <html>
...         <body>
...             <h1>My Home Page!</h1>
...         </body>
...     </html>
...     ''')
>>> print(res) 

Methods

get_header(name) Get the header which already set and return object.
make_output([timestamp]) Make Response text including header and text and return str.
set_body(bodystr) Set the body of response.
set_header(name, value) Set header of Response.
get_header(name)

Get the header which already set and return object.

make_output(timestamp=None)

Make Response text including header and text and return str.

set_body(bodystr)

Set the body of response.

See Examples of this class.

set_header(name, value)

Set header of Response.

handler.operation_fail(msg='', code=1)
handler.operation_success()

This Page