| OLD | NEW |
| 1 import os, sys, array, json, math, StringIO | 1 import os, sys, array, json, math, StringIO |
| 2 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | 2 sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 3 import subresource | 3 import subresource |
| 4 | 4 |
| 5 class Image: | 5 class Image: |
| 6 """This class partially implements the interface of the PIL.Image.Image. | 6 """This class partially implements the interface of the PIL.Image.Image. |
| 7 One day in the future WPT might support the PIL module or another imaging | 7 One day in the future WPT might support the PIL module or another imaging |
| 8 library, so this hacky BMP implementation will no longer be required. | 8 library, so this hacky BMP implementation will no longer be required. |
| 9 """ | 9 """ |
| 10 def __init__(self, width, height): | 10 def __init__(self, width, height): |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 img = Image.new("RGB", (sqrt, sqrt), "black") | 81 img = Image.new("RGB", (sqrt, sqrt), "black") |
| 82 img.putdata(color_data) | 82 img.putdata(color_data) |
| 83 | 83 |
| 84 # Flush image to string. | 84 # Flush image to string. |
| 85 f = StringIO.StringIO() | 85 f = StringIO.StringIO() |
| 86 img.save(f, "BMP") | 86 img.save(f, "BMP") |
| 87 f.seek(0) | 87 f.seek(0) |
| 88 | 88 |
| 89 return f.read() | 89 return f.read() |
| 90 | 90 |
| 91 def generate_payload(server_data): | 91 def generate_payload(request, server_data): |
| 92 data = ('{"headers": %(headers)s}') % server_data | 92 data = ('{"headers": %(headers)s}') % server_data |
| 93 return encode_string_as_bmp_image(data) | 93 if "id" in request.GET: |
| 94 request.server.stash.put(request.GET["id"], data) |
| 95 data = encode_string_as_bmp_image(data) |
| 96 return data |
| 97 |
| 98 def generate_report_headers_payload(request, server_data): |
| 99 stashed_data = request.server.stash.take(request.GET["id"]) |
| 100 return stashed_data |
| 94 | 101 |
| 95 def main(request, response): | 102 def main(request, response): |
| 103 handler = lambda data: generate_payload(request, data) |
| 104 content_type = 'image/bmp' |
| 105 |
| 106 if "report-headers" in request.GET: |
| 107 handler = lambda data: generate_report_headers_payload(request, data) |
| 108 content_type = 'application/json' |
| 109 |
| 96 subresource.respond(request, | 110 subresource.respond(request, |
| 97 response, | 111 response, |
| 98 payload_generator = generate_payload, | 112 payload_generator = handler, |
| 99 content_type = "image/bmp", | 113 content_type = content_type, |
| 100 access_control_allow_origin = "*") | 114 access_control_allow_origin = "*") |
| OLD | NEW |