whois/parser.py
changeset 92 7d3efe9ad172
parent 75 81859268375c
child 93 acdc2cb09f60
equal deleted inserted replaced
82:fc40924ac59b 92:7d3efe9ad172
   147         super(WhoisEntry, self).__setitem__(name, value)
   147         super(WhoisEntry, self).__setitem__(name, value)
   148 
   148 
   149 
   149 
   150     def __getattr__(self, name):
   150     def __getattr__(self, name):
   151         return self.get(name)
   151         return self.get(name)
   152         
   152 
   153 
   153 
   154     def __str__(self):
   154     def __str__(self):
   155         handler = lambda e: str(e)
   155         handler = lambda e: str(e)
   156         return json.dumps(self, indent=2, default=handler)
   156         return json.dumps(self, indent=2, default=handler)
   157 
   157 
   220             return WhoisIo(domain, text)
   220             return WhoisIo(domain, text)
   221         elif domain.endswith('.biz'):
   221         elif domain.endswith('.biz'):
   222             return WhoisBiz(domain, text)
   222             return WhoisBiz(domain, text)
   223         elif domain.endswith('.mobi'):
   223         elif domain.endswith('.mobi'):
   224             return WhoisMobi(domain, text)
   224             return WhoisMobi(domain, text)
       
   225         elif domain.endswith('.ch'):
       
   226             return WhoisChLi(domain, text)
       
   227         elif domain.endswith('.li'):
       
   228             return WhoisChLi(domain, text)
   225         else:
   229         else:
   226             return WhoisEntry(domain, text)
   230             return WhoisEntry(domain, text)
   227 
   231 
   228 
   232 
   229 class WhoisCom(WhoisEntry):
   233 class WhoisCom(WhoisEntry):
   259         'expiration_date':  'Registry Expiry Date: *(.+)',
   263         'expiration_date':  'Registry Expiry Date: *(.+)',
   260         'name_servers':     'Name Server: *(.+)', # list of name servers
   264         'name_servers':     'Name Server: *(.+)', # list of name servers
   261         'status':           'Status: *(.+)', # list of statuses
   265         'status':           'Status: *(.+)', # list of statuses
   262         'emails':           EMAIL_REGEX, # list of email addresses
   266         'emails':           EMAIL_REGEX, # list of email addresses
   263     }
   267     }
   264     
   268 
   265     def __init__(self, domain, text):
   269     def __init__(self, domain, text):
   266         if text.strip() == 'NOT FOUND':
   270         if text.strip() == 'NOT FOUND':
   267             raise PywhoisError(text)
   271             raise PywhoisError(text)
   268         else:
   272         else:
   269             WhoisEntry.__init__(self, domain, text)
   273             WhoisEntry.__init__(self, domain, text)
   314             self['address'] = lines[1]
   318             self['address'] = lines[1]
   315             if len(lines) == 4:
   319             if len(lines) == 4:
   316                 self['zip_code'], _, self['city'] = lines[2].partition(' ')
   320                 self['zip_code'], _, self['city'] = lines[2].partition(' ')
   317             self['country'] = lines[-1]
   321             self['country'] = lines[-1]
   318 
   322 
   319                 
   323 
   320 
   324 
   321 class WhoisName(WhoisEntry):
   325 class WhoisName(WhoisEntry):
   322     """Whois parser for .name domains
   326     """Whois parser for .name domains
   323     """
   327     """
   324     regex = {
   328     regex = {
   968     def __init__(self, domain, text):
   972     def __init__(self, domain, text):
   969         if 'Data not found. This domain is available for registration' in text:
   973         if 'Data not found. This domain is available for registration' in text:
   970             raise PywhoisError(text)
   974             raise PywhoisError(text)
   971         else:
   975         else:
   972             WhoisEntry.__init__(self, domain, text, self.regex)
   976             WhoisEntry.__init__(self, domain, text, self.regex)
       
   977 
       
   978 
       
   979 class WhoisChLi(WhoisEntry):
       
   980     """Whois Parser for .ch and .li domains
       
   981     """
       
   982     regex = {
       
   983         'domain_name':                      '\nDomain name:\n*(.+)',
       
   984         'registrant':                       'Holder of domain name:\n*([\n\s\S]+)\nContractual Language:',
       
   985         'registrar':                        'Registrar:\n*(.+)',
       
   986         'creation_date':                    'First registration date:\n*(.+)',
       
   987         'dnssec':                           'DNSSEC:*([\S]+)',
       
   988         'tech-c':                           'Technical contact:\n*([\n\s\S]+)\nRegistrar:',
       
   989         'name_servers':                     'Name servers:\n *([\n\S\s]+)'
       
   990     }
       
   991     def __init__(self,domain,text):
       
   992         if 'We do not have an entry in our database matching your query.' in text:
       
   993             raise PywhoisError(text)
       
   994         else:
       
   995             WhoisEntry.__init__(self, domain, text, self.regex)