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

A minor question with django #8

Open
pythonzm opened this issue Jan 8, 2019 · 1 comment
Open

A minor question with django #8

pythonzm opened this issue Jan 8, 2019 · 1 comment

Comments

@pythonzm
Copy link

pythonzm commented Jan 8, 2019

thanks for your project!

i'm using it with django, and an error occurred while I was running the program:bytes has no attribute encode 。so i changed the code of client.py at line 122.
before:

self.client.sendall(data.encode())

after:

if isinstance(data, bytes): self.client.sendall(data) elif isinstance(data, str): self.client.sendall(data.encode())

and then the program runs well.

i hope this issue will help

@mohabusama
Copy link
Owner

Thanks for the report.

I kind of wanted to keep the interface streamlined for send() and receive() to be handling strings. The conversion can be done from the caller (i.e. convert the data to str before calling client.send()) which adds a little bit of overhead of course.

The other solution would be for send to accept bytes and str. I have done a quick benchmarking on the overhead incurred on each instruction (assuming the baseline is passing data: str):

def send(data):
    return data.encode()

def send_cond(data):
    if isinstance(data, str):
        return data.encode()
    return data

assuming we are passing data: str

... timeit setup removed for brevity ...
>>> send.timeit()
>>> 0.2808417819906026

>>> send_cond.timeit()
>>> 0.540613093005959

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

No branches or pull requests

2 participants