source: subversion/applications/rendering/parking/osray/osray_server.py @ 21956

Last change on this file since 21956 was 21956, checked in by kdrangmeister, 9 years ago

osray: server

  • Property svn:mime-type set to text/plain
File size: 2.3 KB
Line 
1# -*- coding: utf-8 -*-
2
3import string, cgi, time
4from os import curdir, sep
5from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
6import urlparse
7
8class osrayHandler(BaseHTTPRequestHandler):
9
10    def do_GET(self):
11        try:
12            theurl = self.path
13            if theurl == "/favicon.ico":
14                self.send_response(200)
15                self.end_headers()
16                self.wfile.write("")
17                return
18            baseurl = urlparse.urlparse(theurl)[2]
19            if baseurl.endswith(".png"):
20                f = open(curdir + sep + 'scene-osray.png')
21                self.send_response(200)
22                self.send_header('Content-type','image/png')
23                self.end_headers()
24                self.wfile.write(f.read())
25                f.close()
26                return
27            print "URL was ", theurl
28            urlqs = urlparse.urlparse(theurl)[4]
29            print "URL qs:", urlqs
30            queryparams = urlparse.parse_qs(urlqs)
31            print queryparams
32            self.send_response(200)
33            self.send_header('Content-type', 'text/html')
34            self.end_headers()
35            self.wfile.write("hey, today is the" + str(time.localtime()[7]))
36            self.wfile.write(" day in the year " + str(time.localtime()[0]))
37            return
38        except IOError:
39            self.send_error(404, 'File Not Found: %s' % self.path)
40
41
42"""
43    def do_POST(self):
44        global rootnode
45        try:
46            ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
47            if ctype == 'multipart/form-data':
48                query = cgi.parse_multipart(self.rfile, pdict)
49            self.send_response(301)
50           
51            self.end_headers()
52            upfilecontent = query.get('upfile')
53            print "filecontent", upfilecontent[0]
54            self.wfile.write("<HTML>POST OK.<BR><BR>");
55            self.wfile.write(upfilecontent[0]);
56           
57        except :
58            pass
59"""
60
61def main():
62    try:
63        server = HTTPServer(('', 8087), osrayHandler)
64        print 'started osray server...'
65        server.serve_forever()
66    except KeyboardInterrupt:
67        print 'shutting down server'
68        server.socket.close()
69
70if __name__ == '__main__':
71    main()
Note: See TracBrowser for help on using the repository browser.