Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: cms/bin/test_server.py

Issue 6236544096534528: Issue 2578 - Refactored and added missing hidden import (Closed)
Patch Set: Created May 22, 2015, 9:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runserver.py » ('j') | runserver.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 if isinstance(data, unicode): 93 if isinstance(data, unicode):
94 data = data.encode(UNICODE_ENCODING) 94 data = data.encode(UNICODE_ENCODING)
95 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING) 95 mime = "%s; charset=%s" % (mime, UNICODE_ENCODING)
96 96
97 start_response("200 OK", [("Content-Type", mime)]) 97 start_response("200 OK", [("Content-Type", mime)])
98 return [data] 98 return [data]
99 99
100 if __name__ == "__main__": 100 if __name__ == "__main__":
101 if len(sys.argv) < 2: 101 if len(sys.argv) < 2:
102 print >>sys.stderr, "Usage: %s source_dir" % sys.argv[0] 102 source = FileSource(os.curdir)
103 sys.exit(1) 103 elif os.path.isdir(sys.argv[1]):
104 104 source = FileSource(sys.argv[1])
105 source = FileSource(sys.argv[1]) 105 else:
106 sys.exit("Usage: %s [source_dir]" % sys.argv[0])
106 107
107 try: 108 try:
108 from werkzeug.serving import run_simple 109 from werkzeug.serving import run_simple
109 def run(*args, **kwargs): 110 def run(*args, **kwargs):
110 # The werkzeug logger must be configured before the 111 # The werkzeug logger must be configured before the
111 # root logger. Also we must prevent it from propagating 112 # root logger. Also we must prevent it from propagating
112 # messages, otherwise messages are logged twice. 113 # messages, otherwise messages are logged twice.
113 import logging 114 import logging
114 logger = logging.getLogger("werkzeug") 115 logger = logging.getLogger("werkzeug")
115 logger.propagate = False 116 logger.propagate = False
116 logger.setLevel(logging.INFO) 117 logger.setLevel(logging.INFO)
117 logger.addHandler(logging.StreamHandler()) 118 logger.addHandler(logging.StreamHandler())
118 119
119 run_simple(*args, **kwargs) 120 run_simple(*args, **kwargs)
120 except ImportError: 121 except ImportError:
121 from wsgiref.simple_server import make_server 122 from wsgiref.simple_server import make_server
122 def run(host, port, app, **kwargs): 123 def run(host, port, app, **kwargs):
123 def wrapper(environ, start_response): 124 def wrapper(environ, start_response):
124 try: 125 try:
125 return app(environ, start_response) 126 return app(environ, start_response)
126 except Exception, e: 127 except Exception, e:
127 return show_error(start_response, "500 Internal Server Error", 128 return show_error(start_response, "500 Internal Server Error",
128 uri=environ.get("PATH_INFO"), error=e) 129 uri=environ.get("PATH_INFO"), error=e)
129 130
130 server = make_server(host, port, wrapper) 131 server = make_server(host, port, wrapper)
131 print " * Running on http://%s:%i/" % server.server_address 132 print " * Running on http://%s:%i/" % server.server_address
132 server.serve_forever() 133 server.serve_forever()
133 134
134 run("localhost", 5000, handler, use_reloader=True, use_debugger=True) 135 run("localhost", 5000, handler, use_reloader=True, use_debugger=True)
OLDNEW
« no previous file with comments | « no previous file | runserver.py » ('j') | runserver.py » ('J')

Powered by Google App Engine
This is Rietveld