(self)
| 80 | sys.stdin = data_string |
| 81 | |
| 82 | def serve(self): |
| 83 | try: |
| 84 | self.load() |
| 85 | except Exception as e: |
| 86 | if hasattr(e, 'error_type'): |
| 87 | error_type = e.error_type |
| 88 | else: |
| 89 | error_type = 'AlgorithmError' |
| 90 | load_error_string = json.dumps({ |
| 91 | 'error': { |
| 92 | 'message': str(e), |
| 93 | 'stacktrace': traceback.format_exc(), |
| 94 | 'error_type': error_type |
| 95 | } |
| 96 | }) |
| 97 | return self.write_to_pipe(load_error_string) |
| 98 | for line in sys.stdin: |
| 99 | try: |
| 100 | request = json.loads(line) |
| 101 | formatted_input = self.format_data(request) |
| 102 | if self.load_result: |
| 103 | apply_result = self.apply_func(formatted_input, self.load_result) |
| 104 | else: |
| 105 | apply_result = self.apply_func(formatted_input) |
| 106 | response_string = self.format_response(apply_result) |
| 107 | except Exception as e: |
| 108 | if hasattr(e, 'error_type'): |
| 109 | error_type = e.error_type |
| 110 | else: |
| 111 | error_type = 'AlgorithmError' |
| 112 | response_string = json.dumps({ |
| 113 | 'error': { |
| 114 | 'message': str(e), |
| 115 | 'stacktrace': traceback.format_exc(), |
| 116 | 'error_type': error_type |
| 117 | } |
| 118 | }) |
| 119 | finally: |
| 120 | self.write_to_pipe(response_string) |
nothing calls this directly
no test coverage detected