1- # -*- coding: utf-8 -*-
2- from __future__ import unicode_literals
3-
4- import sys
51import re
62from operator import itemgetter
73from itertools import groupby
84
9- from nameparser .util import u
10- from nameparser .util import text_types , binary_type
115from nameparser .util import lc
126from nameparser .util import log
137from nameparser .config import CONSTANTS
@@ -123,10 +117,10 @@ def __eq__(self, other):
123117 HumanName instances are equal to other objects whose
124118 lower case unicode representation is the same.
125119 """
126- return ( u ( self )) .lower () == ( u ( other ) ).lower ()
120+ return str ( self ).lower () == str ( other ).lower ()
127121
128122 def __ne__ (self , other ):
129- return not ( u ( self )) .lower () == ( u ( other ) ).lower ()
123+ return not str ( self ).lower () == str ( other ).lower ()
130124
131125 def __getitem__ (self , key ):
132126 if isinstance (key , slice ):
@@ -140,9 +134,6 @@ def __setitem__(self, key, value):
140134 else :
141135 raise KeyError ("Not a valid HumanName attribute" , key )
142136
143- def next (self ):
144- return self .__next__ ()
145-
146137 def __next__ (self ):
147138 if self ._count >= len (self ._members ):
148139 self ._count = 0
@@ -152,7 +143,7 @@ def __next__(self):
152143 self ._count = c + 1
153144 return getattr (self , self ._members [c ]) or next (self )
154145
155- def __unicode__ (self ):
146+ def __str__ (self ):
156147 if self .string_format :
157148 # string_format = "{title} {first} {middle} {last} {suffix} ({nickname})"
158149 _s = self .string_format .format (** self .as_dict ())
@@ -164,11 +155,6 @@ def __unicode__(self):
164155 def __hash__ (self ):
165156 return hash (str (self ))
166157
167- def __str__ (self ):
168- if sys .version_info [0 ] >= 3 :
169- return self .__unicode__ ()
170- return self .__unicode__ ().encode (self .encoding )
171-
172158 def __repr__ (self ):
173159 if self .unparsable :
174160 _string = "<%(class)s : [ Unparsable ] >" % {'class' : self .__class__ .__name__ , }
@@ -182,9 +168,7 @@ def __repr__(self):
182168 'suffix' : self .suffix or '' ,
183169 'nickname' : self .nickname or '' ,
184170 }
185- if sys .version_info [0 ] >= 3 :
186- return _string
187- return _string .encode (self .encoding )
171+ return _string
188172
189173 def as_dict (self , include_empty = True ):
190174 """
@@ -361,7 +345,7 @@ def surnames(self):
361345 def _set_list (self , attr , value ):
362346 if isinstance (value , list ):
363347 val = value
364- elif isinstance (value , text_types ):
348+ elif isinstance (value , ( str , bytes ) ):
365349 val = [value ]
366350 elif value is None :
367351 val = []
@@ -481,7 +465,7 @@ def full_name(self):
481465 def full_name (self , value ):
482466 self .original = value
483467 self ._full_name = value
484- if isinstance (value , binary_type ):
468+ if isinstance (value , bytes ):
485469 self ._full_name = value .decode (self .encoding )
486470 self .parse_full_name ()
487471
@@ -657,7 +641,7 @@ def parse_full_name(self):
657641
658642 self .suffix_list += parts [1 :]
659643 pieces = self .parse_pieces (parts [0 ].split (' ' ))
660- log .debug ("pieces: %s" , u (pieces ))
644+ log .debug ("pieces: %s" , str (pieces ))
661645 for i , piece in enumerate (pieces ):
662646 try :
663647 nxt = pieces [i + 1 ]
@@ -686,7 +670,7 @@ def parse_full_name(self):
686670 # last [suffix], title first middles[,] suffix [,suffix]
687671 # parts[0], parts[1], parts[2:...]
688672
689- log .debug ("post-comma pieces: %s" , u (post_comma_pieces ))
673+ log .debug ("post-comma pieces: %s" , str (post_comma_pieces ))
690674
691675 # lastname part may have suffixes in it
692676 lastname_pieces = self .parse_pieces (parts [0 ].split (' ' ), 1 )
@@ -747,7 +731,7 @@ def parse_pieces(self, parts, additional_parts_count=0):
747731
748732 output = []
749733 for part in parts :
750- if not isinstance (part , text_types ):
734+ if not isinstance (part , ( str , bytes ) ):
751735 raise TypeError ("Name parts must be strings. "
752736 "Got {0}" .format (type (part )))
753737 output += [x .strip (' ,' ) for x in part .split (' ' )]
@@ -981,7 +965,7 @@ def capitalize(self, force=None):
981965 'Shirley MacLaine'
982966
983967 """
984- name = u (self )
968+ name = str (self )
985969 force = self .C .force_mixed_case_capitalization \
986970 if force is None else force
987971
0 commit comments