Skip to content

Commit 2cee37a

Browse files
committed
Fix unicode format error - .format'ing unicode strings into a ASCII format definition tries to convert the unicode strings to ASCII, throwing an exception for characters not in the ASCII set. Wrapping format strings in u(...) fixes.
1 parent 00e4a88 commit 2cee37a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

summarize/summarize.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def u(s):
2525
"""Ensure our string is unicode independent of Python version, since Python 3 versions < 3.3 do not support the u"..." prefix"""
26-
if _IS_PYTHON_3:
26+
if _IS_PYTHON_3 or type(s) == unicode:
2727
return s
2828
else:
2929
# not well documented but seems to work
@@ -90,10 +90,10 @@ def __init__(self, url, article_html, title, summaries):
9090
self.summaries = summaries
9191

9292
def __repr__(self):
93-
return 'Summary({}, {}, {}, {})'.format(repr(self.url), repr(self.article_html), repr(self.title), repr(self.summaries))
93+
return u('Summary({}, {}, {}, {})').format(repr(self.url), repr(self.article_html), repr(self.title), repr(self.summaries))
9494

9595
def __unicode__(self):
96-
return u('{} - {}\n\n{}'.format(self.title, self.url, '\n'.join(self.summaries)))
96+
return u('{} - {}\n\n{}').format(self.title, self.url, '\n'.join(self.summaries))
9797

9898
def __str__(self):
9999
if _IS_PYTHON_3:

0 commit comments

Comments
 (0)