Skip to content

Commit d2b8697

Browse files
committed
Hotfix unicode processing for Python 3 (fixes chubin#265)
This fix is temprorary, and must be implemented properly, after Python 2 support will be fully dropped.
1 parent 011a077 commit d2b8697

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/fmt/comments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def _beautify(text, filetype, add_comments=False, remove_text=False):
230230
# or remove the text completely. Otherwise the code has to remain aligned
231231
unindent_code = add_comments or remove_text
232232

233-
lines = [x.rstrip('\n') for x in text.splitlines()]
233+
lines = [x.decode("utf-8").rstrip('\n') for x in text.splitlines()]
234234
lines = _cleanup_lines(lines)
235235
lines_classes = zip(_classify_lines(lines), lines)
236236
lines_classes = _wrap_lines(lines_classes, unindent_code=unindent_code)
@@ -292,7 +292,8 @@ def beautify(text, lang, options):
292292
# if mode is unknown, just don't transform the text at all
293293
return text
294294

295-
text = text.encode('utf-8')
295+
if isinstance(text, str):
296+
text = text.encode('utf-8')
296297
digest = "t:%s:%s:%s" % (hashlib.md5(text).hexdigest(), lang, mode)
297298

298299
# temporary added line that removes invalid cache entries

lib/postprocessing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def _join_paragraphs(paragraphs):
4040
def _split_paragraphs(text):
4141
answer = []
4242
paragraph = ""
43+
if isinstance(text, bytes):
44+
text = text.decode("utf-8")
4345
for line in text.splitlines():
4446
if line == "":
4547
answer.append(paragraph)

0 commit comments

Comments
 (0)