Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix utf8 encoding on py2 #1575

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions py3status/py3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import unicode_literals

import collections
import os
Expand Down Expand Up @@ -317,7 +319,7 @@ def flatten_dict(self, d, delimiter="-", intermediates=False, parent_key=None):
d = dict(enumerate(d))
for k, v in d.items():
if parent_key:
k = u"{}{}{}".format(parent_key, delimiter, k)
k = "{}{}{}".format(parent_key, delimiter, k)
if intermediates:
items.append((k, v))
if isinstance(v, list):
Expand Down Expand Up @@ -480,6 +482,7 @@ def log(self, message, level=LOG_INFO):
message = "\n" + message
except: # noqa e722
pass
message = message.decode('utf-8')
Copy link
Author

@apiraino apiraino Nov 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should do. Feel free to refactor something else in another PR and close this one if not deemed suitable in some aspects 👍

message = "Module `{}`: {}".format(self._module.module_full_name, message)
self._py3_wrapper.log(message, level)

Expand Down Expand Up @@ -834,7 +837,7 @@ def safe_format(
attr_getter=attr_getter,
)
except Exception:
self._report_exception(u"Invalid format `{}`".format(format_string))
self._report_exception("Invalid format `{}`".format(format_string))
return "invalid format"

def build_composite(
Expand Down Expand Up @@ -870,7 +873,7 @@ def build_composite(
attr_getter=attr_getter,
)
except Exception:
self._report_exception(u"Invalid format `{}`".format(format_string))
self._report_exception("Invalid format `{}`".format(format_string))
return [{"full_text": "invalid format"}]

def composite_update(self, item, update_dict, soft=False):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_py3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

from pprint import pformat

from py3status.py3 import Py3
Expand Down