summaryrefslogtreecommitdiff
path: root/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'core.py')
-rw-r--r--core.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/core.py b/core.py
index cdb5343..430bdf2 100644
--- a/core.py
+++ b/core.py
@@ -7,16 +7,26 @@ class Daemon():
def query(self, q):
if self.is_ip(q):
- self.search_ip(q)
+ result = self.search_ip(q)
elif self.is_domain(q):
- self.search_domain(q)
+ result = self.search_domain(q)
else:
# Try to find a person with the given query
person = search_person(q)
if person:
- return person
+ result = person
else:
- return self.get_help()
+ result = self.get_help()
+
+ return self.format_result(result)
+
+ def format_result(self, values):
+ """Receive a dictionary and return a string"""
+ result = ""
+ for k, v in values.items():
+ result += '{0}: {1}\n'.format(k, v)
+
+ return result
def search_ip(self, ip):
result = {}
@@ -70,13 +80,14 @@ class WhoisHandler(socketserver.BaseRequestHandler):
self.daemon = self.server.daemon
def handle(self):
- data = str(self.request.recv(100), 'utf-8')[:-2]
+ data = str(self.request.recv(100).strip(), 'utf-8')
+ print('Received: {}'.format(data))
- response = self.daemon.get_header() + "\n"
- response += self.daemon.query(data) + "\n"
- response += self.daemon.get_footer()
+ response = self.daemon.get_header() + " \n"
+ response += self.daemon.query(data)
+ response += self.daemon.get_footer() + "\n"
- self.request.sendall(response)
+ self.request.sendall(bytes(response, 'utf-8'))
class ClassicServer(socketserver.ThreadingTCPServer):
def __init__(self, config, daemon):
nihil fit ex nihilo