summaryrefslogtreecommitdiff
path: root/core.py
diff options
context:
space:
mode:
authorRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-02 22:51:17 -0300
committerRaúl Benencia <rbenencia@linti.unlp.edu.ar>2012-08-02 22:51:17 -0300
commit9d13223e971c1bb37b141cb0b0a3a7dd4077f4d8 (patch)
treee5894afd118054f58d6dd19cc95bb8db93208ed0 /core.py
parentee504272d535dcfab2d00948a1b005b87dc6605a (diff)
Fix various semantic errors
Diffstat (limited to 'core.py')
-rw-r--r--core.py64
1 files changed, 37 insertions, 27 deletions
diff --git a/core.py b/core.py
index 1ac7e4f..cdb5343 100644
--- a/core.py
+++ b/core.py
@@ -2,34 +2,33 @@ import socketserver
import ipaddr
class Daemon():
- def __init__(data):
+ def __init__(self, data):
self.data = data
- def query(q):
+ def query(self, q):
if self.is_ip(q):
- self.search_ip(q)
-
+ self.search_ip(q)
elif self.is_domain(q):
- self.search_domain(q)
-
+ self.search_domain(q)
else:
# Try to find a person with the given query
person = search_person(q)
if person:
return person
else:
- return self.show_help()
+ return self.get_help()
def search_ip(self, ip):
result = {}
# Iterate over all IP block elements
- for network in self.data.get_networks():
- for block in network.ip_blocks:
+ networks = self.data.get_networks()
+ for key in networks:
+ for block in networks[key].ip_blocks:
if ipaddr.IPAddress(ip) in ipaddr.IPNetwork(block):
- result['name'] = network.name
- for key in network.data:
- result[key] = network.data[key]
+ result['name'] = networks[key].name
+ for k in networks[key].data:
+ result[k] = networks[key].data[k]
return result
@@ -40,46 +39,57 @@ class Daemon():
def search_domain(self, domain):
pass
+ # TODO
+
def search_person(self, query):
pass
# TODO
def is_ip(self, query):
- pass
+ return True
# TODO
def is_domain(self, query):
pass
# TODO
- def show_help():
- pass
+ def get_help(self):
+ return "This will be the help"
+
+ # TODO
+ def get_footer(self):
+ return "This will be the footer"
+
+ # TODO
+ def get_header(self):
+ return "This will be the header"
class WhoisHandler(socketserver.BaseRequestHandler):
+ def setup(self):
+ self.daemon = self.server.daemon
+
def handle(self):
- daemon = self.server.daemon
- data = self.request.recv(100)
- cur_thread = threading.current_thread()
- response = daemon.get_header() + "\n" + daemon.query(data) + "\n" + daemon.get_footer()
+ data = str(self.request.recv(100), 'utf-8')[:-2]
+
+ response = self.daemon.get_header() + "\n"
+ response += self.daemon.query(data) + "\n"
+ response += self.daemon.get_footer()
self.request.sendall(response)
-class ClassicServer(socketserver.ThreadingTCPServer):
+class ClassicServer(socketserver.ThreadingTCPServer):
def __init__(self, config, daemon):
host = config['Servers']['classic_host']
- port = config['Servers']['classic_port']
+ port = int(config['Servers']['classic_port'])
self.daemon = daemon
- ThreadingTCPServer.__init__(self, (host, port), WhoisHandler)
-
- def start(self):
- pass
+ socketserver.ThreadingTCPServer.__init__(self, (host, port), WhoisHandler)
class WebServer(socketserver.ThreadingTCPServer):
def __init__(self, config, daemon):
self.host = config['Servers']['web_host']
- self.port = config['Servers']['web_port']
+ self.port = int(config['Servers']['web_port'])
self.daemon = daemon
- ThreadingTCPServer.__init__(self, (host, port), WhoisHandler)
+ socketserver.ThreadingTCPServer.__init__(self, (self.host, self.port), WhoisHandler)
nihil fit ex nihilo