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
WIP: Flake8 & isort #200
WIP: Flake8 & isort #200
Conversation
@@ -32,34 +32,18 @@ | |||
THE SOFTWARE. | |||
|
|||
''' | |||
|
|||
__author__ = 'Marcel Hellkamp' |
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.
Hm, this is just a package from upstream.
edf3757
to
57ba96d
Compare
So, the testsuite passes and I think I've addressed all comments by @spaceone -- any objections to merging that? (Integrating web.url as dependency is imo out of scope for this issue). |
You ignored some of my comments about the .decode('unicode_escape') changes |
No, circuits.web.http is affected |
And circuits.web.parsers.http |
Mhm, not sure I follow -- I've changed Please tell me what I am missing |
@@ -57,7 +59,7 @@ def __init__(self, channel=channel): | |||
def _create_control_con(self): | |||
if platform.system() == "Linux": | |||
return os.pipe() | |||
server = create_socket(AF_INET, SOCK_STREAM) | |||
server = socket(AF_INET, SOCK_STREAM) |
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.
name not already defined?
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.
Nope, no idea why the socket
class was aliased to create_socket
:D
if pytest.PLATFORM == "win32": | ||
pytest.skip("Unsupported Platform") | ||
|
||
|
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.
too much whitespace
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.
Fixed, that said there is plenty of "too much whitespace" still around, but I am not going to fix all of those manually for this PR
@@ -13,7 +13,7 @@ | |||
def load_event(s): | |||
data = json.loads(s) | |||
|
|||
name = bytes_to_str(data["name"].encode("utf-8")) | |||
name = data["name"] |
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.
please explain
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.
So the current code is: https://github.com/circuits/circuits/pull/200/files#diff-015e99aa1b430ebfaa9aa46322a22df0R16 -- I think that fixes it
Essentially the idea is:
- On Py3 classnames are unicode/text which is what json returns, so there is nothing to do
- On Py2 classnames need to be bytes so we encode via utf-8
try: | ||
unicode | ||
except NameError: | ||
unicode = str |
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.
please explain
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.
unicode
was not used anywhere in this file and I do not think it was added as "utility" for other modules.
@@ -184,7 +177,7 @@ def execute(self, data, length): | |||
else: | |||
self.__on_firstline = True | |||
self._buf.append(data[:idx]) | |||
first_line = bytes_to_str(b("").join(self._buf)) | |||
first_line = (b("").join(self._buf)).decode('unicode_escape') |
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.
this changes the content. please explain
@@ -310,7 +303,7 @@ def _parse_headers(self, data): | |||
return False | |||
|
|||
# Split lines on \r\n keeping the \r\n on each line | |||
lines = [bytes_to_str(line) + "\r\n" | |||
lines = [line.decode('unicode_escape') + "\r\n" |
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.
same here
first_line = bytes_to_str(b("").join(self._buf)) | ||
first_line = b("").join(self._buf) | ||
if PY3: | ||
first_line = str(first_line, 'unicode_escape') |
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.
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.
Okay, this takes a little bit -- lets step back:
What did bytes_to_str(b("").join(self._buf))
originally do:
On py2 bytes_to_str
is a no-op:
Lines 299 to 300 in 5797ea3
def bytes_to_str(s): | |
return s |
hence leaving it out is okay for python 2.
On Py3 it did decode the bytes using unicode_escape
:
Lines 281 to 282 in 5797ea3
def bytes_to_str(b): | |
return str(b, "unicode_escape") |
which my
if PY3
should do.
(bytes_to_str
is no longer part [or rather was never] of six, hence I removed it when updating six to upstream)
Arguably the code is broken (I am not sure that unicode_escape is the way to go here), but it is the same brokenness as before (or same correctness for that matter)
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.
Alright. Then it is wrong on python3.
@@ -313,7 +305,7 @@ def _parse_headers(self, data): | |||
return False | |||
|
|||
# Split lines on \r\n keeping the \r\n on each line | |||
lines = [bytes_to_str(line) + "\r\n" | |||
lines = [(str(line, 'unicode_escape') if PY3 else line) + "\r\n" |
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.
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.
Same answer as above
ae187e6
to
6240eba
Compare
I copied most of the settings from what we have in Django