Add more support for .ca domains parse dates, names, and emails correctly
authorBrian Murphy <brian.p.murphy@gmail.com>
Mon, 27 Jun 2016 17:00:26 +0000
changeset 102 e8cb8d1367c0
parent 101 e804426aad35
child 103 9b79ce8f9829
Add more support for .ca domains parse dates, names, and emails correctly
test/test_parser.py
whois/parser.py
--- a/test/test_parser.py	Wed Jun 15 09:39:05 2016 +0100
+++ b/test/test_parser.py	Mon Jun 27 17:00:26 2016 +0000
@@ -95,5 +95,91 @@
                       % (fail, total))
 
 
+    def test_ca_parse(self):
+        data = """
+        Domain name:           testdomain.ca
+        Domain status:         registered
+        Creation date:         2000/11/20
+        Expiry date:           2020/03/08
+        Updated date:          2016/04/29
+        DNSSEC:                Unsigned
+
+        Registrar:
+            Name:              Webnames.ca Inc.
+            Number:            70
+
+        Registrant:
+            Name:              Test Industries
+
+        Administrative contact:
+            Name:              Test Person1
+            Postal address:    Test Address
+                               Test City, TestVille
+            Phone:             +1.1235434123x123
+            Fax:               +1.123434123
+            Email:             testperson1@testcompany.ca
+
+        Technical contact:
+            Name:              Test Persion2
+            Postal address:    Other TestAddress
+                               TestTown OCAS Canada
+            Phone:             +1.09876545123
+            Fax:               +1.12312993873
+            Email:             testpersion2@testcompany.ca
+
+        Name servers:
+            ns1.testserver1.net
+            ns2.testserver2.net
+        """
+        results = WhoisEntry.load('testcompany.ca', data)
+        expected_results = {
+            "updated_date": "2016-04-29 00:00:00", 
+            "registrant_name": [
+                "Webnames.ca Inc.", 
+                "Test Industries", 
+                "Test Person1", 
+                "Test Persion2"
+            ], 
+            "fax": [
+                "+1.123434123", 
+                "+1.12312993873"
+            ], 
+            "dnssec": "Unsigned", 
+            "registrant_number": "70", 
+            "expiration_date": "2020-03-08 00:00:00", 
+            "domain_name": "testdomain.ca", 
+            "creation_date": "2000-11-20 00:00:00", 
+            "phone": [
+                "+1.1235434123x123", 
+                "+1.09876545123"
+            ], 
+            "domain_status": "registered", 
+            "emails": [
+                "testperson1@testcompany.ca", 
+                "testpersion2@testcompany.ca"
+            ]
+        }
+        
+        fail = 0
+        total = 0
+
+        # Compare each key
+        for key in expected_results:
+            total += 1
+            result = results.get(key)
+            if isinstance(result, datetime.datetime):
+                result = str(result)
+            expected = expected_results.get(key)
+            if expected != result:
+                print("%s \t(%s):\t %s != %s" % (domain, key, result, expected))
+                fail += 1
+        if fail:
+            self.fail("%d/%d sample whois attributes were not parsed properly!"
+                      % (fail, total))
+
+
+
+        
+
 if __name__ == '__main__':
     unittest.main()
--- a/whois/parser.py	Wed Jun 15 09:39:05 2016 +0100
+++ b/whois/parser.py	Mon Jun 27 17:00:26 2016 +0000
@@ -457,8 +457,17 @@
     """Whois parser for .ca domains
     """
     regex = {
-        'registrant_name':                'Name: *(.+)',
+        'domain_name':                    'Domain name: *(.+)',
+        'registrant_name':                '(?<!Domain) Name: *(.+)',
         'registrant_number':              'Number: *(.+)\n',
+        'domain_status':                  'Domain status: *(.+)',
+        'emails':                         'Email: *(.+)',
+        'updated_date':                   'Updated Date: *(.+)',
+        'creation_date':                  'Creation Date: *(.+)',
+        'expiration_date':                'Expiry Date: *(.+)',
+        'phone':                          'Phone: *(.+)',
+        'fax':                            'Fax: *(.+)',
+        'dnssec':                         'dnssec: *([\S]+)'
     }
 
     def __init__(self, domain, text):