]> jfr.im git - irc/znc/znc.git/commitdiff
Fix python sockets after latest changes.
authorAlexey Sokolov <redacted>
Tue, 27 Mar 2018 21:22:56 +0000 (22:22 +0100)
committerAlexey Sokolov <redacted>
Tue, 27 Mar 2018 21:26:05 +0000 (22:26 +0100)
The issue was triggered by CCoreTranslationMixin being parent of
CZNCSock, and DisableReadLine wasn't found as attribute anymore.

Thanks to obiw4n for report.

modules/modpython/znc.py
test/integration/tests/scripting.cpp

index ad77db6b27b2c737702d6bf9c99a743f62593969..45430cbebd9523d77a81e301b56addf8c4c5d619 100644 (file)
@@ -676,8 +676,9 @@ def make_inherit(cl, parent, attr):
         for x in parent.__dict__:
             if not x.startswith('_') and x not in cl.__dict__:
                 setattr(cl, x, make_caller(parent, x, attr))
-        if '_s' in parent.__dict__:
-            parent = parent._s
+        if parent.__bases__:
+            # Multiple inheritance is not supported (yet?)
+            parent = parent.__bases__[0]
         else:
             break
 
index 2d9836bdd5f50a98d77527bc886424fbce1bca48..ebb4dba23e3ff18abd40ef9e1eabc565a150daed 100644 (file)
@@ -57,5 +57,47 @@ TEST_F(ZNCTest, Modpython) {
     client.ReadUntil("Hi\xEF\xBF\xBD, github issue");
 }
 
+TEST_F(ZNCTest, ModpythonSocket) {
+    if (QProcessEnvironment::systemEnvironment().value(
+            "DISABLED_ZNC_PERL_PYTHON_TEST") == "1") {
+        return;
+    }
+    auto znc = Run();
+    znc->CanLeak();
+
+    InstallModule("socktest.py", R"(
+        import znc
+
+        class acc(znc.Socket):
+            def OnReadData(self, data):
+                self.GetModule().PutModule('received {} bytes'.format(len(data)))
+                self.Close()
+
+        class lis(znc.Socket):
+            def OnAccepted(self, host, port):
+                sock = self.GetModule().CreateSocket(acc)
+                sock.DisableReadLine()
+                return sock
+
+        class socktest(znc.Module):
+            def OnLoad(self, args, ret):
+                listen = self.CreateSocket(lis)
+                self.port = listen.Listen()
+                return True
+
+            def OnModCommand(self, cmd):
+                sock = self.CreateSocket()
+                sock.Connect('127.0.0.1', self.port)
+                sock.WriteBytes(b'blah')
+    )");
+
+    auto ircd = ConnectIRCd();
+    auto client = LoginClient();
+    client.Write("znc loadmod modpython");
+    client.Write("znc loadmod socktest");
+    client.Write("PRIVMSG *socktest :foo");
+    client.ReadUntil("received 4 bytes");
+}
+
 }  // namespace
 }  // namespace znc_inttest