whois/parser.py
changeset 93 acdc2cb09f60
parent 89 0b2e70f3f537
parent 92 7d3efe9ad172
child 99 67b90bfc59c7
equal deleted inserted replaced
91:4382433c1fe0 93:acdc2cb09f60
   149         super(WhoisEntry, self).__setitem__(name, value)
   149         super(WhoisEntry, self).__setitem__(name, value)
   150 
   150 
   151 
   151 
   152     def __getattr__(self, name):
   152     def __getattr__(self, name):
   153         return self.get(name)
   153         return self.get(name)
   154         
   154 
   155 
   155 
   156     def __str__(self):
   156     def __str__(self):
   157         handler = lambda e: str(e)
   157         handler = lambda e: str(e)
   158         return json.dumps(self, indent=2, default=handler)
   158         return json.dumps(self, indent=2, default=handler)
   159 
   159 
   224             return WhoisIo(domain, text)
   224             return WhoisIo(domain, text)
   225         elif domain.endswith('.biz'):
   225         elif domain.endswith('.biz'):
   226             return WhoisBiz(domain, text)
   226             return WhoisBiz(domain, text)
   227         elif domain.endswith('.mobi'):
   227         elif domain.endswith('.mobi'):
   228             return WhoisMobi(domain, text)
   228             return WhoisMobi(domain, text)
       
   229         elif domain.endswith('.ch'):
       
   230             return WhoisChLi(domain, text)
       
   231         elif domain.endswith('.li'):
       
   232             return WhoisChLi(domain, text)
   229         else:
   233         else:
   230             return WhoisEntry(domain, text)
   234             return WhoisEntry(domain, text)
   231 
   235 
   232 
   236 
   233 class WhoisCom(WhoisEntry):
   237 class WhoisCom(WhoisEntry):
   263         'expiration_date':  'Registry Expiry Date: *(.+)',
   267         'expiration_date':  'Registry Expiry Date: *(.+)',
   264         'name_servers':     'Name Server: *(.+)', # list of name servers
   268         'name_servers':     'Name Server: *(.+)', # list of name servers
   265         'status':           'Status: *(.+)', # list of statuses
   269         'status':           'Status: *(.+)', # list of statuses
   266         'emails':           EMAIL_REGEX, # list of email addresses
   270         'emails':           EMAIL_REGEX, # list of email addresses
   267     }
   271     }
   268     
   272 
   269     def __init__(self, domain, text):
   273     def __init__(self, domain, text):
   270         if text.strip() == 'NOT FOUND':
   274         if text.strip() == 'NOT FOUND':
   271             raise PywhoisError(text)
   275             raise PywhoisError(text)
   272         else:
   276         else:
   273             WhoisEntry.__init__(self, domain, text)
   277             WhoisEntry.__init__(self, domain, text)
   318             self['address'] = lines[1]
   322             self['address'] = lines[1]
   319             if len(lines) == 4:
   323             if len(lines) == 4:
   320                 self['zip_code'], _, self['city'] = lines[2].partition(' ')
   324                 self['zip_code'], _, self['city'] = lines[2].partition(' ')
   321             self['country'] = lines[-1]
   325             self['country'] = lines[-1]
   322 
   326 
   323                 
   327 
   324 
   328 
   325 class WhoisName(WhoisEntry):
   329 class WhoisName(WhoisEntry):
   326     """Whois parser for .name domains
   330     """Whois parser for .name domains
   327     """
   331     """
   328     regex = {
   332     regex = {
   992     def __init__(self, domain, text):
   996     def __init__(self, domain, text):
   993         if 'Data not found. This domain is available for registration' in text:
   997         if 'Data not found. This domain is available for registration' in text:
   994             raise PywhoisError(text)
   998             raise PywhoisError(text)
   995         else:
   999         else:
   996             WhoisEntry.__init__(self, domain, text, self.regex)
  1000             WhoisEntry.__init__(self, domain, text, self.regex)
       
  1001 
       
  1002 
       
  1003 class WhoisChLi(WhoisEntry):
       
  1004     """Whois Parser for .ch and .li domains
       
  1005     """
       
  1006     regex = {
       
  1007         'domain_name':                      '\nDomain name:\n*(.+)',
       
  1008         'registrant':                       'Holder of domain name:\n*([\n\s\S]+)\nContractual Language:',
       
  1009         'registrar':                        'Registrar:\n*(.+)',
       
  1010         'creation_date':                    'First registration date:\n*(.+)',
       
  1011         'dnssec':                           'DNSSEC:*([\S]+)',
       
  1012         'tech-c':                           'Technical contact:\n*([\n\s\S]+)\nRegistrar:',
       
  1013         'name_servers':                     'Name servers:\n *([\n\S\s]+)'
       
  1014     }
       
  1015     def __init__(self,domain,text):
       
  1016         if 'We do not have an entry in our database matching your query.' in text:
       
  1017             raise PywhoisError(text)
       
  1018         else:
       
  1019             WhoisEntry.__init__(self, domain, text, self.regex)