Skip to content

Commit 95a579f

Browse files
committed
handle both text types
1 parent a9ed8d5 commit 95a579f

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

nameparser/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import sys
55
from nameparser.util import u
6-
from nameparser.util import text_type
6+
from nameparser.util import text_types
77
from nameparser.util import lc
88
from nameparser.util import log
99
from nameparser.config import CONSTANTS
@@ -226,7 +226,7 @@ def nickname(self):
226226
def _set_list(self, attr, value):
227227
if isinstance(value, list):
228228
val = value
229-
elif isinstance(value, text_type):
229+
elif isinstance(value, text_types):
230230
val = [value]
231231
else:
232232
raise TypeError("Can only assign strings and lists to name attributes. "
@@ -378,7 +378,7 @@ def parse_full_name(self):
378378
self.nickname_list = []
379379
self.unparsable = True
380380

381-
if not isinstance(self._full_name, text_type):
381+
if not isinstance(self._full_name, text_types):
382382
self._full_name = u(self._full_name, self.ENCODING)
383383

384384
self.pre_process()
@@ -524,7 +524,7 @@ def parse_pieces(self, parts, additional_parts_count=0):
524524

525525
tmp = []
526526
for part in parts:
527-
if not isinstance(part, text_type):
527+
if not isinstance(part, text_types):
528528
raise TypeError("Name parts must be strings. Got {0}".format(type(part)))
529529
tmp += [x.strip(' ,') for x in part.split(' ')]
530530
return self.join_on_conjunctions(tmp, additional_parts_count)

nameparser/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def u(x, encoding=None):
3131
def u(x, encoding=None):
3232
return text_type(x)
3333

34+
text_types = (text_type, binary_type)
3435
def lc(value):
3536
"""Lower case and remove any periods to normalize for comparison."""
3637
if not value:

0 commit comments

Comments
 (0)