def handleCommand(protocol, user, channel, message, max_line_length, callback): command, _, suffix = message.partition(" ") with sqlite3.connect(config["core"]["db"]) as conn: cur = conn.cursor() res = cur.execute(user_query, (user,)) roles = [role[0] for role in res.fetchmany()] if command == "reincarnate": if "superadmin" in roles: log.info("Restarting app") reactor.stop() else: log.info("User {user} tried to do code reload", user=user) elif command == "eval": truth, expr = suffix.split(":") truth = [s.strip() for s in truth.split(",")] try: ret = simple_eval.eval_bool(expr, truth) except simple_eval.EvalError as e: callback(str(e)) else: callback("Result: %s" % ret) elif command == "join": channel, _, password = suffix.partition(" ") if not password: password = None if "superadmin" in roles: if password: log.info("Joining {channel} ({password})", channel=channel, password=password) else: log.info("Joining {channel}", channel=channel) return protocol.callRemote("join", channel, password) elif command == "leave": channel, _, reason = suffix.partition(" ") if not reason: reason = None if "superadmin" in roles: if reason: log.info("Leaving {channel} ({reason})", channel=channel, reason=reason) else: log.info("Leaving {channel}", channel=channel) return protocol.callRemote("leave", channel, reason) else: log.info("Unrecognized command {command}", command=command)
def test_simple_false(self): self.assertFalse(simple_eval.eval_bool("foo", ("bar",)))
def test_simple_true(self): self.assertTrue(simple_eval.eval_bool("foo", ("foo",)))
def test_bad_legal(self): with self.assertRaisesRegex(ValueError, "Invalid token & at position 2"): simple_eval.eval_bool("a&&b", ())
def test_bad_legal(self): with self.assertRaisesRegexp(ValueError, "Invalid token & at position 2"): simple_eval.eval_bool("a&&b", ())
def test_demorgan(self): expr = "~(foo&bar)&~(~foo|~bar)" self.assertFalse(simple_eval.eval_bool(expr, ("foo", "bar") ) )
def test_true_or_true(self): self.assertTrue(simple_eval.eval_bool("foo|bar", ("foo", "bar")))
def test_not_false(self): self.assertTrue(simple_eval.eval_bool("~foo", ()))
def test_false_or_true(self): self.assertTrue(simple_eval.eval_bool("foo|bar", ("bar", )))
def test_not_true(self): self.assertFalse(simple_eval.eval_bool("~foo", ("foo", )))
def test_false_and_true(self): self.assertFalse(simple_eval.eval_bool("foo&bar", ("bar", )))
def test_simple_false(self): self.assertFalse(simple_eval.eval_bool("foo", ("bar", )))
def test_simple_true(self): self.assertTrue(simple_eval.eval_bool("foo", ("foo", )))
def test_false_and_true(self): self.assertFalse(simple_eval.eval_bool("foo&bar", ("bar",)))
def test_false_or_false(self): self.assertFalse(simple_eval.eval_bool("foo|bar", ()))
def test_demorgan(self): expr = "~(foo&bar)&~(~foo|~bar)" self.assertFalse(simple_eval.eval_bool(expr, ("foo", "bar")))
def test_bad_input_illegal(self): with self.assertRaisesRegex(ValueError, "Invalid token / at position 4"): simple_eval.eval_bool("aef&//&||", ())
def test_bad_input(self): with self.assertRaises(ValueError): simple_eval.eval_bool("aef&//&||", ())
def test_bad_input_illegal(self): with self.assertRaisesRegexp(ValueError, "Invalid token / at position 4"): simple_eval.eval_bool("aef&//&||", ())