# HG changeset patch # User Richard Penman # Date 1464901186 25200 # Node ID acdc2cb09f6001c32789a629a856fef1ef16d6c8 # Parent 4382433c1fe0a5aac4363373cd0ec3b0612155cb# Parent 7d3efe9ad17243b65865d8bec0b7fab96db8724c Merged in rothi83/pywhois (pull request #6) Extended parser.py to parse .ch and .li domains diff -r 4382433c1fe0 -r acdc2cb09f60 whois/parser.py --- a/whois/parser.py Thu Jun 02 13:58:54 2016 -0700 +++ b/whois/parser.py Thu Jun 02 13:59:46 2016 -0700 @@ -151,7 +151,7 @@ def __getattr__(self, name): return self.get(name) - + def __str__(self): handler = lambda e: str(e) @@ -226,6 +226,10 @@ return WhoisBiz(domain, text) elif domain.endswith('.mobi'): return WhoisMobi(domain, text) + elif domain.endswith('.ch'): + return WhoisChLi(domain, text) + elif domain.endswith('.li'): + return WhoisChLi(domain, text) else: return WhoisEntry(domain, text) @@ -265,7 +269,7 @@ 'status': 'Status: *(.+)', # list of statuses 'emails': EMAIL_REGEX, # list of email addresses } - + def __init__(self, domain, text): if text.strip() == 'NOT FOUND': raise PywhoisError(text) @@ -320,7 +324,7 @@ self['zip_code'], _, self['city'] = lines[2].partition(' ') self['country'] = lines[-1] - + class WhoisName(WhoisEntry): """Whois parser for .name domains @@ -994,3 +998,22 @@ raise PywhoisError(text) else: WhoisEntry.__init__(self, domain, text, self.regex) + + +class WhoisChLi(WhoisEntry): + """Whois Parser for .ch and .li domains + """ + regex = { + 'domain_name': '\nDomain name:\n*(.+)', + 'registrant': 'Holder of domain name:\n*([\n\s\S]+)\nContractual Language:', + 'registrar': 'Registrar:\n*(.+)', + 'creation_date': 'First registration date:\n*(.+)', + 'dnssec': 'DNSSEC:*([\S]+)', + 'tech-c': 'Technical contact:\n*([\n\s\S]+)\nRegistrar:', + 'name_servers': 'Name servers:\n *([\n\S\s]+)' + } + def __init__(self,domain,text): + if 'We do not have an entry in our database matching your query.' in text: + raise PywhoisError(text) + else: + WhoisEntry.__init__(self, domain, text, self.regex)