mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 22:01:55 +00:00
Add examples to showcase Component's usage
This commit is contained in:
parent
ff38f41f57
commit
5609fde996
32
component_example.py
Normal file
32
component_example.py
Normal file
@ -0,0 +1,32 @@
|
||||
import codecs
|
||||
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from component import Component
|
||||
|
||||
|
||||
def echo_handler(data):
|
||||
return data
|
||||
|
||||
|
||||
def rot13_handler(data):
|
||||
data['data'] = codecs.encode(data['data'], 'rot13')
|
||||
return data
|
||||
|
||||
|
||||
def change_case_handler(data):
|
||||
data['data'] = data['data'].upper() if data['data'].islower() else data['data'].lower()
|
||||
return data
|
||||
|
||||
|
||||
def reverse_handler(data):
|
||||
data['data'] = data['data'][::-1]
|
||||
return data
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
anchor_a = Component('anchor_a', change_case_handler)
|
||||
anchor_b = Component('anchor_b', rot13_handler)
|
||||
anchor_c = Component('anchor_c', reverse_handler)
|
||||
|
||||
IOLoop.instance().start()
|
Loading…
Reference in New Issue
Block a user