From 018f621a96f792776801ebb376224b32602a6959 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Thu, 23 Feb 2017 18:06:36 -0800 Subject: [PATCH 1/2] Fix python 2 / 3 version check for basestring sys.version_info[1] checks the minor version, so on python 2.7 string_type is set to `str` instead of `basestring`. This causes unicode strings to fail when bernhard attempts to convert them to str via string_type at line 158. --- bernhard/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bernhard/__init__.py b/bernhard/__init__.py index f3d238b..faddab7 100644 --- a/bernhard/__init__.py +++ b/bernhard/__init__.py @@ -11,7 +11,7 @@ from . import pb string_type = str -if sys.version_info[1] < 3: +if sys.version_info.major < 3: string_type = basestring class TransportError(Exception): From 704b9b745d48396660c6c738d8ae2ba91731b326 Mon Sep 17 00:00:00 2001 From: Dana Powers Date: Fri, 24 Feb 2017 11:58:43 -0800 Subject: [PATCH 2/2] Encode non-string-type attributes with str; drop unneeded double encode. --- bernhard/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bernhard/__init__.py b/bernhard/__init__.py index faddab7..bffd023 100644 --- a/bernhard/__init__.py +++ b/bernhard/__init__.py @@ -155,8 +155,8 @@ def __setattr__(self, name, value): if isinstance(val, bytes): val = val.decode('utf-8') elif not isinstance(val, string_type): - val = string_type(val) - a.value = string_type(val) + val = str(val) + a.value = val else: raise TypeError("'attributes' parameter must be type 'dict'") elif name in set(f.name for f in pb.Event.DESCRIPTOR.fields):