コード例 #1
0
ファイル: test_file.py プロジェクト: ke4roh/circuits
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!"
コード例 #2
0
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!"
コード例 #3
0
 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))
コード例 #4
0
ファイル: echoserial.py プロジェクト: totalgood/circuits
    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))
コード例 #5
0
ファイル: echoserial.py プロジェクト: AdricEpic/circuits
    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))
コード例 #6
0
ファイル: ssdp.py プロジェクト: mnlipp/CoCy
 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))
コード例 #7
0
ファイル: main.py プロジェクト: carriercomm/irclogger
 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
     )
コード例 #8
0
    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")
コード例 #9
0
ファイル: machineroom.py プロジェクト: ri0t/hfos
    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")
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
    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")
コード例 #13
0
ファイル: main.py プロジェクト: carriercomm/irclogger
 def keepalive(self):
     self.fire(write(b"\x00"))
コード例 #14
0
 def keepalive(self):
     self.fire(write(b"\x00"))
コード例 #15
0
 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)
コード例 #16
0
ファイル: machineroom.py プロジェクト: addy2342/hfos
    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")
コード例 #17
0
    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")