diff --git a/modules/modpython.cpp b/modules/modpython.cpp index 71169d12..d7abb14c 100644 --- a/modules/modpython.cpp +++ b/modules/modpython.cpp @@ -442,23 +442,6 @@ CPySocket::~CPySocket() { Py_CLEAR(m_pyObj); } -PyObject* CPySocket::WriteBytes(PyObject* data) { - if (!PyBytes_Check(data)) { - PyErr_SetString(PyExc_TypeError, "socket.WriteBytes needs bytes as argument"); - return NULL; - } - char* buffer; - Py_ssize_t length; - if (-1 == PyBytes_AsStringAndSize(data, &buffer, &length)) { - return NULL; - } - if (Write(buffer, length)) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - template<> void TModInfo(CModInfo& Info) { Info.SetWikiPage("modpython"); } diff --git a/modules/modpython/modpython.i b/modules/modpython/modpython.i index 19308a53..53ba0435 100644 --- a/modules/modpython/modpython.i +++ b/modules/modpython/modpython.i @@ -68,6 +68,7 @@ using std::allocator; %template(SCString) std::set; typedef std::set SCString; %template(PyMCString) std::map; +%template(PyMStringVString) std::map; class MCString : public std::map {}; %template(PyModulesVector) std::vector; %template(VListeners) std::vector; @@ -108,6 +109,7 @@ class MCString : public std::map {}; %include "../include/znc/defines.h" %include "../include/znc/Utils.h" %template(PAuthBase) CSmartPtr; +%template(WebSession) CSmartPtr; %include "../include/znc/Config.h" %include "../include/znc/Csocket.h" %template(ZNCSocketManager) TSocketManager; @@ -163,6 +165,25 @@ class CPyRetBool { } } +%extend Csock { + PyObject* WriteBytes(PyObject* data) { + if (!PyBytes_Check(data)) { + PyErr_SetString(PyExc_TypeError, "socket.WriteBytes needs bytes as argument"); + return NULL; + } + char* buffer; + Py_ssize_t length; + if (-1 == PyBytes_AsStringAndSize(data, &buffer, &length)) { + return NULL; + } + if ($self->Write(buffer, length)) { + Py_RETURN_TRUE; + } else { + Py_RETURN_FALSE; + } + } +} + %extend CModule { CString __str__() { return $self->GetModName(); diff --git a/modules/modpython/module.h b/modules/modpython/module.h index 26c3388a..8e52c154 100644 --- a/modules/modpython/module.h +++ b/modules/modpython/module.h @@ -180,7 +180,6 @@ public: virtual void ReadData(const char *data, size_t len); virtual void ReadLine(const CString& sLine); virtual Csock* GetSockObj(const CString& sHost, unsigned short uPort); - PyObject* WriteBytes(PyObject* data); }; inline CPySocket* CreatePySocket(CPyModule* pModule, PyObject* pyObj) {