Skip to content

Commit ae77a0e

Browse files
committed
Clean up
1 parent c1b8417 commit ae77a0e

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

‎language_check/main.py‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def get_text(filename, encoding, ignore):
6565
return text
6666

6767

68-
def encode(text):
69-
"""Return UTF-8 encoded byte string."""
70-
if sys.version_info[0] >= 3:
71-
return text
72-
else:
73-
return text.encode('utf-8')
68+
def print_unicode(text):
69+
"""Print in a portable manner."""
70+
if sys.version_info[0] < 3:
71+
text = text.encode('utf-8')
72+
73+
print(text)
7474

7575

7676
def main():
@@ -127,9 +127,9 @@ def main():
127127

128128
try:
129129
if args.api:
130-
print(lang_tool._check_api(text).decode())
130+
print_unicode(lang_tool._check_api(text).decode())
131131
elif args.apply:
132-
print(lang_tool.correct(text))
132+
print_unicode(lang_tool.correct(text))
133133
else:
134134
for match in lang_tool.check(text):
135135
rule_id = match.ruleId
@@ -147,13 +147,13 @@ def main():
147147
if replacement_text and not message.endswith(('.', '?')):
148148
message += '; suggestions: ' + replacement_text
149149

150-
print(encode(
151-
'{}:{}:{}: {}: {}'.format(
152-
filename,
153-
match.fromy + 1,
154-
match.fromx + 1,
155-
rule_id,
156-
message)))
150+
print_unicode('{}:{}:{}: {}: {}'.format(
151+
filename,
152+
match.fromy + 1,
153+
match.fromx + 1,
154+
rule_id,
155+
message))
156+
157157
status = 2
158158
except Error as exception:
159159
print('{}: {}'.format(filename, exception), file=sys.stderr)

0 commit comments

Comments
 (0)