pyguacamole icon indicating copy to clipboard operation
pyguacamole copied to clipboard

A minor question with django

Open pythonzm opened this issue 5 years ago • 1 comments

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

pythonzm avatar Jan 08 '19 09:01 pythonzm

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

mohabusama avatar Jan 08 '19 21:01 mohabusama