-
Notifications
You must be signed in to change notification settings - Fork 20
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
handle edge case were too many bytes are supplied #80
base: master
Are you sure you want to change the base?
Conversation
@@ -20,9 +20,6 @@ | |||
class FrameParser(Parser): | |||
"""Parses a stream of data in to HTTP headers + WS frames.""" | |||
|
|||
unpack16 = struct.Struct(b"!H").unpack |
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 was the source of the strange traceback. On Python 2.7.3 struct.unpack failed with anything that wasn't a bytes object. On later versions, it would accept any object with the buffer protocol, i.e. bytearray.
@@ -18,8 +18,13 @@ class ParseEOF(ParseError): | |||
"""End of Stream.""" | |||
|
|||
|
|||
class ParseOverflow(Exception): |
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 new exception is thrown if data is supplied in feed
when the parser has finished. This wasn't ever occurring, but at least its implemented now. It could catch issues in the future.
@@ -71,6 +71,13 @@ def feed(self, data): | |||
raise errors.CriticalProtocolError( | |||
text_type(error) | |||
) | |||
except errors.WebSocketError: | |||
raise | |||
except Exception as error: |
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 is mere paranoia.
@@ -39,6 +36,17 @@ def __repr__(self): | |||
self.validate | |||
) | |||
|
|||
# A bug in Python2.7.3 requires casting data to bytes | |||
@classmethod | |||
def unpack16(cls, data, _unpack16 = struct.Struct(b"!H").unpack): |
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.
The _unpack16
is in the params so that it is a local, which is faster.
while not isinstance(self._awaiting, _Awaitable): | ||
yield self._awaiting | ||
self._awaiting = next(self._gen) | ||
self._gen.throw(ParseEOF("unexpected eof of file")) |
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 function is too weighty. As some point I will break it up a little. It's on my list.
What this PR solves
Review