Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2525)

Unified Diff: chrome/common/extensions/docs/server2/previewserver.py

Issue 10823105: Extensions Docs Server: Preview server and more integration tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/previewserver.py
diff --git a/chrome/common/extensions/docs/server2/previewserver.py b/chrome/common/extensions/docs/server2/previewserver.py
new file mode 100755
index 0000000000000000000000000000000000000000..9ff68e8db729cce1f3ab6e62e87883e380e879cf
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/previewserver.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
not at google - send to devlin 2012/07/31 21:34:40 comment plz. People will probably open up this fil
cduvall 2012/07/31 21:53:10 Done.
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+import optparse
+import os
+from StringIO import StringIO
+import sys
+import urlparse
+
+from handler import Handler
+
+class Response(object):
+ def __init__(self):
+ self.status = 200
+ self.out = StringIO()
+ self.headers = {}
+
+ def set_status(self, status):
+ self.status = status
+
+class Request(object):
+ def __init__(self, path):
+ self.headers = {}
+ self.path = path
+
+class RequestHandler(BaseHTTPRequestHandler):
+ """A HTTPRequestHandler that outputs the docs page generated by Handler.
+ """
+ def do_GET(self):
+ parsed_url = urlparse.urlparse(self.path)
+ request = Request(parsed_url.path)
+ response = Response()
+ Handler(request, response, local_path='../..').get()
not at google - send to devlin 2012/07/31 21:34:40 It's equally likely that this script will be run f
cduvall 2012/07/31 21:53:10 Done.
+ if os.path.splitext(parsed_url.path)[-1] in ['.png', '.gif', '.jpeg']:
not at google - send to devlin 2012/07/31 21:34:40 is the difference here in encoding? like, should t
cduvall 2012/07/31 21:53:10 Done.
+ self.wfile.write(response.out.getvalue())
+ else:
+ self.wfile.write(response.out.getvalue().encode('ascii', 'replace'))
not at google - send to devlin 2012/07/31 21:34:40 utf8 would be more appropriate if it works? ascii
cduvall 2012/07/31 21:53:10 Done.
+
+if __name__ == '__main__':
+ parser = optparse.OptionParser(
+ description='Runs a server to preview the extension documentation.',
+ usage='usage: %prog [option]...')
+ parser.add_option('-p', '--port', default=8000,
+ help='port to run the server on')
+
+ (opts, argv) = parser.parse_args()
+
+ try:
+ print('Starting previewserver on port %d' % opts.port)
+ print('The extension documentation can be found at:')
+ print('')
+ print(' http://localhost:%d' % opts.port)
+ print('')
+
+ server = HTTPServer(('', int(opts.port)), RequestHandler)
+ server.serve_forever()
+ except KeyboardInterrupt:
not at google - send to devlin 2012/07/31 21:34:40 "finally" would be a more appropriate idiom.
cduvall 2012/07/31 21:53:10 Done.
+ server.socket.close()

Powered by Google App Engine
This is Rietveld 408576698