commit 2cb052d072d9a14d82ac6a8806213fcb69e06c61
Author: Vitezslav Humpa <vhumpa@redhat.com>
Date: Tue Sep 20 17:18:09 2016 +0200
Fix several python2 unicode issues + python3 unicode() function compat
--- a/behave/formatter/html.py
+++ b/behave/formatter/html.py
@@ -33,6 +33,7 @@ from behave.compat.collections import Co
import xml.etree.ElementTree as ET
import base64
# XXX-JE-NOT-USED: import os.path
+import six
def _valid_XML_char_ordinal(i):
@@ -334,7 +335,9 @@ class HTMLFormatter(Formatter):
for argument in self.arguments:
step_part = ET.SubElement(step_text, 'span')
step_part.text = result.name[text_start:argument.start]
- ET.SubElement(step_text, 'b').text = str(argument.value)
+ if isinstance(argument.value, six.integer_types):
+ argument.value = str(argument.value)
+ ET.SubElement(step_text, 'b').text = argument.value
text_start = argument.end
step_part = ET.SubElement(step_text, 'span')
step_part.text = result.name[self.arguments[-1].end:]
@@ -403,7 +406,7 @@ class HTMLFormatter(Formatter):
if 'video/' in mime_type:
if not caption:
caption = u'Video'
- link.text = unicode(caption)
+ link.text = six.u(caption)
embed = ET.SubElement(span, 'video',
{'id': 'embed_%s' % self.embed_id,
@@ -418,7 +421,7 @@ class HTMLFormatter(Formatter):
if 'image/' in mime_type:
if not caption:
caption = u'Screenshot'
- link.text = unicode(caption)
+ link.text = six.u(caption)
embed = ET.SubElement(span, 'img', {
'id': 'embed_%s' % self.embed_id,
@@ -430,7 +433,7 @@ class HTMLFormatter(Formatter):
if 'text/' in mime_type:
if not caption:
caption = u'Data'
- link.text = unicode(caption)
+ link.text = six.u(caption)
cleaned_data = ''.join(
c for c in data if _valid_XML_char_ordinal(ord(c))
@@ -439,7 +442,7 @@ class HTMLFormatter(Formatter):
embed = ET.SubElement(span, 'pre',
{'id': "embed_%s" % self.embed_id,
'style': 'display: none'})
- embed.text = cleaned_data
+ embed.text = six.u(cleaned_data)
embed.tail = u' '
def embedding(self, mime_type, data, caption=None):