>>> test(HelloPage, PATH_INFO="/x")
HTTP/1.0 404 Not Found
Date: ...
Content-Type: text/plain
...
404 not found
You deserve a kinder note
Than this web haiku!
...
>>> test(HelloPage, form={"a":"b"})
HTTP/1.0 405 Method not allowed
Date: ...
Content-Type: text/plain
Allow: HEAD, GET
...
Excellent method!
Alas, my response must be:
"I cannot comply."
>>> test(HelloPage, REQUEST_METHOD="HEAD")
HTTP/1.0 200 OK
Date: ...
Content-Type: text/html
Content-Length: 22
>>> from web_haiku import Text, form_handler
>>> class TestForm(Page):
... """A stupid example to test the framework"""
...
... form_defaults = dict(name='Joey', animal='Dog', email='joe@dog.com')
...
... body = form_failure = HTML("""
...
...
... What is your favorite animal ?
...
... $show_errors
...
...
... """)
... form_success = Text("Hey Joe!")
...
... @form_handler
... def check_joe(self):
... if self.name!='Joe': self.errors.append("Hey, you're not Joe!")
...
... errors_found = HTML.fragment(
... "
Please correct the following problems:
\n"
... '
'
... r'$(? "
\n
".join(errors) ?)'
... '
'
... )
>>> class Folder(Page):
... hello = HelloPage
... form = TestForm
>>> test(Folder, PATH_INFO="/hello")
HTTP/1.0 200 OK
Date: ...
Content-Type: text/html
...
Hello, world!
>>> test(Folder, PATH_INFO="/hello/")
HTTP/1.0 302 Found
Date: ...
Content-Type: text/html
Location: http://127.0.0.1/hello
...
......
>>> test(Folder, PATH_INFO="/form")
HTTP/1.0 200 OK
...
Content-Type: text/html
...
...What is your favorite animal ?...
......
...
>>> test(Folder, form=dict(name="Me", email="blah"), PATH_INFO="/form")
HTTP/1.0 200 OK
...