def test_read_write(manager, watcher, tmpdir): filename = str(tmpdir.ensure("helloworld.txt")) app = FileApp(filename, "w").register(manager) assert watcher.wait("opened", app.file.channel) app.fire(write(b"Hello World!"), app.file.channel) assert watcher.wait("write", app.file.channel) app.fire(close(), app.file.channel) assert watcher.wait("closed", app.file.channel) assert app.closed app.unregister() assert watcher.wait("unregistered") app = FileApp(filename, "r").register(manager) assert watcher.wait("opened", app.file.channel) assert watcher.wait("eof", app.file.channel) assert app.eof app.fire(close(), app.file.channel) assert watcher.wait("closed", app.file.channel) assert app.closed app.unregister() assert watcher.wait("unregistered") s = app.buffer.getvalue() assert s == b"Hello World!"
def _send_template(self, template_name, data, to=(SSDP_ADDR, SSDP_PORT)): template = self._get_template(template_name) message = template % data headers = "" for line in message.splitlines(): headers = headers + line + "\r\n" headers += "\r\n" self.fireEvent(write(to, headers))
def on_read(self, data): """Read Event Handler This is fired by the underlying Serial Component when there has been new data read from the serial port. """ self.fire(write(data))
def log(self, message): timestamp = strftime("[%H:%M:%S]", localtime(time())) self.fire( write( u"{0:s} {1:s}\n".format( timestamp, message ).encode("utf-8") ), self.channel )
def _sendcommand(self, command): if not self._serialopen: self.log("Cannot transmit, serial port not available!", lvl=warn) return cmd = command + self.terminator # cmdbytes = bytes(cmd, encoding="ascii") self.log("Transmitting bytes: ", "\n", cmd, lvl=critical) self.fireEvent(write(cmd), "port")
def _send_command(self, command): if not self._serial_open: self.log("Cannot transmit, serial port not available!", lvl=warn) return cmd = command + self.terminator # cmdbytes = bytes(cmd, encoding="ascii") self.log("Transmitting bytes: ", "\n", cmd, lvl=critical) self.fireEvent(write(cmd), "port")
def _on_portal_update(self, portlet, session, name, *args): if portlet is None: handle = "portal" else: handle = portlet.description().handle data = [ handle, name ] for arg in args: data.append(arg) msg = json.dumps(data) self.fire(write(self.client_connection(session), msg), \ self._event_exchange_channel)
def _send_command(self, command): if not self._serial_open: self.log("Cannot transmit, serial port not available!", lvl=warn) return if not isinstance(command, bytes): command = bytes(command, encoding='ascii') if not self.maestro: cmd = command + self.terminator else: cmd = command # cmdbytes = bytes(cmd, encoding="ascii") self.log("Transmitting bytes: ", "\n", cmd, lvl=critical) if len(cmd) != 3: self.log('Illegal command:', cmd, lvl=critical) return self.fireEvent(write(cmd), "port")
def keepalive(self): self.fire(write(b"\x00"))
def log(self, message): timestamp = strftime("[%H:%M:%S]", localtime(time())) self.fire( write(u"{0:s} {1:s}\n".format(timestamp, message).encode("utf-8")), self.channel)
def _sendcommand(self, command): cmd = command + self.terminator # cmdbytes = bytes(cmd, encoding="ascii") hfoslog("[MR] Transmitting bytes: ", "\n", cmd, lvl=critical) self.fireEvent(write(cmd), "port")