Esempio n. 1
0
 def test_binary_to_term_binary(self):
     self.assertRaises(erlang.ParseException, erlang.binary_to_term,
                       b'\x83m')
     self.assertRaises(erlang.ParseException, erlang.binary_to_term,
                       b'\x83m\0')
     self.assertRaises(erlang.ParseException, erlang.binary_to_term,
                       b'\x83m\0\0')
     self.assertRaises(erlang.ParseException, erlang.binary_to_term,
                       b'\x83m\0\0\0')
     self.assertRaises(erlang.ParseException, erlang.binary_to_term,
                       b'\x83m\0\0\0\1')
     self.assertEqual(erlang.OtpErlangBinary(b''),
                      erlang.binary_to_term(b'\x83m\0\0\0\0'))
     self.assertEqual(erlang.OtpErlangBinary(b'data'),
                      erlang.binary_to_term(b'\x83m\0\0\0\4data'))
Esempio n. 2
0
    def socket_thread_function(self, name):
        self._logger.info("Setting up socket")
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.bind((socket.gethostname(), 42069))
        self.sock.listen()
        self.sock.settimeout(None)
        while True:
            self._logger.info("Waiting for connection")
            connection, _client_address = self.sock.accept()
            connection.settimeout(None)
            self.connection = connection
            self._logger.info("Connection established")
            url = self._settings.get(["url"])
            if url:
                self._logger.info("URL Configured")
                term = (erlang.OtpErlangAtom(bytes("url", "utf-8")),
                        erlang.OtpErlangBinary(bytes(url, "utf-8")))
                self.queue.put(term)

            try:
                for data in self.recv_loop(connection):
                    if data[0] == erlang.OtpErlangAtom(bytes(
                            "logger", "utf-8")):
                        self.handle_erlang_log(data[1], data[2])
                    elif data[0] == erlang.OtpErlangAtom(b'ping'):
                        self.last_ping = datetime.datetime.now().isoformat()
                        self.send(erlang.OtpErlangAtom(b'pong'), connection)
                    elif data[0] == erlang.OtpErlangAtom(
                            b'phoenix_socket_connection'):
                        self.phoenix_socket_connection = data[1].value.decode()
                    else:
                        self._logger.error("unhandled message=" + str(data))
            except (OSError):
                pass
Esempio n. 3
0
 def on_settings_save(self, data):
     old_url = self._settings.get(["url"])
     octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
     new_url = self._settings.get(["url"])
     if old_url != new_url:
         self._logger.info(
             "url changed from {old_url} to {new_url}".format(**locals()))
         term = (erlang.OtpErlangAtom(bytes("url", "utf-8")),
                 erlang.OtpErlangBinary(bytes(new_url, "utf-8")))
         self.send(term, self.connection)
Esempio n. 4
0
 def on_print_progress(self, storage, path, progress):
     term = (erlang.OtpErlangAtom(b'progress'),
             erlang.OtpErlangBinary(bytes(storage, "utf-8")),
             erlang.OtpErlangBinary(bytes(path, "utf-8")), progress)
     self.send(term, self.connection)