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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
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.
6 from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
7 import optparse
8 import os
9 from StringIO import StringIO
10 import sys
11 import urlparse
12
13 from handler import Handler
14
15 class Response(object):
16 def __init__(self):
17 self.status = 200
18 self.out = StringIO()
19 self.headers = {}
20
21 def set_status(self, status):
22 self.status = status
23
24 class Request(object):
25 def __init__(self, path):
26 self.headers = {}
27 self.path = path
28
29 class RequestHandler(BaseHTTPRequestHandler):
30 """A HTTPRequestHandler that outputs the docs page generated by Handler.
31 """
32 def do_GET(self):
33 parsed_url = urlparse.urlparse(self.path)
34 request = Request(parsed_url.path)
35 response = Response()
36 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.
37 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.
38 self.wfile.write(response.out.getvalue())
39 else:
40 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.
41
42 if __name__ == '__main__':
43 parser = optparse.OptionParser(
44 description='Runs a server to preview the extension documentation.',
45 usage='usage: %prog [option]...')
46 parser.add_option('-p', '--port', default=8000,
47 help='port to run the server on')
48
49 (opts, argv) = parser.parse_args()
50
51 try:
52 print('Starting previewserver on port %d' % opts.port)
53 print('The extension documentation can be found at:')
54 print('')
55 print(' http://localhost:%d' % opts.port)
56 print('')
57
58 server = HTTPServer(('', int(opts.port)), RequestHandler)
59 server.serve_forever()
60 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.
61 server.socket.close()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698