added pretty formatting to string rendering
authorRichard Penman
Tue, 01 Sep 2015 12:06:17 +0800
changeset 59 f1e5214a1b16
parent 58 5c89d5dbac5b
child 60 7801a420f679
added pretty formatting to string rendering
whois/parser.py
--- a/whois/parser.py	Tue Sep 01 12:00:34 2015 +0800
+++ b/whois/parser.py	Tue Sep 01 12:06:17 2015 +0800
@@ -1,12 +1,13 @@
 # coding=utf-8
-from datetime import datetime
-
 # parser.py - Module for parsing whois response data
 # Copyright (c) 2008 Andrey Petrov
 #
 # This module is part of pywhois and is released under
 # the MIT license: http://www.opensource.org/licenses/mit-license.php
 
+
+import json
+from datetime import datetime
 import re
 try:
     import dateutil.parser as dp
@@ -137,6 +138,11 @@
         return self.get(name)
         
 
+    def __str__(self):
+        handler = lambda e: str(e)
+        return json.dumps(self, indent=2, default=handler)
+
+
     @staticmethod
     def load(domain, text):
         """Given whois output in ``text``, return an instance of ``WhoisEntry``