X-Git-Url: https://blacka.com/cgi-bin/gitweb.cgi?p=python-rwhoisd.git;a=blobdiff_plain;f=rwhoisd%2FRwhoisServer.py;h=2729f85841cfc126e369a2735fb45e96f003e470;hp=cf3b8a7e96acec552c14e2d4c1ef9f6bbec3fce9;hb=HEAD;hpb=43edb56f0f6d14eb7578ccfc39da801b906870e1 diff --git a/rwhoisd/RwhoisServer.py b/rwhoisd/RwhoisServer.py index cf3b8a7..2729f85 100644 --- a/rwhoisd/RwhoisServer.py +++ b/rwhoisd/RwhoisServer.py @@ -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 """\