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

WIP: Flake8 & isort #200

Merged
merged 1 commit into from Jan 21, 2017
Merged

WIP: Flake8 & isort #200

merged 1 commit into from Jan 21, 2017

Conversation

apollo13
Copy link
Contributor

I copied most of the settings from what we have in Django

@apollo13 apollo13 changed the title Flake8 & isort WIP: Flake8 & isort Jan 20, 2017
@@ -32,34 +32,18 @@
THE SOFTWARE.

'''

__author__ = 'Marcel Hellkamp'
Copy link
Contributor

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.

@apollo13
Copy link
Contributor Author

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).

@spaceone
Copy link
Contributor

You ignored some of my comments about the .decode('unicode_escape') changes

@apollo13
Copy link
Contributor Author

@spaceone is that not addressed by ae187e6 ?

@spaceone
Copy link
Contributor

No, circuits.web.http is affected

@spaceone
Copy link
Contributor

And circuits.web.parsers.http

@apollo13
Copy link
Contributor Author

Mhm, not sure I follow -- I've changed circuits.web.parser.http, but I think I've kept the original behavior of bytes_to_str there. The tests seem also okay (aside from changing them to adhere to the behavior change in b()).

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

name not already defined?

Copy link
Contributor Author

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")


Copy link
Contributor

Choose a reason for hiding this comment

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

too much whitespace

Copy link
Contributor Author

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"]
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain

Copy link
Contributor Author

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')
Copy link
Contributor

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"
Copy link
Contributor

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')
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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:

circuits/circuits/six.py

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:

circuits/circuits/six.py

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)

Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer as above

@apollo13 apollo13 merged commit f2798d0 into circuits:master Jan 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants