convert PKey to a type that can be instantiated
diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c
index e12c72a..2024077 100644
--- a/src/crypto/crypto.c
+++ b/src/crypto/crypto.c
@@ -566,27 +566,6 @@
     return (PyObject *)crypto_X509Req_New(X509_REQ_new(), 1);
 }
 
-static char crypto_PKey_doc[] = "\n\
-The factory function inserted in the module dictionary to create PKey\n\
-objects\n\
-\n\
-@return: The PKey object\n\
-";
-
-static PyObject *
-crypto_PKey(PyObject *spam, PyObject *args)
-{
-    crypto_PKeyObj *py_pkey;
-
-    if (!PyArg_ParseTuple(args, ":PKey"))
-        return NULL;
-
-    py_pkey = crypto_PKey_New(EVP_PKEY_new(), 1);
-    if (py_pkey) {
-	py_pkey->initialized = 0;
-    }
-    return (PyObject *)py_pkey;
-}
 
 static char crypto_X509Extension_doc[] = "\n\
 The factory function inserted in the module dictionary to create\n\
@@ -679,7 +658,6 @@
     { "X509",    (PyCFunction)crypto_X509,    METH_VARARGS, crypto_X509_doc },
     { "X509Name",(PyCFunction)crypto_X509Name,METH_VARARGS, crypto_X509Name_doc },
     { "X509Req", (PyCFunction)crypto_X509Req, METH_VARARGS, crypto_X509Req_doc },
-    { "PKey",    (PyCFunction)crypto_PKey,    METH_VARARGS, crypto_PKey_doc },
     { "X509Extension", (PyCFunction)crypto_X509Extension, METH_VARARGS, crypto_X509Extension_doc },
     { "NetscapeSPKI", (PyCFunction)crypto_NetscapeSPKI, METH_VARARGS, crypto_NetscapeSPKI_doc },
     { "X509_verify_cert_error_string", (PyCFunction)crypto_X509_verify_cert_error_string, METH_VARARGS, crypto_X509_verify_cert_error_string_doc },
@@ -803,7 +781,7 @@
     if (!init_openssl_threads())
         goto error;
 #endif
-    if (!init_crypto_x509(dict))
+    if (!init_crypto_x509(module))
         goto error;
     if (!init_crypto_x509name(dict))
         goto error;
@@ -811,7 +789,7 @@
         goto error;
     if (!init_crypto_x509req(dict))
         goto error;
-    if (!init_crypto_pkey(dict))
+    if (!init_crypto_pkey(module))
         goto error;
     if (!init_crypto_x509extension(dict))
         goto error;
diff --git a/src/crypto/pkey.c b/src/crypto/pkey.c
index 3d67cfc..f78acf7 100644
--- a/src/crypto/pkey.c
+++ b/src/crypto/pkey.c
@@ -156,6 +156,30 @@
     return self;
 }
 
+static char crypto_PKey_doc[] = "\n\
+PKey() -> PKey instance\n\
+\n\
+Create a new PKey object.\n\
+\n\
+@return: The PKey object\n\
+";
+static PyObject*
+crypto_PKey_new(PyTypeObject *subtype, PyObject *args, PyObject *kwargs) {
+    crypto_PKeyObj *self;
+
+    if (!PyArg_ParseTuple(args, ":PKey")) {
+        return NULL;
+    }
+
+    self = crypto_PKey_New(EVP_PKEY_new(), 1);
+    if (self) {
+	self->initialized = 0;
+    }
+
+    return (PyObject *)self;
+}
+
+
 /*
  * Deallocate the memory used by the PKey object
  *
@@ -189,7 +213,7 @@
 PyTypeObject crypto_PKey_Type = {
     PyObject_HEAD_INIT(NULL)
     0,
-    "PKey",
+    "OpenSSL.crypto.PKey",
     sizeof(crypto_PKeyObj),
     0,
     (destructor)crypto_PKey_dealloc,
@@ -202,21 +226,54 @@
     NULL, /* as_sequence */
     NULL, /* as_mapping */
     NULL, /* hash */
+    NULL, /* call */
+    NULL, /* str */
+    NULL, /* getattro */
+    NULL, /* setattro */
+    NULL, /* as_buffer */
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+    crypto_PKey_doc, /* doc */
+    NULL, /* traverse */
+    NULL, /* clear */
+    NULL, /* tp_richcompare */
+    0, /* tp_weaklistoffset */
+    NULL, /* tp_iter */
+    NULL, /* tp_iternext */
+    crypto_PKey_methods, /* tp_methods */
+    NULL, /* tp_members */
+    NULL, /* tp_getset */
+    NULL, /* tp_base */
+    NULL, /* tp_dict */
+    NULL, /* tp_descr_get */
+    NULL, /* tp_descr_set */
+    0, /* tp_dictoffset */
+    NULL, /* tp_init */
+    NULL, /* tp_alloc */
+    crypto_PKey_new, /* tp_new */
 };
 
 
 /*
  * Initialize the PKey part of the crypto sub module
  *
- * Arguments: dict - The crypto module dictionary
+ * Arguments: module - The crypto module
  * Returns:   None
  */
 int
-init_crypto_pkey(PyObject *dict)
+init_crypto_pkey(PyObject *module)
 {
-    crypto_PKey_Type.ob_type = &PyType_Type;
-    Py_INCREF(&crypto_PKey_Type);
-    PyDict_SetItemString(dict, "PKeyType", (PyObject *)&crypto_PKey_Type);
+    if (PyType_Ready(&crypto_PKey_Type) < 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "PKey", (PyObject *)&crypto_PKey_Type) != 0) {
+        return 0;
+    }
+
+    if (PyModule_AddObject(module, "PKeyType", (PyObject *)&crypto_PKey_Type) != 0) {
+        return 0;
+    }
+
     return 1;
 }
 
diff --git a/src/ssl/context.c b/src/ssl/context.c
index cb9aa88..ae669d0 100644
--- a/src/ssl/context.c
+++ b/src/ssl/context.c
@@ -550,7 +550,7 @@
 	if (!PyArg_ParseTuple(args, "O:use_privatekey", &pkey))
 	    return NULL;
 
-	if (strcmp(pkey->ob_type->tp_name, "PKey") != 0 ||
+	if (strcmp(pkey->ob_type->tp_name, "OpenSSL.crypto.PKey") != 0 ||
 	    pkey->ob_type->tp_basicsize != sizeof(crypto_PKeyObj))
 	{
 	    PyErr_SetString(PyExc_TypeError, "Expected a PKey object");