-
-
Notifications
You must be signed in to change notification settings - Fork 7
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 code for Python3 #11
base: main
Are you sure you want to change the base?
Changes from all commits
e494b25
8d040f8
5e603e5
c58b614
c3eb18f
86f754c
79d20a6
1bb97e3
0bf9c28
35017cd
7876e3a
ed05583
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,20 +30,23 @@ def log(self, msg, level): | |
if self.encoding is not None: | ||
if isinstance(complete_msg, unicodestr): | ||
complete_msg = complete_msg.encode(self.encoding) | ||
else: | ||
if not isinstance(complete_msg, unicodestr): | ||
complete_msg = complete_msg.decode("utf-8") | ||
|
||
self.stream.write(complete_msg) | ||
self.stream.flush() | ||
|
||
|
||
class StdoutLogger(StreamLogger): | ||
|
||
def __init__(self, bus, level=None, format=None, encoding='utf-8'): | ||
def __init__(self, bus, level=None, format=None, encoding=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this is related to the problem in question. Could you drop changing the defaults too? It is a behavior change at best (and a public interface change at worst. This does not seem to be fixing bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the default change is actually the fix, otherwise you would have to explicitly pass See
VS
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a bytes vs unicode py2/3 issue. It's usually better to always have this normalized internally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't personally consider this a string encoding/decoding issue. The problem is related to the fact that In PY2 I think that it was mostly an hack the fact that magicbus allowed you to send bytes to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. Honestly, it'd be great to integrate stdlib |
||
StreamLogger.__init__(self, bus, sys.stdout, level, format, encoding) | ||
|
||
|
||
class StderrLogger(StreamLogger): | ||
|
||
def __init__(self, bus, level=None, format=None, encoding='utf-8'): | ||
def __init__(self, bus, level=None, format=None, encoding=None): | ||
StreamLogger.__init__(self, bus, sys.stderr, level, format, encoding) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if in this case we might want to add
errors="backslashreplace"
given that we are mostly guessingutf-8
might be a good choice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PPS: This can probably just become
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misread the two
if
branches o_OYou are
encoding
in one anddecoding
in the other, my suggestion of squashing the two branches was totally wrong :DThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, you're right. I haven't noticed that too :) I have reverted the changes. I think it's fine now.