Ejemplo n.º 1
0
 def go():
     if self.readyState != self.OPEN:
         return
     if self.binaryType == "arraybuffer":
         uint8_array = self.runtime.context.locals.Uint8Array
         buffer = uint8_array.create(
             uint8_array, (v8.JSArray(list(bytearray(data))), )).buffer
         self.triggerEvent("message",
                           MessageEvent(self.runtime, self.url, buffer))
Ejemplo n.º 2
0
 def go():
     try:
         token = self._get_timeline_token()
         result = requests.get(self.runtime.runner.urls.app_subscription_list, headers={'X-User-Token': token})
         result.raise_for_status()
         subs = v8.JSArray(result.json()['topics'])
     except (requests.RequestException, TokenException) as e:
         if callable(failure):
             self.runtime.enqueue(failure, str(e))
     except Exception:
         traceback.print_exc()
         if callable(failure):
             self.runtime.enqueue(failure, "Internal failure.")
     else:
         if callable(success):
             self.runtime.enqueue(success, subs)
Ejemplo n.º 3
0
    def _do_send(self):
        self._sent = True
        req = self._session.prepare_request(self._request)
        try:
            if self.timeout:
                timeout = self.timeout / 1000.0
            else:
                timeout = None
            self._response = self._session.send(req,
                                                timeout=timeout,
                                                verify=True)
            self.readyState = self.DONE
            self.status = self._response.status_code
            self.statusText = self._response.reason
            self.responseText = self._response.text

            if self.responseType == "json":
                self.response = self._response.json()
            elif self.responseType == "arraybuffer":
                self.response = v8.JSObject.create(
                    self._runtime.context.locals.Uint8Array, (v8.JSArray(
                        list(bytearray(self._response.content))), )).buffer
            else:
                self.response = self.responseText

            self._trigger_async_event("load", ProgressEvent, (self._runtime, ))
        except requests.exceptions.Timeout:
            self._trigger_async_event("timeout", ProgressEvent,
                                      (self._runtime, ))
            self.readyState = self.DONE
        except requests.exceptions.RequestException as e:
            self.status = 0
            self.statusText = str(e)
            self.readyState = self.DONE
        finally:
            self._trigger_async_event("loadend", ProgressEvent,
                                      (self._runtime, ))
            self._trigger_async_event("readystatechange")
Ejemplo n.º 4
0
    def _handle_message(self, tid, uuid, dictionary):
        if uuid != self.uuid:
            logger.warning("Discarded message for %s (expected %s)", uuid, self.uuid)
            self.pebble._send_message("APPLICATION_MESSAGE", struct.pack('<BB', 0x7F, tid))  # ACK
            return

        app_keys = dict(zip(self.app_keys.values(), self.app_keys.keys()))
        d = self.runtime.context.eval("({})")  # This is kinda absurd.
        for k, v in dictionary.iteritems():
            if isinstance(v, int):
                value = v
            elif isinstance(v, basestring):
                value = v
            elif isinstance(v, bytearray):
                value = v8.JSArray(list(v))
            else:
                raise JSRuntimeException("?????")
            d[str(k)] = value
            if k in app_keys:
                d[str(app_keys[k])] = value
        e = events.Event(self.runtime, "AppMessage")
        e.payload = d
        self.triggerEvent("appmessage", e)
Ejemplo n.º 5
0
 def enumerate(self):
     return v8.JSArray(self.storage.keys())
Ejemplo n.º 6
0
 def keys(self, p):
     return v8.JSArray(self.storage.keys())