From 319f08033d5d1dc7afe71a65d9a2cf0dcc4d55ad Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 12 Jun 2011 22:44:48 -0400 Subject: [PATCH] TEAPOT POWER! --- httpbin/helpers.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index d02e457..73f2c1c 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -8,11 +8,23 @@ This module provides helper functions for httpbin. """ -from flask import request +from flask import request, make_response from .structures import CaseInsensitiveDict +ASCII_ART = r""" + -=[ teapot ]=- + + _...._ + .' _ _ `. + | ."` ^ `". _, + \_;`"---"`|// + | ;/ + \_ _/ + `\"\"\"` +""" + def get_files(): """Returns files dict from request context.""" @@ -25,8 +37,25 @@ def get_files(): return files - def get_headers(): """Returns headers dict from request context.""" - return CaseInsensitiveDict(request.headers.items()) \ No newline at end of file + return CaseInsensitiveDict(request.headers.items()) + + +def status_code(code): + """Returns response object of given status code.""" + + code_map = { + 418: dict(data=ASCII_ART), + } + + r = make_response() + r.status_code = code + + if code in code_map: + if 'data' in code_map[code]: + r.data = code_map[code]['data'] + + print code_map.get(code) + return r \ No newline at end of file