1from gi.repository import GObject
2
3sanmove = "([a-hx@OoPKQRBN0-8+#=-]{2,7})"
4
5
6class ErrorManager(GObject.GObject):
7
8    __gsignals__ = {
9        'onCommandNotFound': (GObject.SignalFlags.RUN_FIRST, None, (str, )),
10        'onAmbiguousMove': (GObject.SignalFlags.RUN_FIRST, None, (str, )),
11        'onIllegalMove': (GObject.SignalFlags.RUN_FIRST, None, (str, )),
12    }
13
14    def __init__(self, connection):
15        GObject.GObject.__init__(self)
16        connection.expect_line(self.onError, r"(.*?): Command not found\.")
17        connection.expect_line(self.onAmbiguousMove,
18                               r"Ambiguous move \((%s)\)\." % sanmove)
19        connection.expect_line(self.onIllegalMove, r"Illegal move \((%s)\)\." %
20                               sanmove)
21
22    def onError(self, match):
23        command = match.groups()[0]
24        self.emit("onCommandNotFound", command)
25
26    def onAmbiguousMove(self, match):
27        move = match.groups()[0]
28        self.emit("onAmbiguousMove", move)
29
30    def onIllegalMove(self, match):
31        move = match.groups()[0]
32        self.emit("onIllegalMove", move)
33