source: subversion/applications/routing/pyroute_webGUI/server.py @ 8081

Last change on this file since 8081 was 8081, checked in by ojw, 11 years ago

outline of some code to write

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/usr/bin/python
2#----------------------------------------------------------------------------
3# DEVELOPMENT CODE, DO NOT USE
4#----------------------------------------------------------------------------
5# Copyright 2008, Oliver White
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#---------------------------------------------------------------------------
20from BaseHTTPServer import *
21import re
22import sys
23
24class tileServer(BaseHTTPRequestHandler):
25  def __init__(self, request, client_address, server):
26    self.re = re.compile('/(\w+)/(\d+)/(\d+)/(\d+)\.png')
27    BaseHTTPRequestHandler.__init__(self, request, client_address, server)
28
29  def log_message(self, format, *args):
30    pass  # Kill logging to stderr
31 
32  def return_file(self, filename, contentType='text/HTML'):
33    # Serve a real file from disk (for indexes etc.)
34    f = open(filename, "r")
35    self.send_response(200)
36    self.send_header('Content-type',contentType) # TODO: more headers
37    self.end_headers()
38    self.wfile.write(f.read())
39    f.close()
40
41  def do_GET(self):
42    # Specific files to serve:
43    if self.path[0:1]=='/':
44      self.return_file('slippy.html')
45      return
46
47    # See if a tile was requested
48    match = self.re.search(self.path)
49    if(match):
50      (layer,z,x,y) = match.groups()
51      z = int(z)
52      x = int(x)
53      y = int(y)
54     
55      # Render the tile
56      print 'Request for %d,%d at zoom %d, layer %s' % (x,y,z,layer)
57      self.send_response(404)
58      return
59     
60      # Return the tile as a PNG
61      self.send_response(200)
62      self.send_header('Content-type','image/PNG')
63      self.end_headers()
64      self.wfile.write(pngData)
65    else:
66      self.send_response(404)
67
68try:
69  server = HTTPServer(('',1280), tileServer)
70  server.serve_forever()
71except KeyboardInterrupt:
72  server.socket.close()
73  sys.exit()
74
Note: See TracBrowser for help on using the repository browser.