Add examples to showcase Component's usage

This commit is contained in:
Bálint Bokros 2017-11-17 15:56:38 +01:00
parent ff38f41f57
commit 5609fde996
1 changed files with 32 additions and 0 deletions

32
component_example.py Normal file
View 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()