whois/parser.py
changeset 17 2d4e7d896236
parent 16 098d65e3cce7
child 18 0181ec83a7e9
equal deleted inserted replaced
16:098d65e3cce7 17:2d4e7d896236
    23         '%Y/%m/%d',                 # 2000/01/02
    23         '%Y/%m/%d',                 # 2000/01/02
    24         '%d-%b-%Y %H:%M:%S %Z',		# 24-Jul-2009 13:20:03 UTC
    24         '%d-%b-%Y %H:%M:%S %Z',		# 24-Jul-2009 13:20:03 UTC
    25         '%a %b %d %H:%M:%S %Z %Y',  # Tue Jun 21 23:59:59 GMT 2011
    25         '%a %b %d %H:%M:%S %Z %Y',  # Tue Jun 21 23:59:59 GMT 2011
    26         '%Y-%m-%dT%H:%M:%SZ',       # 2007-01-26T19:10:31Z
    26         '%Y-%m-%dT%H:%M:%SZ',       # 2007-01-26T19:10:31Z
    27         '%Y-%m-%d %H:%M:%SZ',       # 2000-08-22 18:55:20Z
    27         '%Y-%m-%d %H:%M:%SZ',       # 2000-08-22 18:55:20Z
       
    28         '%Y-%m-%d %H:%M:%S',        # 2000-08-22 18:55:20
    28         '%d %b %Y %H:%M:%S',        # 08 Apr 2013 05:44:00
    29         '%d %b %Y %H:%M:%S',        # 08 Apr 2013 05:44:00
    29     ]
    30     ]
    30 
    31 
    31     for known_format in known_formats:
    32     for known_format in known_formats:
    32         try:
    33         try:
    33             return datetime.strptime(s.strip(), known_format)
    34             s = datetime.strptime(s.strip(), known_format)
       
    35             break
    34         except ValueError as e:
    36         except ValueError as e:
    35             pass # Wrong format, keep trying
    37             pass # Wrong format, keep trying
    36     return s
    38     return s
    37 
    39 
    38 
    40 
   110             return WhoisOrg(domain, text)
   112             return WhoisOrg(domain, text)
   111         elif domain.endswith('.name'):
   113         elif domain.endswith('.name'):
   112         	return WhoisName(domain, text)
   114         	return WhoisName(domain, text)
   113         elif domain.endswith('.me'):
   115         elif domain.endswith('.me'):
   114         	return WhoisMe(domain, text)
   116         	return WhoisMe(domain, text)
       
   117         elif domain.endswith('.au'):
       
   118             return WhoisAU(domain, text)
   115         elif domain.endswith('.ru'):
   119         elif domain.endswith('.ru'):
   116             return WhoisRu(domain, text)
   120             return WhoisRu(domain, text)
   117         elif domain.endswith('.us'):
   121         elif domain.endswith('.us'):
   118         	return WhoisUs(domain, text)
   122         	return WhoisUs(domain, text)
   119         elif domain.endswith('.uk'):
   123         elif domain.endswith('.uk'):
   459         if text.strip() == 'No entries found':
   463         if text.strip() == 'No entries found':
   460             raise PywhoisError(text)
   464             raise PywhoisError(text)
   461         else:
   465         else:
   462             WhoisEntry.__init__(self, domain, text, self.regex)
   466             WhoisEntry.__init__(self, domain, text, self.regex)
   463 
   467 
       
   468 
       
   469 class WhoisAU(WhoisEntry):
       
   470    """Whois parser for .au domains
       
   471    """
       
   472    regex = {
       
   473        'domain_name':                    'Domain Name:\s*(.+)\n',
       
   474        'last_modified':			      'Last Modified:\s*(.+)\n',
       
   475        'registrar':                      'Registrar Name:\s*(.+)\n',
       
   476        'status':                         'Status:\s*(.+)',  
       
   477        'registrant_name':                'Registrant:\s*(.+)',
       
   478        'name_servers':                   'Name Server:\s*(.+)',
       
   479    }
       
   480    def __init__(self, domain, text):
       
   481        if text.strip() == 'No Data Found':
       
   482            raise PywhoisError(text)
       
   483        else:
       
   484            WhoisEntry.__init__(self, domain, text, self.regex)
       
   485 
       
   486 
   464 class WhoisBr(WhoisEntry):
   487 class WhoisBr(WhoisEntry):
   465    """Whois parser for .br domains
   488    """Whois parser for .br domains
   466    """
   489    """
   467    regex = {
   490    regex = {
   468        'domain':                        'domain:\s*(.+)\n',
   491        'domain':                        'domain:\s*(.+)\n',