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

Support sending ArrayBuffers #11

Merged
merged 4 commits into from May 28, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion javascript/xhr.py
Expand Up @@ -164,7 +164,12 @@ def go():

def send(self, data=None):
if data is not None:
self._request.data = str(data)
if str(data) == '[object ArrayBuffer]':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break if someone happens to send the string "[object ArrayBuffer]". You want to check for a string type first:

if isinstance(data, basestring):
    self._request.data = str(data)
elif str(data) == '[object ArrayBuffer]':
    # ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I check like this, so that we don't convert twice?

if not isinstance(data, str) and str(data) == '[object ArrayBuffer]':

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but use basestring for your isinstance check.

uint8_array = self._runtime.context.locals.Uint8Array
data_array = uint8_array.create(uint8_array, (data,))
self._request.data = bytes(bytearray(data_array[str(x)] for x in xrange(data_array.length)))
else:
self._request.data =str(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You dropped a space after the = here.

self._thread = self._runtime.group.spawn(self._do_send)
if not self._async:
self._thread.join()
Expand Down