mirror of
https://github.com/chubin/cheat.sh.git
synced 2024-11-22 18:17:38 +03:00
Hotfix unicode processing for Python 3 (fixes #265)
This fix is temprorary, and must be implemented properly, after Python 2 support will be fully dropped.
This commit is contained in:
parent
011a077915
commit
d2b8697ea2
@ -230,7 +230,7 @@ def _beautify(text, filetype, add_comments=False, remove_text=False):
|
||||
# or remove the text completely. Otherwise the code has to remain aligned
|
||||
unindent_code = add_comments or remove_text
|
||||
|
||||
lines = [x.rstrip('\n') for x in text.splitlines()]
|
||||
lines = [x.decode("utf-8").rstrip('\n') for x in text.splitlines()]
|
||||
lines = _cleanup_lines(lines)
|
||||
lines_classes = zip(_classify_lines(lines), lines)
|
||||
lines_classes = _wrap_lines(lines_classes, unindent_code=unindent_code)
|
||||
@ -292,6 +292,7 @@ def beautify(text, lang, options):
|
||||
# if mode is unknown, just don't transform the text at all
|
||||
return text
|
||||
|
||||
if isinstance(text, str):
|
||||
text = text.encode('utf-8')
|
||||
digest = "t:%s:%s:%s" % (hashlib.md5(text).hexdigest(), lang, mode)
|
||||
|
||||
|
@ -40,6 +40,8 @@ def _filter_by_keyword(answer, keyword, options):
|
||||
def _split_paragraphs(text):
|
||||
answer = []
|
||||
paragraph = ""
|
||||
if isinstance(text, bytes):
|
||||
text = text.decode("utf-8")
|
||||
for line in text.splitlines():
|
||||
if line == "":
|
||||
answer.append(paragraph)
|
||||
|
Loading…
Reference in New Issue
Block a user