Improvements to modpython.

1. Be able to write binary data to any sockets, not only to ones created
from python.
2. Add support for CSmartPtr<CWebSession>
This commit is contained in:
Alexey Sokolov
2012-08-13 20:01:07 +07:00
parent d7bd8d8a04
commit fcc7839771
3 changed files with 21 additions and 18 deletions

View File

@@ -68,6 +68,7 @@ using std::allocator;
%template(SCString) std::set<CString>;
typedef std::set<CString> SCString;
%template(PyMCString) std::map<CString, CString>;
%template(PyMStringVString) std::map<CString, VCString>;
class MCString : public std::map<CString, CString> {};
%template(PyModulesVector) std::vector<CModule*>;
%template(VListeners) std::vector<CListener*>;
@@ -108,6 +109,7 @@ class MCString : public std::map<CString, CString> {};
%include "../include/znc/defines.h"
%include "../include/znc/Utils.h"
%template(PAuthBase) CSmartPtr<CAuthBase>;
%template(WebSession) CSmartPtr<CWebSession>;
%include "../include/znc/Config.h"
%include "../include/znc/Csocket.h"
%template(ZNCSocketManager) TSocketManager<CZNCSock>;
@@ -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();