support multiple matches in regex
authorRichard Penman
Fri, 20 Jan 2017 15:25:04 +0800
changeset 121 ccd653a54263
parent 120 b4273400685e
child 122 95feee1af1da
support multiple matches in regex
setup.py
whois/parser.py
--- a/setup.py	Tue Jan 10 09:33:41 2017 +0800
+++ b/setup.py	Fri Jan 20 15:25:04 2017 +0800
@@ -1,7 +1,7 @@
 import sys, os
 import setuptools
 
-version = '0.6.3'
+version = '0.6.5'
 
 setuptools.setup(
     name='python-whois',
--- a/whois/parser.py	Tue Jan 10 09:33:41 2017 +0800
+++ b/whois/parser.py	Fri Jan 20 15:25:04 2017 +0800
@@ -125,17 +125,19 @@
         for attr, regex in list(self._regex.items()):
             if regex:
                 values = []
-                for value in re.findall(regex, self.text, re.IGNORECASE):
-                    value = value.strip()
-                    if value and isinstance(value, basestring) and not value.isdigit() and '_date' in attr:
-                        # try casting to date format
-                        value = cast_date(
-                            value,
-                            dayfirst=self.dayfirst,
-                            yearfirst=self.yearfirst)
-                    if value and value not in values:
-                        # avoid duplicates
-                        values.append(value)
+                for data in re.findall(regex, self.text, re.IGNORECASE):
+                    matches = data if isinstance(data, tuple) else [data]
+                    for value in matches:
+                        value = value.strip()
+                        if value and isinstance(value, basestring) and not value.isdigit() and '_date' in attr:
+                            # try casting to date format
+                            value = cast_date(
+                                value,
+                                dayfirst=self.dayfirst,
+                                yearfirst=self.yearfirst)
+                        if value and value not in values:
+                            # avoid duplicates
+                            values.append(value)
                 if values and attr in ('registrar', 'whois_server', 'referral_url'):
                     values = values[-1] # ignore junk
                 if len(values) == 1: