Skip to content

Commit

Permalink
encode binary strings, better fix for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
derek73 committed Sep 20, 2015
1 parent 940bd22 commit 08e6a30
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/release_log.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Release Log
===========
* 0.3.10 - September 19, 2015
- Fix encoding of byte strings on python 2.x (#37)
* 0.3.9 - September 5, 2015
- Separate suffixes that are acronyms to handle periods differently, fixes #29, #21
- Don't find titles after first name is filled, fixes (#27)
Expand Down
8 changes: 3 additions & 5 deletions nameparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys
from nameparser.util import u
from nameparser.util import text_types
from nameparser.util import text_types, binary_type
from nameparser.util import lc
from nameparser.util import log
from nameparser.config import CONSTANTS
Expand Down Expand Up @@ -324,6 +324,8 @@ def full_name(self):
def full_name(self, value):
self.original = value
self._full_name = value
if isinstance(value, binary_type):
self._full_name = value.decode(self.ENCODING)
self.parse_full_name()

def collapse_whitespace(self, string):
Expand Down Expand Up @@ -390,10 +392,6 @@ def parse_full_name(self):
self.nickname_list = []
self.unparsable = True

try:
self._full_name = u(self._full_name, self.ENCODING)
except TypeError:
pass

self.pre_process()

Expand Down
6 changes: 3 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ def test_string_output(self):
print(hn)
print(repr(hn))

def test_escaped_u(self):
hn = HumanName('B\xe4ck, Gerald')
def test_escaped_utf8_bytes(self):
hn = HumanName(b'B\xc3\xb6ck, Gerald')
self.m(hn.first, "Gerald", hn)
self.m(hn.last, "B\xe4ck", hn)
self.m(hn.last, "Böck", hn)

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

0 comments on commit 08e6a30

Please sign in to comment.