| 20 | |
| 21 | # Handle {ctrl} server response |
| 22 | def handle_ctrl(ctrl): |
| 23 | # Run code on command completion |
| 24 | func = tn_globals.OnCompletion.get(ctrl.id) |
| 25 | if func: |
| 26 | del tn_globals.OnCompletion[ctrl.id] |
| 27 | if ctrl.code >= 200 and ctrl.code < 400: |
| 28 | func(ctrl.params) |
| 29 | |
| 30 | if tn_globals.WaitingFor and tn_globals.WaitingFor.await_id == ctrl.id: |
| 31 | if 'varname' in tn_globals.WaitingFor: |
| 32 | tn_globals.Variables[tn_globals.WaitingFor.varname] = ctrl |
| 33 | if tn_globals.WaitingFor.failOnError and ctrl.code >= 400: |
| 34 | raise Exception(str(ctrl.code) + " " + ctrl.text) |
| 35 | tn_globals.WaitingFor = None |
| 36 | |
| 37 | topic = " (" + str(ctrl.topic) + ")" if ctrl.topic else "" |
| 38 | stdoutln("\r<= " + str(ctrl.code) + " " + ctrl.text + topic) |
| 39 | |
| 40 | |
| 41 | # Lambda for handling login |