-
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
Implement response handlers #54
Conversation
Codecov Report
@@ Coverage Diff @@
## main #54 +/- ##
===========================================
+ Coverage 99.43% 100.00% +0.56%
===========================================
Files 51 55 +4
Lines 1405 1462 +57
===========================================
+ Hits 1397 1462 +65
+ Misses 8 0 -8
|
2deaf29
to
89816b7
Compare
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
@@ -30,6 +30,7 @@ jobs: | |||
poetry install | |||
protoc -I=$PROTOBUF_SRC_DIR --python_out=$PROTOBUF_SRC_DIR $PROTOBUF_SRC_DIR/*.proto | |||
2to3 --no-diff -n -w $PROTOBUF_SRC_DIR | |||
find $PROTOBUF_SRC_DIR -type f -name "*_pb2.py" | xargs sed -i.bak -E 's/(USE_C_DESCRIPTORS == False:)/\1 # pragma: no cover/g' |
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 works. A more generic way of doing it would be to generate a .patch
with git diff
and apply it. That helps catch the moment when this find
+ sed
stop doing something useful.
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.
We could also just remove these 3 lines altogether since we've committed the generated (and properly fixed up) files, possibly adding a note in the developer guide what to do if editing or adding new .proto
files.
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 captured this in #23 (comment).
raw_out = output.getvalue() | ||
logging.info(f"> {message.__str__()}, size={len(raw_out)} byte(s)") | ||
logging.info(f"> {self.response.__str__()}, size={len(raw_out)} byte(s)") |
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.
Shouldn't need __str__()
here, I think it's implied by {self.response}
, or maybe use str(self.response)
.
response.write_to(output) | ||
logging.info(f"> {response}") | ||
logging.info(f"< response {response}") | ||
if response.request_id in self.response_handlers: |
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.
Could probably move this into self.response_handlers.handle
, it would just return None
if unhandled.
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 wanted to keep the implementation similar to the request handling above it. I agree we could move both into the handlers.
* Implement resopnse handlers Signed-off-by: Daniel Widdis <widdis@gmail.com> * Add missing test which uncovered missing return statement Signed-off-by: Daniel Widdis <widdis@gmail.com> * Ignore unreachable protobuf code branch Signed-off-by: Daniel Widdis <widdis@gmail.com> * Fix event loop deprecation warning Signed-off-by: Daniel Widdis <widdis@gmail.com> --------- Signed-off-by: Daniel Widdis <widdis@gmail.com> Signed-off-by: Jatin <jatin.kshatriya2821@gmail.com>
Description
Implements a response handling mechanism
handle
andsend
methods on the request handler, to permit sending a stored response at a later timeresponse
variable on the superclass andsend()
now takes no argumentssend
andhandle
will happen in reverse orderOther misc. changes:
Issues Resolved
Fixes #31 (or at least most of the requests; separating the ability to "send" from requiring responses to go to the event loop would increase flexibility)
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.