Package: python-sendfile
Severity: wishlist
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I have made a (not very strongly tested, though) Python 3 port of
py-sendfile (I've already sent the patch upstream, too.) I'd appreciate
a python3 version in Debian.
cheers
- -- vbi
- -- System Information:
Debian Release: squeeze/sid
APT prefers testing
APT policy: (700, 'testing'), (600, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.6.37-rc5-686 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iEYEARECAAYFAk0bcIsACgkQKqpm2L3fmXpHegCfUwLF7W9AfbRn6NEgtPTV3tV6
LcoAoI7B8Newn8fRU7BuAI1uPDYnJ2OT
=RttH
-----END PGP SIGNATURE-----
diff --git a/sendfilemodule.c b/sendfilemodule.c
--- a/sendfilemodule.c
+++ b/sendfilemodule.c
@@ -286,20 +286,41 @@
{NULL, NULL, 0, NULL} /* Sentinel */
};
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef SendfileModuleDef = {
+ PyModuleDef_HEAD_INIT,
+ "sendfile",
+ NULL,
+ -1,
+ SendfileMethods,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+#endif
+
static void
insint (PyObject *d, char *name, int value)
{
- PyObject *v = PyInt_FromLong((long) value);
+ PyObject *v = PyLong_FromLong((long) value);
if (!v || PyDict_SetItemString(d, name, v))
PyErr_Clear();
Py_XDECREF(v);
}
+#if PY_MAJOR_VERSION >= 3
+PyMODINIT_FUNC
+PyInit_sendfile(void)
+{
+ PyObject *m = PyModule_Create(&SendfileModuleDef);
+#else
PyMODINIT_FUNC
initsendfile(void)
{
PyObject *m = Py_InitModule("sendfile", SendfileMethods);
+#endif
PyObject *d = PyModule_GetDict (m);
@@ -310,4 +331,8 @@
#endif
PyModule_AddStringConstant(m, "__doc__", "Direct interface to FreeBSD and Linux sendfile(2), for sending file data to a socket directly via the kernel.");
PyModule_AddStringConstant(m, "__version__", "1.2.4");
+
+#if PY_MAJOR_VERSION >= 3
+ return m;
+#endif
}
diff --git a/test.py b/test.py
--- a/test.py
+++ b/test.py
@@ -1,17 +1,21 @@
-import SocketServer, os, socket, sendfile
+try:
+ from socketserver import BaseRequestHandler, ThreadingTCPServer
+except ImportError:
+ from SocketServer import BaseRequestHandler, ThreadingTCPServer
+import os, socket, sendfile
datafile = open('sendfilemodule.c', 'rb')
datafileblocksize = os.fstat(datafile.fileno()).st_blksize
-print datafileblocksize
-class handler(SocketServer.BaseRequestHandler):
+print(datafileblocksize)
+class handler(BaseRequestHandler):
def handle (self):
if sendfile.has_sf_hdtr:
#print sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0, (["HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n", "Connection: close\r\n\r\n"], 'test'))
- print sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0, ["HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n", "Connection: close\r\n\r\n"])
+ print(sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0, ["HTTP/1.1 200 OK\r\n", "Content-Type: text/html\r\n", "Connection: close\r\n\r\n"]))
#print sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0, "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n", 'test')
else:
- print sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0)
+ print(sendfile.sendfile(self.request.fileno(), datafile.fileno(), 0, 0))
self.request.close()
-SocketServer.ThreadingTCPServer.request_queue_size = socket.SOMAXCONN
-SocketServer.ThreadingTCPServer.allow_reuse_address = True
-server = SocketServer.ThreadingTCPServer (('', 8079), handler)
+ThreadingTCPServer.request_queue_size = socket.SOMAXCONN
+ThreadingTCPServer.allow_reuse_address = True
+server = ThreadingTCPServer (('', 8079), handler)
server.serve_forever()
_______________________________________________
Python-modules-team mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/python-modules-team