--- _c_urlarg.c.0	2010-01-30 17:56:52.000000000 +0100
+++ _c_urlarg.c	2010-01-30 18:38:52.000000000 +0100
@@ -14,6 +14,16 @@
 }
 #endif
 
+#if PY_MAJOR_VERSION < 3
+#define Bytes_FromStringAndSize PyString_FromStringAndSize
+#define Bytes_AsString PyString_AsString
+#define _Bytes_Resize _PyString_Resize
+#else
+#define Bytes_FromStringAndSize PyBytes_FromStringAndSize
+#define Bytes_AsString PyBytes_AsString
+#define _Bytes_Resize _PyBytes_Resize
+#endif
+
 #ifdef __GNUC__
 #       define TM_INLINE inline
 #else
@@ -47,15 +57,15 @@
         return NULL;
     }
     if (length == 0) {
-        return PyString_FromStringAndSize("", 0);
+        return Bytes_FromStringAndSize("", 0);
     }
     /* Allocating an output buffer of length will be sufficient,
        as the output can only be smaller. We resize the output in the end. */
-    str = PyString_FromStringAndSize(NULL, length);
+    str = Bytes_FromStringAndSize(NULL, length);
     if (str == NULL) {
         return NULL;
     }
-    output = output_start = (unsigned char*)PyString_AsString(str);
+    output = output_start = (unsigned char*)Bytes_AsString(str);
     end = s + length;
     s = s - 1;
     while ((++s) < end) {
@@ -102,7 +112,7 @@
         break;
     }
 
-    _PyString_Resize(&str, output-output_start);
+    _Bytes_Resize(&str, output-output_start);
     return str;
 }
 
@@ -111,13 +121,12 @@
     {NULL, NULL} /* sentinel */
 };
 
-DL_EXPORT(void) init_c_urlarg(void)
+static void
+init(PyObject *m)
 {
-    PyObject* m;
     PyObject* d;
     unsigned char i;
 
-    m = Py_InitModule("_c_urlarg", _c_urlarg_methods);
     d = PyModule_GetDict(m);
 
     /* add our base exception class */
@@ -145,3 +154,33 @@
     }
 }
 
+#if PY_MAJOR_VERSION < 3
+DL_EXPORT(void) init_c_urlarg(void)
+{
+    PyObject* m;
+    m = Py_InitModule("_c_urlarg", _c_urlarg_methods);
+    init(m);
+}
+#else
+static struct PyModuleDef _module = {
+	PyModuleDef_HEAD_INIT,
+	"_c_urlarg",
+	NULL,
+	-1,
+	_c_urlarg_methods,
+	NULL,
+	NULL,
+	NULL,
+	NULL
+};
+
+PyMODINIT_FUNC
+PyInit__c_urlarg(void)
+{
+    PyObject *m = PyModule_Create(&_module);
+    if (!m)
+	return NULL;
+    init(m);
+    return m;
+}
+#endif
