diff --git a/whois/__init__.py b/whois/__init__.py index 3d70396..8c9bb28 100644 --- a/whois/__init__.py +++ b/whois/__init__.py @@ -7,5 +7,4 @@ # \/_/ \/_/ \/_/ \/_/ \/_/ from whois import Whois as whois -from parser import Parser as parser - +from parser import Parser diff --git a/whois/flags.py b/whois/flags.py new file mode 100644 index 0000000..13fbcd2 --- /dev/null +++ b/whois/flags.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +'''This file contains flag variables.''' + +RETURN_TYPE_LIST=0x01 +RETURN_TYPE_DICT=0x02 diff --git a/whois/whois.py b/whois/whois.py index d1db049..07d774a 100644 --- a/whois/whois.py +++ b/whois/whois.py @@ -13,6 +13,7 @@ import re import logging import error +import flags class Whois(object): def __init__(self, domain, debug=False): @@ -45,6 +46,7 @@ class Whois(object): logging.debug("__init__: No server settings found") def chooseServer(self): + '''Choose whois server by detecting tld of given domain.''' if "host" in self.settings: logging.debug("chooseServer: Whois server addr: %s"%(self.settings["host"])) return self.settings["host"] @@ -53,6 +55,7 @@ class Whois(object): return self.tld + ".whois-servers.net" def sendQuery(self, whoisServer): + '''Send query to whois server.''' logging.debug("sendQuery: Connecting to whois server") s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -90,7 +93,8 @@ class Whois(object): return finalResult - def query(self, redirect=True): + def query(self, redirect=True, return_type=flags.RETURN_TYPE_LIST): + '''Start whole process of whois query. This method will do them all.''' whoisServer = self.chooseServer() result = self.sendQuery(whoisServer) @@ -105,4 +109,7 @@ class Whois(object): redirection = re.findall(self.settings["redirect"], result) - return whoisServer, result + if return_type == flags.RETURN_TYPE_LIST: + return whoisServer, result + else: + return {"whoisServer": whoisServer, "result": result}