OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Protocol Buffers - Google's data interchange format | 3 # Protocol Buffers - Google's data interchange format |
4 # Copyright 2008 Google Inc. All rights reserved. | 4 # Copyright 2008 Google Inc. All rights reserved. |
5 # https://developers.google.com/protocol-buffers/ | 5 # https://developers.google.com/protocol-buffers/ |
6 # | 6 # |
7 # Redistribution and use in source and binary forms, with or without | 7 # Redistribution and use in source and binary forms, with or without |
8 # modification, are permitted provided that the following conditions are | 8 # modification, are permitted provided that the following conditions are |
9 # met: | 9 # met: |
10 # | 10 # |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 if request.WhichOneof('payload') == 'protobuf_payload': | 60 if request.WhichOneof('payload') == 'protobuf_payload': |
61 try: | 61 try: |
62 test_message.ParseFromString(request.protobuf_payload) | 62 test_message.ParseFromString(request.protobuf_payload) |
63 except message.DecodeError as e: | 63 except message.DecodeError as e: |
64 response.parse_error = str(e) | 64 response.parse_error = str(e) |
65 return response | 65 return response |
66 | 66 |
67 elif request.WhichOneof('payload') == 'json_payload': | 67 elif request.WhichOneof('payload') == 'json_payload': |
68 try: | 68 try: |
69 json_format.Parse(request.json_payload, test_message) | 69 json_format.Parse(request.json_payload, test_message) |
70 except json_format.ParseError as e: | 70 except Exception as e: |
71 response.parse_error = str(e) | 71 response.parse_error = str(e) |
72 return response | 72 return response |
73 | 73 |
74 else: | 74 else: |
75 raise ProtocolError("Request didn't have payload.") | 75 raise ProtocolError("Request didn't have payload.") |
76 | 76 |
77 if request.requested_output_format == conformance_pb2.UNSPECIFIED: | 77 if request.requested_output_format == conformance_pb2.UNSPECIFIED: |
78 raise ProtocolError("Unspecified output format") | 78 raise ProtocolError("Unspecified output format") |
79 | 79 |
80 elif request.requested_output_format == conformance_pb2.PROTOBUF: | 80 elif request.requested_output_format == conformance_pb2.PROTOBUF: |
81 response.protobuf_payload = test_message.SerializeToString() | 81 response.protobuf_payload = test_message.SerializeToString() |
82 | 82 |
83 elif request.requested_output_format == conformance_pb2.JSON: | 83 elif request.requested_output_format == conformance_pb2.JSON: |
84 response.json_payload = json_format.MessageToJson(test_message) | 84 try: |
| 85 response.json_payload = json_format.MessageToJson(test_message) |
| 86 except Exception as e: |
| 87 response.serialize_error = str(e) |
| 88 return response |
85 | 89 |
86 except Exception as e: | 90 except Exception as e: |
87 response.runtime_error = str(e) | 91 response.runtime_error = str(e) |
88 | 92 |
89 return response | 93 return response |
90 | 94 |
91 def do_test_io(): | 95 def do_test_io(): |
92 length_bytes = sys.stdin.read(4) | 96 length_bytes = sys.stdin.read(4) |
93 if len(length_bytes) == 0: | 97 if len(length_bytes) == 0: |
94 return False # EOF | 98 return False # EOF |
(...skipping 26 matching lines...) Expand all Loading... |
121 global test_count | 125 global test_count |
122 test_count += 1 | 126 test_count += 1 |
123 | 127 |
124 return True | 128 return True |
125 | 129 |
126 while True: | 130 while True: |
127 if not do_test_io(): | 131 if not do_test_io(): |
128 sys.stderr.write("conformance_python: received EOF from test runner " + | 132 sys.stderr.write("conformance_python: received EOF from test runner " + |
129 "after %s tests, exiting\n" % (test_count)) | 133 "after %s tests, exiting\n" % (test_count)) |
130 sys.exit(0) | 134 sys.exit(0) |
OLD | NEW |