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

Unified Diff: cms/bin/test_server.py

Issue 29345291: Noissue - Adapt quotes for compliance with our coding style in the CMS (Closed)
Patch Set: Created May 29, 2016, 1:27 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cms/bin/generate_static_pages.py ('k') | cms/bin/translate.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cms/bin/test_server.py
===================================================================
--- a/cms/bin/test_server.py
+++ b/cms/bin/test_server.py
@@ -28,9 +28,9 @@
address = None
port = None
-UNICODE_ENCODING = "utf-8"
+UNICODE_ENCODING = 'utf-8'
-ERROR_TEMPLATE = """
+ERROR_TEMPLATE = '''
<html>
<head>
<title>{{status}}</title>
@@ -45,7 +45,7 @@
<pre>{{error}}</pre>
{% endif %}
</body>
-</html>"""
+</html>'''
# Initilize the mimetypes modules manually for consistent behavior,
# ignoring local files and Windows Registry.
@@ -53,21 +53,21 @@
def get_page(path):
- path = path.strip("/")
- if path == "":
- path = source.read_config().get("general", "defaultlocale")
- if "/" in path:
- locale, page = path.split("/", 1)
+ path = path.strip('/')
+ if path == '':
+ path = source.read_config().get('general', 'defaultlocale')
+ if '/' in path:
+ locale, page = path.split('/', 1)
else:
- locale, page = path, ""
+ locale, page = path, ''
- default_page = source.read_config().get("general", "defaultpage")
- alternative_page = "/".join([page, default_page]).lstrip("/")
+ default_page = source.read_config().get('general', 'defaultpage')
+ alternative_page = '/'.join([page, default_page]).lstrip('/')
for format in converters.iterkeys():
for p in (page, alternative_page):
if source.has_page(p, format):
- return (p, process_page(source, locale, p, format, "http://%s:%d" % (address, port)))
+ return (p, process_page(source, locale, p, format, 'http://%s:%d' % (address, port)))
if source.has_localizable_file(locale, page):
return (page, source.read_localizable_file(locale, page))
@@ -80,7 +80,7 @@
if pages.count(page) > 1:
return True
- if any(p.startswith(page + "/") or page.startswith(p + "/") for p in pages):
+ if any(p.startswith(page + '/') or page.startswith(p + '/') for p in pages):
return True
return False
@@ -91,36 +91,36 @@
page, data = get_page(path)
if page and has_conflicting_pages(page):
- raise Exception("The requested page conflicts with another page")
+ raise Exception('The requested page conflicts with another page')
return data
def show_error(start_response, status, **kwargs):
env = jinja2.Environment(autoescape=True)
template = env.from_string(ERROR_TEMPLATE)
- mime = "text/html; encoding=%s" % UNICODE_ENCODING
- start_response(status, [("Content-Type", mime)])
+ mime = 'text/html; encoding=%s' % UNICODE_ENCODING
+ start_response(status, [('Content-Type', mime)])
for fragment in template.stream(status=status, **kwargs):
yield fragment.encode(UNICODE_ENCODING)
def handler(environ, start_response):
- path = environ.get("PATH_INFO")
+ path = environ.get('PATH_INFO')
data = get_data(path)
if data is None:
- return show_error(start_response, "404 Not Found", uri=path)
+ return show_error(start_response, '404 Not Found', uri=path)
- mime = mimetypes.guess_type(path)[0] or "text/html"
+ mime = mimetypes.guess_type(path)[0] or 'text/html'
if isinstance(data, unicode):
data = data.encode(UNICODE_ENCODING)
- mime = "%s; charset=%s" % (mime, UNICODE_ENCODING)
+ mime = '%s; charset=%s' % (mime, UNICODE_ENCODING)
- start_response("200 OK", [("Content-Type", mime)])
+ start_response('200 OK', [('Content-Type', mime)])
return [data]
-if __name__ == "__main__":
+if __name__ == '__main__':
parser = argparse.ArgumentParser(description='CMS development server created to test pages locally and on-the-fly')
parser.add_argument('path', nargs='?', default=os.curdir)
@@ -143,7 +143,7 @@
# root logger. Also we must prevent it from propagating
# messages, otherwise messages are logged twice.
import logging
- logger = logging.getLogger("werkzeug")
+ logger = logging.getLogger('werkzeug')
logger.propagate = False
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
@@ -161,11 +161,11 @@
try:
return app(environ, start_response)
except Exception, e:
- return show_error(start_response, "500 Internal Server Error",
- uri=environ.get("PATH_INFO"), error=e)
+ return show_error(start_response, '500 Internal Server Error',
+ uri=environ.get('PATH_INFO'), error=e)
server = make_server(host, port, wrapper, ThreadedWSGIServer)
- print " * Running on http://%s:%i/" % server.server_address
+ print ' * Running on http://%s:%i/' % server.server_address
server.serve_forever()
run(address, port, handler, use_reloader=True, use_debugger=True)
« no previous file with comments | « cms/bin/generate_static_pages.py ('k') | cms/bin/translate.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld