diff -rupN pysmbc/context.c pysmbc-py3k/context.c
--- pysmbc/context.c	2010-10-20 17:43:23.323822389 +0200
+++ pysmbc-py3k/context.c	2010-10-20 22:23:26.002076698 +0200
@@ -2,9 +2,11 @@
  * pysmbc - Python bindings for libsmbclient
  * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2010  Red Hat, Inc
  * Copyright (C) 2010  Open Source Solution Technology Corporation
+ * Copyright (C) 2010  Patrick Geltinger <patlkli@patlkli.org>
  * Authors:
  *  Tim Waugh <twaugh@redhat.com>
  *  Tsukasa Hamano <hamano@osstech.co.jp>
+ *  Patrick Geltinger <patlkli@patlkli.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -28,6 +30,15 @@
 #include "dir.h"
 #include "file.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define PyString_FromString PyUnicode_FromString
+#define PyString_Check PyUnicode_Check
+#define PyString_GetSize PyUnicode_GetSize
+#define PyInt_FromLong PyLong_FromLong
+#define PyInt_Check PyLong_Check
+#define PyInt_AsLong PyLong_AsLong
+#endif
+
 static void
 auth_fn (SMBCCTX *ctx,
 	 const char *server, const char *share,
@@ -170,7 +181,7 @@ Context_dealloc (Context *self)
       smbc_free_context (self->context, 1);
     }
 
-  self->ob_type->tp_free ((PyObject *) self);
+  Py_TYPE(self)->tp_free ((PyObject *) self);
 }
 
 static PyObject *
@@ -467,8 +478,14 @@ Context_setNetbiosName (Context *self, P
       PyErr_SetString (PyExc_TypeError, "must be string");
       return -1;
     }
+  #if PY_MAJOR_VERSION >= 3
+    wchar_t* w_name;
+    Py_ssize_t size = PyUnicode_AsWideChar((PyUnicodeObject*)value, w_name, PyUnicode_GetSize(value));
+    wcstombs(name, w_name, size);
+  #else
+    name = strdup (PyString_AsString (value));
+  #endif
 
-  name = strdup (PyString_AsString (value));
   if (!name)
     {
       return -1;
@@ -497,7 +514,14 @@ Context_setWorkgroup (Context *self, PyO
       return -1;
     }
 
-  workgroup = strdup (PyString_AsString (value));
+  #if PY_MAJOR_VERSION >= 3
+    wchar_t* w_workgroup;
+    Py_ssize_t size = PyUnicode_AsWideChar((PyUnicodeObject*)value, w_workgroup, PyUnicode_GetSize(value));
+    wcstombs(workgroup, w_workgroup, size);
+  #else
+    workgroup = strdup (PyString_AsString (value));
+  #endif
+
   if (!workgroup)
     {
       return -1;
@@ -680,58 +704,113 @@ PyMethodDef Context_methods[] =
 
     { NULL } /* Sentinel */
   };
-
-PyTypeObject smbc_ContextType =
-  {
-    PyObject_HEAD_INIT(NULL)
-    0,                         /*ob_size*/
-    "smbc.Context",            /*tp_name*/
-    sizeof(Context),           /*tp_basicsize*/
-    0,                         /*tp_itemsize*/
-    (destructor)Context_dealloc, /*tp_dealloc*/
-    0,                         /*tp_print*/
-    0,                         /*tp_getattr*/
-    0,                         /*tp_setattr*/
-    0,                         /*tp_compare*/
-    0,                         /*tp_repr*/
-    0,                         /*tp_as_number*/
-    0,                         /*tp_as_sequence*/
-    0,                         /*tp_as_mapping*/
-    0,                         /*tp_hash */
-    0,                         /*tp_call*/
-    0,                         /*tp_str*/
-    0,                         /*tp_getattro*/
-    0,                         /*tp_setattro*/
-    0,                         /*tp_as_buffer*/
-    Py_TPFLAGS_DEFAULT,        /*tp_flags*/
-    "SMBC context\n"
-    "============\n\n"
-
-    "  A context for libsmbclient calls.\n\n"
-    "Optional parameters are:\n\n"
-    "auth_fn: a function for collecting authentication details from\n"
-    "the user. This is called whenever authentication details are needed.\n"
-    "The parameters it will be given are all strings: server, share,\n"
-    "workgroup, username, and password (these last two can be ignored).\n"
-    "The function should return a tuple of strings: workgroup, username,\n"
-    "and password.\n\n"
-    "debug: an integer representing the debug level to use.\n"
-    "",                        /* tp_doc */
-    0,                         /* tp_traverse */
-    0,                         /* tp_clear */
-    0,                         /* tp_richcompare */
-    0,                         /* tp_weaklistoffset */
-    0,                         /* tp_iter */
-    0,                         /* tp_iternext */
-    Context_methods,           /* tp_methods */
-    0,                         /* tp_members */
-    Context_getseters,         /* tp_getset */
-    0,                         /* tp_base */
-    0,                         /* tp_dict */
-    0,                         /* tp_descr_get */
-    0,                         /* tp_descr_set */
-    0,                         /* tp_dictoffset */
-    (initproc)Context_init,    /* tp_init */
-    0,                         /* tp_alloc */
-    Context_new,               /* tp_new */
-  };
+#if PY_MAJOR_VERSION >= 3
+  PyTypeObject smbc_ContextType =
+    {
+      PyVarObject_HEAD_INIT(NULL, 0)
+      "smbc.Context",            /*tp_name*/
+      sizeof(Context),           /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Context_dealloc, /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_reserved*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC context\n"
+      "============\n\n"
+  
+      "  A context for libsmbclient calls.\n\n"
+      "Optional parameters are:\n\n"
+      "auth_fn: a function for collecting authentication details from\n"
+      "the user. This is called whenever authentication details are needed.\n"
+      "The parameters it will be given are all strings: server, share,\n"
+      "workgroup, username, and password (these last two can be ignored).\n"
+      "The function should return a tuple of strings: workgroup, username,\n"
+      "and password.\n\n"
+      "debug: an integer representing the debug level to use.\n"
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      Context_methods,           /* tp_methods */
+      0,                         /* tp_members */
+      Context_getseters,         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Context_init,    /* tp_init */
+      0,                         /* tp_alloc */
+      Context_new,               /* tp_new */
+    };
+#else
+  PyTypeObject smbc_ContextType =
+    {
+      PyObject_HEAD_INIT(NULL)
+      0,                         /*ob_size*/
+      "smbc.Context",            /*tp_name*/
+      sizeof(Context),           /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Context_dealloc, /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_compare*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC context\n"
+      "============\n\n"
+  
+      "  A context for libsmbclient calls.\n\n"
+      "Optional parameters are:\n\n"
+      "auth_fn: a function for collecting authentication details from\n"
+      "the user. This is called whenever authentication details are needed.\n"
+      "The parameters it will be given are all strings: server, share,\n"
+      "workgroup, username, and password (these last two can be ignored).\n"
+      "The function should return a tuple of strings: workgroup, username,\n"
+      "and password.\n\n"
+      "debug: an integer representing the debug level to use.\n"
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      Context_methods,           /* tp_methods */
+      0,                         /* tp_members */
+      Context_getseters,         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Context_init,    /* tp_init */
+      0,                         /* tp_alloc */
+      Context_new,               /* tp_new */
+    };
+#endif
diff -rupN pysmbc/dir.c pysmbc-py3k/dir.c
--- pysmbc/dir.c	2010-10-20 17:43:23.323822389 +0200
+++ pysmbc-py3k/dir.c	2010-10-20 22:22:40.028818003 +0200
@@ -1,6 +1,7 @@
 /* -*- Mode: C; c-file-style: "gnu" -*-
  * pysmbc - Python bindings for libsmbclient
  * Copyright (C) 2002, 2005, 2006, 2007, 2008  Tim Waugh <twaugh@redhat.com>
+ * Copyright (C) 2010  Patrick Geltinger <patlkli@patlkli.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +24,11 @@
 #include "dir.h"
 #include "smbcdirent.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define PyString_FromString PyUnicode_FromString
+#define PyInt_FromLong PyLong_FromLong
+#endif
+
 typedef struct
 {
   PyObject_HEAD
@@ -103,7 +109,7 @@ Dir_dealloc (Dir *self)
       Py_DECREF ((PyObject *) self->context);
     }
 
-  self->ob_type->tp_free ((PyObject *) self);
+  Py_TYPE(self)->tp_free ((PyObject *) self);
 }
 
 static PyObject *
@@ -180,49 +186,98 @@ PyMethodDef Dir_methods[] =
     { NULL } /* Sentinel */
   };
 
-PyTypeObject smbc_DirType =
-  {
-    PyObject_HEAD_INIT(NULL)
-    0,                         /*ob_size*/
-    "smbc.Dir",                /*tp_name*/
-    sizeof(Dir),               /*tp_basicsize*/
-    0,                         /*tp_itemsize*/
-    (destructor)Dir_dealloc,  /*tp_dealloc*/
-    0,                         /*tp_print*/
-    0,                         /*tp_getattr*/
-    0,                         /*tp_setattr*/
-    0,                         /*tp_compare*/
-    0,                         /*tp_repr*/
-    0,                         /*tp_as_number*/
-    0,                         /*tp_as_sequence*/
-    0,                         /*tp_as_mapping*/
-    0,                         /*tp_hash */
-    0,                         /*tp_call*/
-    0,                         /*tp_str*/
-    0,                         /*tp_getattro*/
-    0,                         /*tp_setattro*/
-    0,                         /*tp_as_buffer*/
-    Py_TPFLAGS_DEFAULT,        /*tp_flags*/
-    "SMBC Dir\n"
-    "========\n\n"
-
-    "  A directory object."
-    "",                        /* tp_doc */
-    0,                         /* tp_traverse */
-    0,                         /* tp_clear */
-    0,                         /* tp_richcompare */
-    0,                         /* tp_weaklistoffset */
-    0,                         /* tp_iter */
-    0,                         /* tp_iternext */
-    Dir_methods,               /* tp_methods */
-    0,                         /* tp_members */
-    0,                         /* tp_getset */
-    0,                         /* tp_base */
-    0,                         /* tp_dict */
-    0,                         /* tp_descr_get */
-    0,                         /* tp_descr_set */
-    0,                         /* tp_dictoffset */
-    (initproc)Dir_init,        /* tp_init */
-    0,                         /* tp_alloc */
-    Dir_new,                   /* tp_new */
-  };
+#if PY_MAJOR_VERSION >= 3
+  PyTypeObject smbc_DirType =
+    {
+      PyVarObject_HEAD_INIT(NULL, 0)
+      "smbc.Dir",                /*tp_name*/
+      sizeof(Dir),               /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Dir_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_reserved*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC Dir\n"
+      "========\n\n"
+  
+      "  A directory object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      Dir_methods,               /* tp_methods */
+      0,                         /* tp_members */
+      0,                         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Dir_init,        /* tp_init */
+      0,                         /* tp_alloc */
+      Dir_new,                   /* tp_new */
+    };
+#else
+  PyTypeObject smbc_DirType =
+    {
+      PyObject_HEAD_INIT(NULL)
+      0,                         /*ob_size*/
+      "smbc.Dir",                /*tp_name*/
+      sizeof(Dir),               /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Dir_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_compare*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC Dir\n"
+      "========\n\n"
+  
+      "  A directory object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      Dir_methods,               /* tp_methods */
+      0,                         /* tp_members */
+      0,                         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Dir_init,        /* tp_init */
+      0,                         /* tp_alloc */
+      Dir_new,                   /* tp_new */
+    };
+#endif
+
diff -rupN pysmbc/file.c pysmbc-py3k/file.c
--- pysmbc/file.c	2010-10-20 17:43:23.323822389 +0200
+++ pysmbc-py3k/file.c	2010-10-20 22:24:16.099257705 +0200
@@ -2,9 +2,11 @@
  * pysmbc - Python bindings for libsmbclient
  * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2010  Red Hat, Inc
  * Copyright (C) 2010  Open Source Solution Technology Corporation
+ * Copyright (C) 2010  Patrick Geltinger <patlkli@patlkli.org>
  * Authors:
  *  Tim Waugh <twaugh@redhat.com>
  *  Tsukasa Hamano <hamano@osstech.co.jp>
+ *  Patrick Geltinger <patlkli@patlkli.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -26,6 +28,11 @@
 #include "context.h"
 #include "file.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define PyInt_FromLong PyLong_FromLong
+#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
+#endif
+
 //////////
 // File //
 //////////
@@ -124,7 +131,7 @@ File_dealloc (File *self)
       Py_DECREF ((PyObject *) self->context);
     }
 
-  self->ob_type->tp_free ((PyObject *) self);
+  Py_TYPE(self)->tp_free ((PyObject *) self);
 }
 
 static PyObject *
@@ -316,49 +323,97 @@ PyMethodDef File_methods[] =
     { NULL } /* Sentinel */
   };
 
-PyTypeObject smbc_FileType =
-  {
-    PyObject_HEAD_INIT(NULL)
-    0,                         /*ob_size*/
-    "smbc.File",               /*tp_name*/
-    sizeof(File),              /*tp_basicsize*/
-    0,                         /*tp_itemsize*/
-    (destructor)File_dealloc,  /*tp_dealloc*/
-    0,                         /*tp_print*/
-    0,                         /*tp_getattr*/
-    0,                         /*tp_setattr*/
-    0,                         /*tp_compare*/
-    0,                         /*tp_repr*/
-    0,                         /*tp_as_number*/
-    0,                         /*tp_as_sequence*/
-    0,                         /*tp_as_mapping*/
-    0,                         /*tp_hash */
-    0,                         /*tp_call*/
-    0,                         /*tp_str*/
-    0,                         /*tp_getattro*/
-    0,                         /*tp_setattro*/
-    0,                         /*tp_as_buffer*/
-    Py_TPFLAGS_DEFAULT,        /*tp_flags*/
-    "SMBC File\n"
-    "=========\n\n"
-
-    "  A file object."
-    "",                        /* tp_doc */
-    0,                         /* tp_traverse */
-    0,                         /* tp_clear */
-    0,                         /* tp_richcompare */
-    0,                         /* tp_weaklistoffset */
-    File_iter,                 /* tp_iter */
-    File_iternext,             /* tp_iternext */
-    File_methods,              /* tp_methods */
-    0,                         /* tp_members */
-    0,                         /* tp_getset */
-    0,                         /* tp_base */
-    0,                         /* tp_dict */
-    0,                         /* tp_descr_get */
-    0,                         /* tp_descr_set */
-    0,                         /* tp_dictoffset */
-    (initproc)File_init,       /* tp_init */
-    0,                         /* tp_alloc */
-    File_new,                  /* tp_new */
-  };
+#if PY_MAJOR_VERSION >= 3
+  PyTypeObject smbc_FileType =
+    {
+      PyVarObject_HEAD_INIT(NULL, 0)
+      "smbc.File",               /*tp_name*/
+      sizeof(File),              /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)File_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_reserved*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC File\n"
+      "=========\n\n"
+  
+      "  A file object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      File_iter,                 /* tp_iter */
+      File_iternext,             /* tp_iternext */
+      File_methods,              /* tp_methods */
+      0,                         /* tp_members */
+      0,                         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)File_init,       /* tp_init */
+      0,                         /* tp_alloc */
+      File_new,                  /* tp_new */
+    };
+#else
+  PyTypeObject smbc_FileType =
+    {
+      PyObject_HEAD_INIT(NULL)
+      0,                         /*ob_size*/
+      "smbc.File",               /*tp_name*/
+      sizeof(File),              /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)File_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_compare*/
+      0,                         /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC File\n"
+      "=========\n\n"
+  
+      "  A file object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      File_iter,                 /* tp_iter */
+      File_iternext,             /* tp_iternext */
+      File_methods,              /* tp_methods */
+      0,                         /* tp_members */
+      0,                         /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)File_init,       /* tp_init */
+      0,                         /* tp_alloc */
+      File_new,                  /* tp_new */
+    };
+#endif
diff -rupN pysmbc/smbcdirent.c pysmbc-py3k/smbcdirent.c
--- pysmbc/smbcdirent.c	2010-10-20 17:43:23.323822389 +0200
+++ pysmbc-py3k/smbcdirent.c	2010-10-20 22:24:56.921776013 +0200
@@ -1,6 +1,7 @@
 /* -*- Mode: C; c-file-style: "gnu" -*-
  * pysmbc - Python bindings for libsmbclient
  * Copyright (C) 2002, 2005, 2006, 2007, 2008  Tim Waugh <twaugh@redhat.com>
+ * Copyright (C) 2010  Patrick Geltinger <patlkli@patlkli.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,6 +22,11 @@
 #include "smbcmodule.h"
 #include "smbcdirent.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define PyInt_FromLong PyLong_FromLong
+#define PyString_FromString PyUnicode_FromString
+#endif
+
 typedef struct
 {
   PyObject_HEAD
@@ -84,7 +90,7 @@ Dirent_dealloc (Dirent *self)
 {
   free (self->comment);
   free (self->name);
-  self->ob_type->tp_free ((PyObject *) self);
+  Py_TYPE(self)->tp_free ((PyObject *) self);
 }
 
 static PyObject *
@@ -149,49 +155,98 @@ PyGetSetDef Dirent_getseters[] =
     { NULL }
   };
 
-PyTypeObject smbc_DirentType =
-  {
-    PyObject_HEAD_INIT(NULL)
-    0,                         /*ob_size*/
-    "smbc.Dirent",             /*tp_name*/
-    sizeof(Dirent),            /*tp_basicsize*/
-    0,                         /*tp_itemsize*/
-    (destructor)Dirent_dealloc,  /*tp_dealloc*/
-    0,                         /*tp_print*/
-    0,                         /*tp_getattr*/
-    0,                         /*tp_setattr*/
-    0,                         /*tp_compare*/
-    Dirent_repr,               /*tp_repr*/
-    0,                         /*tp_as_number*/
-    0,                         /*tp_as_sequence*/
-    0,                         /*tp_as_mapping*/
-    0,                         /*tp_hash */
-    0,                         /*tp_call*/
-    0,                         /*tp_str*/
-    0,                         /*tp_getattro*/
-    0,                         /*tp_setattro*/
-    0,                         /*tp_as_buffer*/
-    Py_TPFLAGS_DEFAULT,        /*tp_flags*/
-    "SMBC Dirent\n"
-    "===========\n\n"
-
-    "  A directory entry object."
-    "",                        /* tp_doc */
-    0,                         /* tp_traverse */
-    0,                         /* tp_clear */
-    0,                         /* tp_richcompare */
-    0,                         /* tp_weaklistoffset */
-    0,                         /* tp_iter */
-    0,                         /* tp_iternext */
-    0,                         /* tp_methods */
-    0,                         /* tp_members */
-    Dirent_getseters,          /* tp_getset */
-    0,                         /* tp_base */
-    0,                         /* tp_dict */
-    0,                         /* tp_descr_get */
-    0,                         /* tp_descr_set */
-    0,                         /* tp_dictoffset */
-    (initproc)Dirent_init,     /* tp_init */
-    0,                         /* tp_alloc */
-    Dirent_new,                /* tp_new */
-  };
+#if PY_MAJOR_VERSION >= 3
+  PyTypeObject smbc_DirentType =
+    {
+      PyVarObject_HEAD_INIT(NULL, 0)
+      "smbc.Dirent",             /*tp_name*/
+      sizeof(Dirent),            /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Dirent_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_reserved*/
+      Dirent_repr,               /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC Dirent\n"
+      "=========\n\n"
+  
+      "  A directory entry object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      0,                         /* tp_methods */
+      0,                         /* tp_members */
+      Dirent_getseters,          /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Dirent_init,     /* tp_init */
+      0,                         /* tp_alloc */
+      Dirent_new,                /* tp_new */
+    };
+#else
+  PyTypeObject smbc_DirentType =
+    {
+      PyObject_HEAD_INIT(NULL)
+      0,                         /*ob_size*/
+      "smbc.Dirent",             /*tp_name*/
+      sizeof(Dirent),            /*tp_basicsize*/
+      0,                         /*tp_itemsize*/
+      (destructor)Dirent_dealloc,  /*tp_dealloc*/
+      0,                         /*tp_print*/
+      0,                         /*tp_getattr*/
+      0,                         /*tp_setattr*/
+      0,                         /*tp_compare*/
+      Dirent_repr,               /*tp_repr*/
+      0,                         /*tp_as_number*/
+      0,                         /*tp_as_sequence*/
+      0,                         /*tp_as_mapping*/
+      0,                         /*tp_hash */
+      0,                         /*tp_call*/
+      0,                         /*tp_str*/
+      0,                         /*tp_getattro*/
+      0,                         /*tp_setattro*/
+      0,                         /*tp_as_buffer*/
+      Py_TPFLAGS_DEFAULT,        /*tp_flags*/
+      "SMBC Dirent\n"
+      "=========\n\n"
+  
+      "  A directory entry object."
+      "",                        /* tp_doc */
+      0,                         /* tp_traverse */
+      0,                         /* tp_clear */
+      0,                         /* tp_richcompare */
+      0,                         /* tp_weaklistoffset */
+      0,                         /* tp_iter */
+      0,                         /* tp_iternext */
+      0,                         /* tp_methods */
+      0,                         /* tp_members */
+      Dirent_getseters,          /* tp_getset */
+      0,                         /* tp_base */
+      0,                         /* tp_dict */
+      0,                         /* tp_descr_get */
+      0,                         /* tp_descr_set */
+      0,                         /* tp_dictoffset */
+      (initproc)Dirent_init,     /* tp_init */
+      0,                         /* tp_alloc */
+      Dirent_new,                /* tp_new */
+    };
+#endif
+
diff -rupN pysmbc/smbcmodule.c pysmbc-py3k/smbcmodule.c
--- pysmbc/smbcmodule.c	2010-10-20 17:43:23.323822389 +0200
+++ pysmbc-py3k/smbcmodule.c	2010-10-20 22:25:48.869222443 +0200
@@ -2,9 +2,11 @@
  * pysmbc - Python bindings for libsmbclient
  * Copyright (C) 2002, 2005, 2006, 2007, 2008, 2010  Red Hat, Inc
  * Copyright (C) 2010  Open Source Solution Technology Corporation
+ * Copyright (C) 2010  Patrick Geltinger <patlkli@patlkli.org>
  * Authors:
  *  Tim Waugh <twaugh@redhat.com>
  *  Tsukasa Hamano <hamano@osstech.co.jp>
+ *  Patrick Geltinger <patlkli@patlkli.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -29,6 +31,10 @@
 #include "file.h"
 #include "smbcdirent.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define PyInt_FromLong PyLong_FromLong
+#endif
+
 static PyMethodDef SmbcMethods[] = {
   { NULL, NULL, 0, NULL }
 };
@@ -40,10 +46,27 @@ PyObject *NotEmptyError;
 PyObject *TimedOutError;
 PyObject *NoSpaceError;
 
+#if PY_MAJOR_VERSION >= 3
+  static struct PyModuleDef smbc_module = {
+    PyModuleDef_HEAD_INIT,
+    "smbc",
+    NULL,
+    -1,
+    SmbcMethods
+  };
+
+PyObject *
+PyInit_smbc (void)
+#else
 void
 initsmbc (void)
+#endif
 {
-  PyObject *m = Py_InitModule ("smbc", SmbcMethods);
+  #if PY_MAJOR_VERSION >= 3
+    PyObject *m = PyModule_Create (&smbc_module);
+  #else
+    PyObject *m = Py_InitModule ("smbc", SmbcMethods);
+  #endif
   PyObject *d = PyModule_GetDict (m);
 
   // Context type
@@ -107,6 +130,10 @@ initsmbc (void)
   NoSpaceError = PyErr_NewException("smbc.NoSpaceError", NULL, NULL);
   Py_INCREF(NoSpaceError);
   PyModule_AddObject(m, "NoSpaceError", NoSpaceError);
+
+  #if PY_MAJOR_VERSION >= 3
+  return m;
+  #endif
 }
 
 void pysmbc_SetFromErrno()
