-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 #976: Add support for websocket send_json and receive_json #984
Conversation
@@ -154,6 +154,13 @@ def send_bytes(self, data): | |||
type(data)) | |||
self._writer.send(data, binary=True) | |||
|
|||
def send_json(self, data, *, dumps=json.dumps): |
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 call .send_str()
instead of working on low level.
Would you add tests also? |
Yes I will |
@asvetlov what I can do to avoid
I am using Also, do you have some suggestions for the tests I wrote? |
@@ -154,6 +154,13 @@ def send_bytes(self, data): | |||
type(data)) | |||
self._writer.send(data, binary=True) | |||
|
|||
def send_json(self, data, *, dumps=json.dumps): | |||
if self._writer is None: |
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.
These checks are not required: .send_str()
performs them anyway.
There is no need to do the check twice.
@asvetlov I've noticed that in |
I think yes. |
@asvetlov I have added all the methods discussed above, now we have:
both on |
Thanks! |
What do these changes do?
Add support for websocket server to send json and for websocket client to send and receive json
Are there changes in behavior for the user?
User can use methods:
send_json
andreceive_json
both on websocket server and clientRelated issue number
#976
Checklist