Update TODO based on work for 0.4.1
[python-rwhoisd.git] / rwhoisd / RwhoisServer.py
index cf3b8a7..2729f85 100644 (file)
@@ -1,4 +1,21 @@
-#! /usr/bin/python
+# This file is part of python-rwhoisd
+#
+# Copyright (C) 2003, 2008 David E. Blacka
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
 
 import sys, socket, SocketServer
 
@@ -42,7 +59,6 @@ class RwhoisHandler(SocketServer.StreamRequestHandler):
         
     def handle(self):
 
-        print repr(self.request)
         self.quit_flag = False
 
         # output a banner
@@ -66,13 +82,16 @@ class RwhoisHandler(SocketServer.StreamRequestHandler):
             # we can skip blank lines.
             if not line:
                 continue
-            
-            if line.startswith("-"):
-                self.handle_directive(session, line)
-            else:
-                self.handle_query(session, line)
-                if not session.holdconnect:
-                    self.quit_flag = True
+        
+            try:
+                if line.startswith("-"):
+                    self.handle_directive(session, line)
+                else:
+                    self.handle_query(session, line)
+                    if not session.holdconnect:
+                        self.quit_flag = True
+            except Rwhois.RwhoisError, e:
+                self.handle_error(session, e)
 
             self.wfile.flush()
 
@@ -96,6 +115,10 @@ class RwhoisHandler(SocketServer.StreamRequestHandler):
             print "%s query %s" % (self.client_address, line)
         query_processor.process_query(session, line)
 
+    def handle_error(self, session, error):
+        code = error[0]
+        msg = error[1]
+        session.wfile.write(Rwhois.error_message((code, msg)))
 
 def usage(pname):
     print """\