| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 """Server for viewing the compiled C++ code from tools/json_schema_compiler. | 6 """Server for viewing the compiled C++ code from tools/json_schema_compiler. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import cc_generator | 9 import cc_generator |
| 10 import code | 10 import code |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 self.server.highlighters[highlighter_param].GetCSS(style_param) + | 242 self.server.highlighters[highlighter_param].GetCSS(style_param) + |
| 243 '</style>') | 243 '</style>') |
| 244 body.Append(self.server.highlighters[highlighter_param] | 244 body.Append(self.server.highlighters[highlighter_param] |
| 245 .GetCodeElement(cpp_code, style_param)) | 245 .GetCodeElement(cpp_code, style_param)) |
| 246 except IOError: | 246 except IOError: |
| 247 self.send_error(404, "File not found: %s" % request_path) | 247 self.send_error(404, "File not found: %s" % request_path) |
| 248 return | 248 return |
| 249 except (TypeError, KeyError, AttributeError, | 249 except (TypeError, KeyError, AttributeError, |
| 250 AssertionError, NotImplementedError) as error: | 250 AssertionError, NotImplementedError) as error: |
| 251 body.Append('<pre>') | 251 body.Append('<pre>') |
| 252 body.Append('compiler error: ' + str(error)) | 252 body.Append('compiler error: %s' % error) |
| 253 body.Append('Check server log for more details') | 253 body.Append('Check server log for more details') |
| 254 body.Append('</pre>') | 254 body.Append('</pre>') |
| 255 raise | 255 raise |
| 256 | 256 |
| 257 def _GetHighlighterParams(self, parsed_url): | 257 def _GetHighlighterParams(self, parsed_url): |
| 258 """Get the highlighting parameters from a parsed url. | 258 """Get the highlighting parameters from a parsed url. |
| 259 """ | 259 """ |
| 260 query_dict = urlparse.parse_qs(parsed_url.query) | 260 query_dict = urlparse.parse_qs(parsed_url.query) |
| 261 return (query_dict.get('highlighter', ['pygments'])[0], | 261 return (query_dict.get('highlighter', ['pygments'])[0], |
| 262 query_dict.get('style', ['colorful'])[0]) | 262 query_dict.get('style', ['colorful'])[0]) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter() | 352 highlighters['pygments'] = pygments_highlighter.PygmentsHighlighter() |
| 353 except ImportError as e: | 353 except ImportError as e: |
| 354 pass | 354 pass |
| 355 | 355 |
| 356 server = PreviewHTTPServer(('', int(opts.port)), | 356 server = PreviewHTTPServer(('', int(opts.port)), |
| 357 CompilerHandler, | 357 CompilerHandler, |
| 358 highlighters) | 358 highlighters) |
| 359 server.serve_forever() | 359 server.serve_forever() |
| 360 except KeyboardInterrupt: | 360 except KeyboardInterrupt: |
| 361 server.socket.close() | 361 server.socket.close() |
| OLD | NEW |