Skip to content

Commit 08e6a30

Browse files
committed
encode binary strings, better fix for #37
1 parent 940bd22 commit 08e6a30

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docs/release_log.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Release Log
22
===========
3+
* 0.3.10 - September 19, 2015
4+
- Fix encoding of byte strings on python 2.x (#37)
35
* 0.3.9 - September 5, 2015
46
- Separate suffixes that are acronyms to handle periods differently, fixes #29, #21
57
- Don't find titles after first name is filled, fixes (#27)

nameparser/parser.py

Lines changed: 3 additions & 5 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_types
6+
from nameparser.util import text_types, binary_type
77
from nameparser.util import lc
88
from nameparser.util import log
99
from nameparser.config import CONSTANTS
@@ -324,6 +324,8 @@ def full_name(self):
324324
def full_name(self, value):
325325
self.original = value
326326
self._full_name = value
327+
if isinstance(value, binary_type):
328+
self._full_name = value.decode(self.ENCODING)
327329
self.parse_full_name()
328330

329331
def collapse_whitespace(self, string):
@@ -390,10 +392,6 @@ def parse_full_name(self):
390392
self.nickname_list = []
391393
self.unparsable = True
392394

393-
try:
394-
self._full_name = u(self._full_name, self.ENCODING)
395-
except TypeError:
396-
pass
397395

398396
self.pre_process()
399397

tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ def test_string_output(self):
6262
print(hn)
6363
print(repr(hn))
6464

65-
def test_escaped_u(self):
66-
hn = HumanName('B\xe4ck, Gerald')
65+
def test_escaped_utf8_bytes(self):
66+
hn = HumanName(b'B\xc3\xb6ck, Gerald')
6767
self.m(hn.first, "Gerald", hn)
68-
self.m(hn.last, "B\xe4ck", hn)
68+
self.m(hn.last, "Böck", hn)
6969

7070
def test_len(self):
7171
hn = HumanName("Doe-Ray, Dr. John P., CLU, CFP, LUTC")

0 commit comments

Comments
 (0)