Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 921750 Details for
Bug 985290
python-nss Python 3 compatibility
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
First rough attempt to make python-nss python3 compatbile
python-nss-python3-first-attempt.patch (text/plain), 192.15 KB, created by
Bohuslav "Slavek" Kabrda
on 2014-07-28 10:46:03 UTC
(
hide
)
Description:
First rough attempt to make python-nss python3 compatbile
Filename:
MIME Type:
Creator:
Bohuslav "Slavek" Kabrda
Created:
2014-07-28 10:46:03 UTC
Size:
192.15 KB
patch
obsolete
>diff -r e1b1afd424c3 setup.py >--- a/setup.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/setup.py Mon Jul 28 12:32:46 2014 +0200 >@@ -57,7 +57,7 @@ > f.write("__version__ = '%s'\n" % version) > > if need_to_update: >- print "Updating version in \"%s\" to \"%s\"" % (version_file, version) >+ print("Updating version in \"%s\" to \"%s\"" % (version_file, version)) > os.rename(tmp_file, version_file) > else: > os.unlink(tmp_file) >@@ -314,11 +314,11 @@ > > for arg in argv[:]: > if arg in ('-d', '--debug'): >- print "compiling with debug" >+ print("compiling with debug") > extra_compile_args += debug_compile_args > argv.remove(arg) > if arg in ('-t', '--trace'): >- print "compiling with trace" >+ print("compiling with trace") > extra_compile_args += ['-DDEBUG'] > argv.remove(arg) > >diff -r e1b1afd424c3 src/py_2_3_compat.h >--- /dev/null Thu Jan 01 00:00:00 1970 +0000 >+++ b/src/py_2_3_compat.h Mon Jul 28 12:32:46 2014 +0200 >@@ -0,0 +1,208 @@ >+#if PY_MAJOR_VERSION >= 3 >+#define IS_PY3K >+#define MODINITERROR return NULL >+#define PYSTRTYPE_RESIZE PyUnicode_Resize >+#define PYSTRTYPE_JOIN PyUnicode_Join >+#define PYSTRTYPE_FROMSTRING PyUnicode_FromString >+#define PYSTRTYPE_FROMFORMAT PyUnicode_FromFormat >+#define PYSTRTYPE_FROMFORMATV PyUnicode_FromFormatV >+// make following functions look like macros to keep things consistent >+inline void PYSTRTYPE_CONCATANDDEL(PyObject** a, PyObject* b) { >+ // TODOpy3: is this correct? >+ PyObject *tmp; >+ tmp = PyUnicode_Concat(*a, b); >+ Py_XDECREF(*a); >+ Py_XDECREF(b); >+ *a = tmp; >+} >+inline void PYSTRTYPE_CONCAT(PyObject** a, PyObject* b) { >+ // TODOpy3: is this correct? >+ PyObject *tmp; >+ tmp = PyUnicode_Concat(*a, b); >+ Py_XDECREF(*a); >+ *a = tmp; >+} >+#define PYSTRTYPE_ASSTRING PyUnicode_AsUTF8 >+#define PYSTRTYPE_FORMAT PyUnicode_Format >+#define PYSTRTYPE_CHECK PyUnicode_Check >+#define PYINTTYPE_FROMLONG PyLong_FromLong >+#define PYINTTYPE_ASLONG PyLong_AsLong >+#define PYINTTYPE_CHECK PyLong_Check >+#define PYINT_TYPE PyLong_Type >+// because of PyObject_IsInstance(file_arg, (PyObject *)&PyIOBase_Type) >+extern PyTypeObject PyIOBase_Type; >+// type of first argument to PySlice_GetIndicesEx >+#define PYSLICE_GETINDICESEX_ARGTYPE PyObject >+#define PYUNICODE_ASUTF8 PyUnicode_AsUTF8 >+// TODOpy3: not sure if this is correct, doesn't accept buffers, only bytes >+#define BYTES_FORMAT_STRING "y#" >+#else >+#include "bytesobject.h" >+#define MODINITERROR return >+#define PYSTRTYPE_RESIZE _PyString_Resize >+#define PYSTRTYPE_JOIN _PyString_Join >+#define PYSTRTYPE_FROMSTRING PyString_FromString >+#define PYSTRTYPE_FROMFORMAT PyString_FromFormat >+#define PYSTRTYPE_FROMFORMATV PyString_FromFormatV >+#define PYSTRTYPE_CONCATANDDEL PyString_ConcatAndDel >+#define PYSTRTYPE_CONCAT PyString_Concat >+#define PYSTRTYPE_ASSTRING PyString_AsString >+#define PYSTRTYPE_FORMAT PyString_Format >+#define PYSTRTYPE_CHECK PyString_Check >+#define PYINTTYPE_FROMLONG PyInt_FromLong >+#define PYINTTYPE_ASLONG PyInt_AsLong >+#define PYINTTYPE_CHECK PyInt_Check >+#define PYINT_TYPE PyInt_Type >+#define PYSLICE_GETINDICESEX_ARGTYPE PySliceObject >+inline char *PYUNICODE_ASUTF8(PyObject *u) { >+ PyObject *bytes = PyUnicode_AsUTF8String(u); >+ char *ret; >+ if (bytes == NULL) >+ return NULL; >+ ret = PyBytes_AsString(bytes); >+ Py_DECREF(bytes); >+ return ret; >+} >+#define BYTES_FORMAT_STRING "t#" >+#endif >+ >+ >+/* Code below is included to be able to use PyCapsule API even in >+ Python 2.6 - as recommended at >+ https://docs.python.org/3/howto/cporting.html#cobject-replaced-with-capsule >+*/ >+ >+#ifndef __CAPSULETHUNK_H >+#define __CAPSULETHUNK_H >+ >+#if ( (PY_VERSION_HEX < 0x02070000) \ >+ || ((PY_VERSION_HEX >= 0x03000000) \ >+ && (PY_VERSION_HEX < 0x03010000)) ) >+ >+#define __PyCapsule_GetField(capsule, field, default_value) \ >+ ( PyCapsule_CheckExact(capsule) \ >+ ? (((PyCObject *)capsule)->field) \ >+ : (default_value) \ >+ ) \ >+ >+#define __PyCapsule_SetField(capsule, field, value) \ >+ ( PyCapsule_CheckExact(capsule) \ >+ ? (((PyCObject *)capsule)->field = value), 1 \ >+ : 0 \ >+ ) \ >+ >+ >+#define PyCapsule_Type PyCObject_Type >+ >+#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) >+#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule)) >+ >+ >+#define PyCapsule_New(pointer, name, destructor) \ >+ (PyCObject_FromVoidPtr(pointer, destructor)) >+ >+ >+#define PyCapsule_GetPointer(capsule, name) \ >+ (PyCObject_AsVoidPtr(capsule)) >+ >+/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */ >+#define PyCapsule_SetPointer(capsule, pointer) \ >+ __PyCapsule_SetField(capsule, cobject, pointer) >+ >+ >+#define PyCapsule_GetDestructor(capsule) \ >+ __PyCapsule_GetField(capsule, destructor) >+ >+#define PyCapsule_SetDestructor(capsule, dtor) \ >+ __PyCapsule_SetField(capsule, destructor, dtor) >+ >+ >+/* >+ * Sorry, there's simply no place >+ * to store a Capsule "name" in a CObject. >+ */ >+#define PyCapsule_GetName(capsule) NULL >+ >+static int >+PyCapsule_SetName(PyObject *capsule, const char *unused) >+{ >+ unused = unused; >+ PyErr_SetString(PyExc_NotImplementedError, >+ "can't use PyCapsule_SetName with CObjects"); >+ return 1; >+} >+ >+ >+ >+#define PyCapsule_GetContext(capsule) \ >+ __PyCapsule_GetField(capsule, descr) >+ >+#define PyCapsule_SetContext(capsule, context) \ >+ __PyCapsule_SetField(capsule, descr, context) >+ >+ >+static void * >+PyCapsule_Import(const char *name, int no_block) >+{ >+ PyObject *object = NULL; >+ void *return_value = NULL; >+ char *trace; >+ size_t name_length = (strlen(name) + 1) * sizeof(char); >+ char *name_dup = (char *)PyMem_MALLOC(name_length); >+ >+ if (!name_dup) { >+ return NULL; >+ } >+ >+ memcpy(name_dup, name, name_length); >+ >+ trace = name_dup; >+ while (trace) { >+ char *dot = strchr(trace, '.'); >+ if (dot) { >+ *dot++ = '\0'; >+ } >+ >+ if (object == NULL) { >+ if (no_block) { >+ object = PyImport_ImportModuleNoBlock(trace); >+ } else { >+ object = PyImport_ImportModule(trace); >+ if (!object) { >+ PyErr_Format(PyExc_ImportError, >+ "PyCapsule_Import could not " >+ "import module \"%s\"", trace); >+ } >+ } >+ } else { >+ PyObject *object2 = PyObject_GetAttrString(object, trace); >+ Py_DECREF(object); >+ object = object2; >+ } >+ if (!object) { >+ goto EXIT; >+ } >+ >+ trace = dot; >+ } >+ >+ if (PyCObject_Check(object)) { >+ PyCObject *cobject = (PyCObject *)object; >+ return_value = cobject->cobject; >+ } else { >+ PyErr_Format(PyExc_AttributeError, >+ "PyCapsule_Import \"%s\" is not valid", >+ name); >+ } >+ >+EXIT: >+ Py_XDECREF(object); >+ if (name_dup) { >+ PyMem_FREE(name_dup); >+ } >+ return return_value; >+} >+ >+#endif /* #if PY_VERSION_HEX < 0x02070000 */ >+ >+#endif /* __CAPSULETHUNK_H */ >diff -r e1b1afd424c3 src/py_nspr_common.h >--- a/src/py_nspr_common.h Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nspr_common.h Mon Jul 28 12:32:46 2014 +0200 >@@ -41,31 +41,6 @@ > #define _(s) s > #endif > >-#if (PY_VERSION_HEX < 0x02050000) >-typedef int Py_ssize_t; >-#define PY_SSIZE_T_MAX INT_MAX >-#define PY_SSIZE_T_MIN INT_MIN >-#define PyInt_FromSsize_t PyInt_FromLong >-#define PyNumber_AsSsize_t(ob, exc) PyInt_AsLong(ob) >-#define PyIndex_Check(ob) PyInt_Check(ob) >-typedef Py_ssize_t (*readbufferproc)(PyObject *, Py_ssize_t, void **); >-typedef Py_ssize_t (*writebufferproc)(PyObject *, Py_ssize_t, void **); >-typedef Py_ssize_t (*segcountproc)(PyObject *, Py_ssize_t *); >-typedef Py_ssize_t (*charbufferproc)(PyObject *, Py_ssize_t, char **); >-typedef Py_ssize_t (*lenfunc)(PyObject *); >-typedef PyObject *(*ssizeargfunc)(PyObject *, Py_ssize_t); >-typedef PyObject *(*ssizessizeargfunc)(PyObject *, Py_ssize_t, Py_ssize_t); >-#endif >- >-#if (PY_VERSION_HEX < 0x02060000) >-#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) >-#define PyVarObject_HEAD_INIT(type, size) \ >- PyObject_HEAD_INIT(type) size, >-#define PyImport_ImportModuleNoBlock PyImport_ImportModule >-#define PyLong_FromSsize_t PyInt_FromLong >-#define Py_TPFLAGS_HAVE_NEWBUFFER 0 >-#endif >- > #define PyNone_Check(x) ((x) == Py_None) > > #define CALL_BASE(type, func, ...) (type)->tp_base->tp_##func(__VA_ARGS__) >@@ -73,12 +48,12 @@ > #define TYPE_READY(type) \ > { \ > if (PyType_Ready(&type) < 0) \ >- return; \ >+ MODINITERROR; \ > Py_INCREF(&type); \ > PyModule_AddObject(m, rindex(type.tp_name, '.')+1, (PyObject *)&type); \ > } > >-#define AddIntConstant(c) if (PyModule_AddIntConstant(m, #c, c) < 0) return; >+#define AddIntConstant(c) if (PyModule_AddIntConstant(m, #c, c) < 0) MODINITERROR; > > #ifdef DEBUG > >diff -r e1b1afd424c3 src/py_nspr_error.c >--- a/src/py_nspr_error.c Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nspr_error.c Mon Jul 28 12:32:46 2014 +0200 >@@ -4,6 +4,7 @@ > > #define PY_SSIZE_T_CLEAN > #include "Python.h" >+#include "py_2_3_compat.h" > #include "structmember.h" > > #define NSS_ERROR_MODULE >@@ -61,8 +62,8 @@ > static int > IntOrNoneConvert(PyObject *obj, int *param) > { >- if (PyInt_Check(obj)) { >- *param = PyInt_AsLong(obj); >+ if (PYINTTYPE_CHECK(obj)) { >+ *param = PYINTTYPE_ASLONG(obj); > return 1; > } > >@@ -166,7 +167,7 @@ > final_err_msg = PR_smprintf("error (%d) unknown", error_code); > } > >- result = PyString_FromString(final_err_msg); >+ result = PYSTRTYPE_FROMSTRING(final_err_msg); > > if (final_err_msg) PR_smprintf_free(final_err_msg); > if (pr_err_msg) PyMem_Free(pr_err_msg); >@@ -188,7 +189,7 @@ > #else > va_start(vargs); > #endif >- error_message = PyString_FromFormatV(format, vargs); >+ error_message = PYSTRTYPE_FROMFORMATV(format, vargs); > va_end(vargs); > } > >@@ -224,7 +225,7 @@ > #else > va_start(vargs); > #endif >- error_message = PyString_FromFormatV(format, vargs); >+ error_message = PYSTRTYPE_FROMFORMATV(format, vargs); > va_end(vargs); > } > >@@ -238,7 +239,7 @@ > } > } > >- if (PyDict_SetItemString(kwds, "usages", PyInt_FromLong(usages)) != 0) { >+ if (PyDict_SetItemString(kwds, "usages", PYINTTYPE_FROMLONG(usages)) != 0) { > return NULL; > } > >@@ -276,7 +277,7 @@ > if ((error_desc = lookup_nspr_error(err_num)) == NULL) > Py_RETURN_NONE; > >- return PyString_FromString(error_desc->string); >+ return PYSTRTYPE_FROMSTRING(error_desc->string); > } > > /* List of functions exported by this module. */ >@@ -299,7 +300,7 @@ > return NULL; > > /* Create a python string to hold the modules error documentation */ >- if ((py_error_doc = PyString_FromString("NSPR Error Constants:\n\n")) == NULL) >+ if ((py_error_doc = PYSTRTYPE_FROMSTRING("NSPR Error Constants:\n\n")) == NULL) > return NULL; > > /* >@@ -309,11 +310,11 @@ > */ > for (i = 0, error_desc = &nspr_errors[0]; i < nspr_error_count; i++, error_desc++) { > >- if ((error_str = PyString_FromFormat("%s: %s\n\n", error_desc->name, error_desc->string)) == NULL) { >+ if ((error_str = PYSTRTYPE_FROMFORMAT("%s: %s\n\n", error_desc->name, error_desc->string)) == NULL) { > Py_DECREF(py_error_doc); > return NULL; > } >- PyString_ConcatAndDel(&py_error_doc, error_str); >+ PYSTRTYPE_CONCATANDDEL(&py_error_doc, error_str); > > if (PyModule_AddIntConstant(module, error_desc->name, error_desc->num) < 0) { > Py_DECREF(py_error_doc); >@@ -346,15 +347,15 @@ > len = PyTuple_GET_SIZE(tuple); > > if (len == 0) { >- return PyString_FromString("()"); >+ return PYSTRTYPE_FROMSTRING("()"); > } > >- if ((text = PyString_FromString("(")) == NULL) { >+ if ((text = PYSTRTYPE_FROMSTRING("(")) == NULL) { > goto exit; > } > > if (len > 1) { >- if ((separator = PyString_FromString(", ")) == NULL) { >+ if ((separator = PYSTRTYPE_FROMSTRING(", ")) == NULL) { > goto exit; > } > } >@@ -362,24 +363,24 @@ > for (i = 0; i < len; i++) { > obj = PyTuple_GET_ITEM(tuple, i); > tmp_obj = PyObject_Str(obj); >- PyString_ConcatAndDel(&text, tmp_obj); >+ PYSTRTYPE_CONCATANDDEL(&text, tmp_obj); > if (text == NULL) { > goto exit; > } > if (i < len-1) { >- PyString_Concat(&text, separator); >+ PYSTRTYPE_CONCAT(&text, separator); > if (text == NULL) { > goto exit; > } > } > } > >- if ((tmp_obj = PyString_FromString(")")) == NULL) { >+ if ((tmp_obj = PYSTRTYPE_FROMSTRING(")")) == NULL) { > Py_CLEAR(text); > goto exit; > } > >- PyString_ConcatAndDel(&text, tmp_obj); >+ PYSTRTYPE_CONCATANDDEL(&text, tmp_obj); > if (text == NULL) { > goto exit; > } >@@ -469,7 +470,7 @@ > error_code : int\n\ > NSS or NSPR error value, if None get current error\n\ > \n\ >-Exception object (derived from StandardException), raised when an\n\ >+Exception object (derived from standard Exception), raised when an\n\ > NSS or NSPR error occurs. The error model in python-nss is anytime\n\ > a NSS or NSPR C function returns an error the python-nss binding\n\n\ > raises a NSPRError exception.\n\ >@@ -520,18 +521,21 @@ > error_desc = get_error_desc(&error_code); > > if (error_message) { >- str_value = PyString_FromFormat("%s: %s", >- error_message, >- error_desc ? PyString_AsString(error_desc) : >- _("Error description unavailable")); >+ str_value = PYSTRTYPE_FROMFORMAT("%s: %s", >+ error_message, >+ error_desc ? PYSTRTYPE_ASSTRING(error_desc) : >+ _("Error description unavailable")); > } else { > str_value = error_desc; > } > > >+#ifndef IS_PY3K >+ // TODOpy3: how to do this properly in in python3? there is no .message for exceptions > Py_CLEAR(self->base.message); > self->base.message = str_value; > Py_XINCREF(self->base.message); >+#endif > > Py_CLEAR(self->str_value); > self->str_value = str_value; >@@ -547,8 +551,7 @@ > } > > static PyTypeObject NSPRErrorType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.error.NSPRError", /* tp_name */ > sizeof(NSPRError), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -617,7 +620,7 @@ > return NULL; > } > >- str = PyString_FromFormat("%s usages=%#x", PyString_AsString(super_str), self->usages); >+ str = PYSTRTYPE_FROMFORMAT("%s usages=%#x", PYSTRTYPE_ASSTRING(super_str), self->usages); > Py_DECREF(super_str); > return str; > } >@@ -727,13 +730,13 @@ > return -1; > } > if (error_message) { >- if (PyDict_SetItemString(super_kwds, "error_message", PyString_FromString(error_message)) != 0) { >+ if (PyDict_SetItemString(super_kwds, "error_message", PYSTRTYPE_FROMSTRING(error_message)) != 0) { > Py_DECREF(super_kwds); > return -1; > } > } > if (error_code != -1) { >- if (PyDict_SetItemString(super_kwds, "error_code", PyInt_FromLong(error_code)) != 0) { >+ if (PyDict_SetItemString(super_kwds, "error_code", PYINTTYPE_FROMLONG(error_code)) != 0) { > Py_DECREF(super_kwds); > return -1; > } >@@ -754,8 +757,7 @@ > } > > static PyTypeObject CertVerifyErrorType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.error.CertVerifyError", /* tp_name */ > sizeof(CertVerifyError), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -814,38 +816,65 @@ > manipulate them.\n\ > "); > >+#ifdef IS_PY3K >+static struct PyModuleDef py_nspr_error_def = { >+ PyModuleDef_HEAD_INIT, >+ "error", >+ NULL, >+ -1, >+ module_methods, >+ NULL, >+ NULL, >+ NULL, >+ NULL >+}; >+ >+PyMODINIT_FUNC >+PyInit_error(void) >+#else > PyMODINIT_FUNC > initerror(void) >+#endif > { > PyObject *m; > PyObject *py_error_doc = NULL; > PyObject *py_module_doc = NULL; > >- if ((m = Py_InitModule3("error", module_methods, module_doc)) == NULL) >- return; >+#ifdef IS_PY3K >+ m = PyModule_Create(&py_nspr_error_def); >+#else >+ m = Py_InitModule3("error", module_methods, module_doc); >+#endif >+ >+ if (m == NULL) >+ MODINITERROR; > > if ((empty_tuple = PyTuple_New(0)) == NULL) { >- return; >+ MODINITERROR; > } > Py_INCREF(empty_tuple); > > if ((py_error_doc = init_py_nspr_errors(m)) == NULL) >- return; >+ MODINITERROR; > >- if ((py_module_doc = PyString_FromString(module_doc)) == NULL) >- return; >+ if ((py_module_doc = PYSTRTYPE_FROMSTRING(module_doc)) == NULL) >+ MODINITERROR; > >- PyString_ConcatAndDel(&py_module_doc, py_error_doc); >+ PYSTRTYPE_CONCATANDDEL(&py_module_doc, py_error_doc); >+ // TODOpy3: set this as a module doc in nice way under Python 3? > PyModule_AddObject(m, "__doc__", py_module_doc); > >- NSPRErrorType.tp_base = (PyTypeObject *)PyExc_StandardError; >+ NSPRErrorType.tp_base = (PyTypeObject *)PyExc_Exception; > > TYPE_READY(NSPRErrorType); > TYPE_READY(CertVerifyErrorType); > > /* Export C API */ > nspr_error_c_api.nspr_exception = (PyObject *)&NSPRErrorType; >- if (PyModule_AddObject(m, "_C_API", PyCObject_FromVoidPtr((void *)&nspr_error_c_api, NULL)) != 0) >- return; >+ if (PyModule_AddObject(m, "_C_API", PyCapsule_New((void *)&nspr_error_c_api, NULL, NULL)) != 0) >+ MODINITERROR; > >+#ifdef IS_PY3K >+ return m; >+#endif > } >diff -r e1b1afd424c3 src/py_nspr_error.h >--- a/src/py_nspr_error.h Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nspr_error.h Mon Jul 28 12:32:46 2014 +0200 >@@ -49,13 +49,13 @@ > return -1; > } > >- if (!(PyCObject_Check(c_api_object))) { >+ if (!(PyCapsule_CheckExact(c_api_object))) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; > } > >- if ((api = PyCObject_AsVoidPtr(c_api_object)) == NULL) { >+ if ((api = PyCapsule_GetPointer(c_api_object, NULL)) == NULL) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; >diff -r e1b1afd424c3 src/py_nspr_io.c >--- a/src/py_nspr_io.c Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nspr_io.c Mon Jul 28 12:32:46 2014 +0200 >@@ -10,6 +10,7 @@ > > #define PY_SSIZE_T_CLEAN > #include "Python.h" >+#include "py_2_3_compat.h" > #include "structmember.h" > > #include "py_nspr_common.h" >@@ -235,12 +236,12 @@ > } > > if ((canonical_name = PR_GetCanonNameFromAddrInfo(pr_addrinfo)) != NULL) { >- if ((self->py_hostname = PyString_FromString(canonical_name)) == NULL) { >+ if ((self->py_hostname = PYSTRTYPE_FROMSTRING(canonical_name)) == NULL) { > PR_FreeAddrInfo(pr_addrinfo); > return NULL; > } > } else { >- if ((self->py_hostname = PyString_FromString(addr_str)) == NULL) { >+ if ((self->py_hostname = PYSTRTYPE_FROMSTRING(addr_str)) == NULL) { > PR_FreeAddrInfo(pr_addrinfo); > return NULL; > } >@@ -296,14 +297,14 @@ > TraceMethodEnter(self); > > if (PR_NetAddrFamily(&self->pr_netaddr) == PR_AF_UNSPEC) { >- return PyString_FromString(unset_string); >+ return PYSTRTYPE_FROMSTRING(unset_string); > } > > if (PR_NetAddrToString(&self->pr_netaddr, buf, sizeof(buf)) != PR_SUCCESS) { > return set_nspr_error(NULL); > } > >- return PyString_FromString(buf); >+ return PYSTRTYPE_FROMSTRING(buf); > } > > static PyObject * >@@ -311,7 +312,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(PR_NetAddrFamily(&self->pr_netaddr)); >+ return PYINTTYPE_FROMLONG(PR_NetAddrFamily(&self->pr_netaddr)); > } > > static PyObject * >@@ -319,7 +320,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(PRNetAddr_port(&self->pr_netaddr)); >+ return PYINTTYPE_FROMLONG(PRNetAddr_port(&self->pr_netaddr)); > } > > static int >@@ -334,12 +335,12 @@ > return -1; > } > >- if (!PyInt_Check(value)) { >+ if (!PYINTTYPE_CHECK(value)) { > PyErr_SetString(PyExc_TypeError, "The port attribute value must be an integer"); > return -1; > } > >- port = PyInt_AsLong(value); >+ port = PYINTTYPE_ASLONG(value); > if (PR_SetNetAddr(PR_IpAddrNull, PR_NetAddrFamily(&self->pr_netaddr), > port, &self->pr_netaddr) != PR_SUCCESS) { > set_nspr_error(NULL); >@@ -402,7 +403,7 @@ > "NetworkAddress initialization from a string parameter only works for IPv4, use AddrInfo instead.", 1) < 0) > return NULL; > >- if (addr && (PyString_Check(addr) || PyUnicode_Check(addr))) { >+ if (addr && (PyBytes_Check(addr) || PyUnicode_Check(addr))) { > PyObject *ascii_str = NULL; > char *addr_str = NULL; > >@@ -415,7 +416,7 @@ > Py_INCREF(ascii_str); > } > >- if ((addr_str = PyString_AsString(ascii_str)) == NULL) { >+ if ((addr_str = PyBytes_AsString(ascii_str)) == NULL) { > Py_DECREF(ascii_str); > return NULL; > } >@@ -498,7 +499,7 @@ > TraceMethodEnter(self); > > NetworkAddress_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(NetworkAddress_doc, >@@ -570,13 +571,13 @@ > &addr, &port, &family)) > return -1; > >- if (addr && !(PyInt_Check(addr) || PyString_Check(addr) || PyUnicode_Check(addr))) { >+ if (addr && !(PYINTTYPE_CHECK(addr) || PyBytes_Check(addr) || PyUnicode_Check(addr))) { > PyErr_SetString(PyExc_ValueError, "addr must be an int or a string"); > return -1; > } > >- if (addr && PyInt_Check(addr)) { >- addr_int = PyInt_AsLong(addr); >+ if (addr && PYINTTYPE_CHECK(addr)) { >+ addr_int = PYINTTYPE_ASLONG(addr); > switch(addr_int) { > case PR_IpAddrNull: > case PR_IpAddrAny: >@@ -606,7 +607,7 @@ > return -1; > } > >- if (addr && (PyString_Check(addr) || PyUnicode_Check(addr))) { >+ if (addr && (PyBytes_Check(addr) || PyUnicode_Check(addr))) { > PyObject *ascii_str = NULL; > char *addr_str = NULL; > PyObject *result = NULL; >@@ -624,7 +625,7 @@ > Py_INCREF(ascii_str); > } > >- if ((addr_str = PyString_AsString(ascii_str)) == NULL) { >+ if ((addr_str = PyBytes_AsString(ascii_str)) == NULL) { > Py_DECREF(ascii_str); > return -1; > } >@@ -646,7 +647,7 @@ > char buf[1024]; > > if (PR_NetAddrFamily(&self->pr_netaddr) == PR_AF_UNSPEC) { >- return PyString_FromString(unset_string); >+ return PYSTRTYPE_FROMSTRING(unset_string); > } > > if (PR_NetAddrToString(&self->pr_netaddr, buf, sizeof(buf)) != PR_SUCCESS) { >@@ -655,18 +656,17 @@ > > switch(PR_NetAddrFamily(&self->pr_netaddr)) { > case PR_AF_INET: >- return PyString_FromFormat("%s:%d", buf, PR_ntohs(self->pr_netaddr.inet.port)); >+ return PYSTRTYPE_FROMFORMAT("%s:%d", buf, PR_ntohs(self->pr_netaddr.inet.port)); > case PR_AF_INET6: >- return PyString_FromFormat("[%s]:%d", buf, PR_ntohs(self->pr_netaddr.ipv6.port)); >+ return PYSTRTYPE_FROMFORMAT("[%s]:%d", buf, PR_ntohs(self->pr_netaddr.ipv6.port)); > default: >- return PyString_FromString(buf); >+ return PYSTRTYPE_FROMSTRING(buf); > } > } > > static PyTypeObject > NetworkAddressType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.io.NetworkAddress", /* tp_name */ > sizeof(NetworkAddress), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -801,7 +801,7 @@ > self->pr_addrinfo = NULL; > } > AddrInfo_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AddrInfo_doc, >@@ -876,7 +876,7 @@ > &hostname, &family, &flags)) > return -1; > >- if ((self->py_hostname = PyString_FromString(hostname)) == NULL) { >+ if ((self->py_hostname = PYSTRTYPE_FROMSTRING(hostname)) == NULL) { > return -1; > } > >@@ -913,7 +913,7 @@ > self->py_canonical_name = Py_None; > Py_INCREF(self->py_canonical_name); > } else { >- if ((self->py_canonical_name = PyString_FromString(canonical_name)) == NULL) { >+ if ((self->py_canonical_name = PYSTRTYPE_FROMSTRING(canonical_name)) == NULL) { > return -1; > } > } >@@ -924,8 +924,8 @@ > static PyObject * > AddrInfo_repr(AddrInfo *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyObject * >@@ -952,18 +952,18 @@ > goto fail; > } > >- if ((format = PyString_FromString("host=%s canonical=%s (%d addrs)")) == NULL) { >+ if ((format = PYSTRTYPE_FROMSTRING("host=%s canonical=%s (%d addrs)")) == NULL) { > goto fail; > } > >- if ((text = PyString_Format(format, args)) == NULL) { >+ if ((text = PYSTRTYPE_FORMAT(format, args)) == NULL) { > goto fail; > } > > Py_CLEAR(format); > Py_CLEAR(args); > >- if ((format = PyString_FromString(" addr[%d]=%s")) == NULL) { >+ if ((format = PYSTRTYPE_FROMSTRING(" addr[%d]=%s")) == NULL) { > goto fail; > } > >@@ -973,11 +973,11 @@ > goto fail; > } > >- if ((addr_str = PyString_Format(format, args)) == NULL) { >+ if ((addr_str = PYSTRTYPE_FORMAT(format, args)) == NULL) { > goto fail; > } > >- PyString_ConcatAndDel(&text, addr_str); >+ PYSTRTYPE_CONCATANDDEL(&text, addr_str); > if (text == NULL) { > goto fail; > } >@@ -1034,8 +1034,7 @@ > }; > > static PyTypeObject AddrInfoType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.io.AddrInfo", /* tp_name */ > sizeof(AddrInfo), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -1086,7 +1085,7 @@ > { > TraceMethodEnter(self); > >- return PyString_FromString(self->entry.h_name); >+ return PYSTRTYPE_FROMSTRING(self->entry.h_name); > } > > static PyObject * >@@ -1094,7 +1093,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->entry.h_addrtype); >+ return PYINTTYPE_FROMLONG(self->entry.h_addrtype); > } > > static PyObject * >@@ -1237,7 +1236,7 @@ > TraceMethodEnter(self); > > HostEntry_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(HostEntry_doc, >@@ -1292,7 +1291,7 @@ > &addr)) > return -1; > >- if (PyString_Check(addr) || PyUnicode_Check(addr)) { >+ if (PyBytes_Check(addr) || PyUnicode_Check(addr)) { > PyObject *ascii_str = NULL; > char *addr_str = NULL; > >@@ -1305,7 +1304,7 @@ > Py_INCREF(ascii_str); > } > >- if ((addr_str = PyString_AsString(ascii_str)) == NULL) { >+ if ((addr_str = PyBytes_AsString(ascii_str)) == NULL) { > Py_DECREF(ascii_str); > return -1; > } >@@ -1347,7 +1346,7 @@ > } > > for (i = 0; i < len; i++) { >- if ((py_alias = PyString_FromString(self->entry.h_aliases[i])) == NULL) { >+ if ((py_alias = PYSTRTYPE_FROMSTRING(self->entry.h_aliases[i])) == NULL) { > Py_CLEAR(self->py_aliases); > return -1; > } >@@ -1411,11 +1410,11 @@ > goto exit; > } > >- if ((format = PyString_FromString("name=%s family=%s aliases=%s addresses=%s")) == NULL) { >+ if ((format = PYSTRTYPE_FROMSTRING("name=%s family=%s aliases=%s addresses=%s")) == NULL) { > goto exit; > } > >- text = PyString_Format(format, args); >+ text = PYSTRTYPE_FORMAT(format, args); > > exit: > Py_XDECREF(aliases); >@@ -1466,8 +1465,7 @@ > > static PyTypeObject > HostEntryType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.io.HostEntry", /* tp_name */ > sizeof(HostEntry), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -1602,7 +1600,7 @@ > } > > desc_type = PR_GetDescType(self->pr_socket); >- return PyInt_FromLong(desc_type); >+ return PYINTTYPE_FROMLONG(desc_type); > } > > static PyGetSetDef >@@ -1732,12 +1730,12 @@ > return NULL; > } > >- if (!PyInt_Check(py_option)) { >+ if (!PYINTTYPE_CHECK(py_option)) { > PyErr_SetString(PyExc_TypeError, "set_socket_option: option must be an int"); > return NULL; > } > >- option = PyInt_AsLong(py_option); >+ option = PYINTTYPE_CHECK(py_option); > data.option = option; > > switch(option) { >@@ -2194,13 +2192,13 @@ > &requested_amount, &timeout)) > return NULL; > >- if ((py_buf = PyString_FromStringAndSize(NULL, requested_amount)) == NULL) { >+ if ((py_buf = PyBytes_FromStringAndSize(NULL, requested_amount)) == NULL) { > return NULL; > } > > Py_BEGIN_ALLOW_THREADS > amount_read = PR_AcceptRead(self->pr_socket, &pr_socket, &pr_netaddr, >- PyString_AS_STRING(py_buf), requested_amount, >+ PyBytes_AS_STRING(py_buf), requested_amount, > timeout); > Py_END_ALLOW_THREADS > >@@ -2210,7 +2208,7 @@ > } > > if (amount_read != requested_amount) { >- if (_PyString_Resize(&py_buf, amount_read) < 0) { >+ if (_PyBytes_Resize(&py_buf, amount_read) < 0) { > goto error; > } > } >@@ -2227,6 +2225,7 @@ > goto error; > } > >+ // TODOpy3: should py_buf be decoded or not? I have no idea > return return_values; > > error: >@@ -2491,14 +2490,15 @@ > } > assert(0); /* should never reach here */ > return_line: >- if ((line = PyString_FromStringAndSize(self->readahead.buf, line_len)) == NULL) { >+ if ((line = PyBytes_FromStringAndSize(self->readahead.buf, line_len)) == NULL) { > return NULL; > } >- memmove(PyString_AsString(line), self->readahead.buf, line_len); >+ memmove(PyBytes_AsString(line), self->readahead.buf, line_len); > /* Subtract the data being returned from the cached readahead buffer */ > tail_len = self->readahead.len - line_len; > memmove(self->readahead.buf, self->readahead.buf + line_len, tail_len); > self->readahead.len = tail_len; >+ // TODOpy3: should line be decoded? > return line; > } > >@@ -2546,7 +2546,19 @@ > return NULL; > } > Py_DECREF(line); >+#ifdef IS_PY3K >+ { >+ PyObject *tmp = PyUnicode_AsUTF8String(line); >+ if (tmp == NULL) { >+ Py_DECREF(list); >+ return NULL; >+ } >+ line_len = PyBytes_Size(tmp); >+ Py_DECREF(tmp); >+ } >+#else > line_len = PyString_Size(line); >+#endif > amount_read += line_len; > if (sizehint > 0 && amount_read >= sizehint) break; /* read at least requested amount */ > if (line_len == 0) break; /* EOF */ >@@ -2570,12 +2582,26 @@ > Socket_iternext(Socket *self) > { > PyObject *line; >+ int lsize; > > if ((line = _readline(self, 0)) == NULL) { > return NULL; > } > >- if (PyString_Size(line) == 0) { >+#ifdef IS_PY3K >+ { >+ PyObject *tmp = PyUnicode_AsUTF8String(line); >+ if (tmp == NULL) { >+ Py_DECREF(line); >+ return NULL; >+ } >+ lsize = PyBytes_Size(tmp); >+ } >+#else >+ lsize = PyString_Size(line); >+#endif >+ >+ if (lsize == 0) { > Py_DECREF(line); > return NULL; > } >@@ -2624,11 +2650,11 @@ > > result_len = 0; > read_len = requested_amount; >- if ((py_buf = PyString_FromStringAndSize(NULL, requested_amount)) == NULL) { >+ if ((py_buf = PyBytes_FromStringAndSize(NULL, requested_amount)) == NULL) { > return NULL; > } > >- dst = PyString_AsString(py_buf); >+ dst = PyBytes_AsString(py_buf); > > /* Is the read request already buffered? */ > if (self->readahead.len) { >@@ -2675,10 +2701,11 @@ > result_len += amount_read; > > if (result_len != requested_amount) { >- if (_PyString_Resize(&py_buf, result_len) < 0) { >+ if (_PyBytes_Resize(&py_buf, result_len) < 0) { > return NULL; > } > } >+ // TODOpy3: should py_buf be decoded here (and also in above return)? > return py_buf; > } > >@@ -2747,12 +2774,13 @@ > > } while (amount_read != 0); > >- if ((py_buf = PyString_FromStringAndSize(self->readahead.buf, self->readahead.len)) == NULL) { >+ if ((py_buf = PyBytes_FromStringAndSize(self->readahead.buf, self->readahead.len)) == NULL) { > return NULL; > } > > FREE_READAHEAD(&self->readahead); > >+ // TODOpy3: should py_buf be decoded here? > return py_buf; > } > >@@ -2800,12 +2828,12 @@ > > ASSIGN_REF(self->py_netaddr, py_netaddr); > >- if ((py_buf = PyString_FromStringAndSize((char *) 0, requested_amount)) == NULL) { >+ if ((py_buf = PyBytes_FromStringAndSize((char *) 0, requested_amount)) == NULL) { > return NULL; > } > > Py_BEGIN_ALLOW_THREADS >- amount_read = PR_RecvFrom(self->pr_socket, PyString_AS_STRING(py_buf), >+ amount_read = PR_RecvFrom(self->pr_socket, PyBytes_AS_STRING(py_buf), > requested_amount, 0, &py_netaddr->pr_netaddr, timeout); > Py_END_ALLOW_THREADS > >@@ -2815,10 +2843,11 @@ > } > > if (amount_read != requested_amount) { >- if (_PyString_Resize(&py_buf, amount_read) < 0) { >+ if (_PyBytes_Resize(&py_buf, amount_read) < 0) { > return NULL; > } > } >+ // TODOpy3: should py_buf be decoded here? > return py_buf; > } > >@@ -2861,7 +2890,7 @@ > return set_nspr_error(NULL); > } > >- return PyInt_FromLong(amount); >+ return PYINTTYPE_FROMLONG(amount); > } > > PyDoc_STRVAR(Socket_sendall_doc, >@@ -2903,7 +2932,7 @@ > return set_nspr_error(NULL); > } > >- return PyInt_FromLong(amount); >+ return PYINTTYPE_FROMLONG(amount); > } > > PyDoc_STRVAR(Socket_send_to_doc, >@@ -2954,7 +2983,7 @@ > return set_nspr_error(NULL); > } > >- return PyInt_FromLong(amount); >+ return PYINTTYPE_FROMLONG(amount); > } > > PyDoc_STRVAR(Socket_get_sock_name_doc, >@@ -3020,7 +3049,7 @@ > } > > #if SIZEOF_SOCKET_T <= SIZEOF_LONG >- return PyInt_FromLong((long)sock_fd); >+ return PYINTTYPE_FROMLONG((long)sock_fd); > #else > return PyLong_FromLongLong((PY_LONG_LONG)sock_fd); > #endif >@@ -3173,7 +3202,7 @@ > if (obj == NULL) { > goto err_descs; > } >- flags = PyInt_AsLong(obj); >+ flags = PYINTTYPE_ASLONG(obj); > if (flags == -1 && PyErr_Occurred()) > goto err_descs; > Py_CLEAR(obj); >@@ -3197,7 +3226,7 @@ > goto err_descs; > } > for (i = 0; i < num_descs; i++) { >- PyTuple_SetItem(return_value, i, PyInt_FromLong(descs[i].out_flags)); >+ PyTuple_SetItem(return_value, i, PYINTTYPE_FROMLONG(descs[i].out_flags)); > } > > PyMem_Del(descs); >@@ -3336,7 +3365,7 @@ > > Socket_clear(self); > FREE_READAHEAD(&self->readahead); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(Socket_doc, >@@ -3369,11 +3398,11 @@ > TraceMethodEnter(self); > > if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!i", kwlist, >- &PyInt_Type, &py_family, &desc_type)) >+ &PYINT_TYPE, &py_family, &desc_type)) > return -1; > > if (py_family) { >- family = PyInt_AsLong(py_family); >+ family = PYINTTYPE_ASLONG(py_family); > } else { > if (PyErr_WarnEx(PyExc_DeprecationWarning, > "Socket initialization will require family parameter in future, default family parameter of PR_AF_INET is deprecated. Suggest using the family property of the NetworkAddress object associated with the socket, e.g. Socket(net_addr.family)", 1) < 0) >@@ -3422,8 +3451,8 @@ > static PyObject * > Socket_repr(Socket *self) > { >- return PyString_FromFormat("<%s object at %p PRFileDesc %p>", >- self->ob_type->tp_name, self, self->pr_socket); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p PRFileDesc %p>", >+ Py_TYPE(self)->tp_name, self, self->pr_socket); > } > > static PyObject * >@@ -3437,15 +3466,14 @@ > pr_file_desc_type_str(PR_GetDescType(self->pr_socket)))) == NULL) { > return NULL; > } >- text = PyString_Format(PyString_FromString("family=%s type=%s"), args); >+ text = PYSTRTYPE_FORMAT(PYSTRTYPE_FROMSTRING("family=%s type=%s"), args); > Py_DECREF(args); > return text; > } > > static PyTypeObject > SocketType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.io.Socket", /* tp_name */ > sizeof(Socket), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -3502,7 +3530,7 @@ > return NULL; > } > host = PR_ntohs(net); >- return PyInt_FromLong(host); >+ return PYINTTYPE_FROMLONG(host); > } > > PyDoc_STRVAR(io_ntohl_doc, "32 bit conversion from network to host"); >@@ -3515,7 +3543,7 @@ > return NULL; > } > host = PR_ntohl(net); >- return PyInt_FromLong(host); >+ return PYINTTYPE_FROMLONG(host); > } > > PyDoc_STRVAR(io_htons_doc, "16 bit conversion from host to network"); >@@ -3528,7 +3556,7 @@ > return NULL; > } > net = PR_htons(host); >- return PyInt_FromLong(net); >+ return PYINTTYPE_FROMLONG(net); > } > > PyDoc_STRVAR(io_htonl_doc, "32 bit conversion from host to network"); >@@ -3541,7 +3569,7 @@ > return NULL; > } > net = PR_htonl(host); >- return PyInt_FromLong(net); >+ return PYINTTYPE_FROMLONG(net); > } > > // FIXME: the PR_GetProto* functions return success even if they fail >@@ -3567,7 +3595,7 @@ > } > Py_END_ALLOW_THREADS > >- return PyInt_FromLong(proto_ent.p_num); >+ return PYINTTYPE_FROMLONG(proto_ent.p_num); > } > > >@@ -3605,7 +3633,7 @@ > } > > for (i = 0; i < len; i++) { >- if ((alias = PyString_FromString(proto_ent.p_aliases[i])) == NULL) { >+ if ((alias = PYSTRTYPE_FROMSTRING(proto_ent.p_aliases[i])) == NULL) { > Py_DECREF(alias_tuple); > return NULL; > } >@@ -3630,7 +3658,7 @@ > PRIntervalTime interval; > > interval = PR_IntervalNow(); >- return PyInt_FromLong(interval); >+ return PYINTTYPE_FROMLONG(interval); > } > > PyDoc_STRVAR(io_ticks_per_second_doc, >@@ -3646,7 +3674,7 @@ > PRUint32 ticks_per_second; > > ticks_per_second = PR_TicksPerSecond(); >- return PyInt_FromLong(ticks_per_second); >+ return PYINTTYPE_FROMLONG(ticks_per_second); > } > > PyDoc_STRVAR(io_seconds_to_interval_doc, >@@ -3662,7 +3690,7 @@ > } > > interval = PR_SecondsToInterval(seconds); >- return PyInt_FromLong(interval); >+ return PYINTTYPE_FROMLONG(interval); > } > > PyDoc_STRVAR(io_milliseconds_to_interval_doc, >@@ -3678,7 +3706,7 @@ > } > > interval = PR_MillisecondsToInterval(milliseconds); >- return PyInt_FromLong(interval); >+ return PYINTTYPE_FROMLONG(interval); > } > > >@@ -3695,7 +3723,7 @@ > } > > interval = PR_MicrosecondsToInterval(microseconds); >- return PyInt_FromLong(interval); >+ return PYINTTYPE_FROMLONG(interval); > } > > PyDoc_STRVAR(io_interval_to_seconds_doc, >@@ -3711,7 +3739,7 @@ > } > > seconds = PR_IntervalToSeconds(interval); >- return PyInt_FromLong(seconds); >+ return PYINTTYPE_FROMLONG(seconds); > } > > PyDoc_STRVAR(io_interval_to_milliseconds_doc, >@@ -3727,7 +3755,7 @@ > } > > milliseconds = PR_IntervalToMilliseconds(interval); >- return PyInt_FromLong(milliseconds); >+ return PYINTTYPE_FROMLONG(milliseconds); > } > > PyDoc_STRVAR(io_interval_to_microseconds_doc, >@@ -3743,7 +3771,7 @@ > } > > microseconds = PR_IntervalToMicroseconds(interval); >- return PyInt_FromLong(microseconds); >+ return PYINTTYPE_FROMLONG(microseconds); > } > > PyDoc_STRVAR(io_addr_family_name_doc, >@@ -3764,7 +3792,7 @@ > return NULL; > } > >- return PyString_FromString(pr_family_str(family)); >+ return PYSTRTYPE_FROMSTRING(pr_family_str(family)); > } > > /* List of functions exported by this module. */ >@@ -3806,16 +3834,39 @@ > \n\ > "); > >+#ifdef IS_PY3K >+static struct PyModuleDef py_nspr_io_def = { >+ PyModuleDef_HEAD_INIT, >+ "io", >+ module_doc, >+ -1, >+ module_methods, >+ NULL, >+ NULL, >+ NULL, >+ NULL >+}; >+ >+PyMODINIT_FUNC >+PyInit_io(void) >+#else > PyMODINIT_FUNC > initio(void) >+#endif > { > PyObject *m; > > if (import_nspr_error_c_api() < 0) >- return; >- >- if ((m = Py_InitModule3("io", module_methods, module_doc)) == NULL) { >- return; >+ MODINITERROR; >+ >+#ifdef IS_PY3K >+ m = PyModule_Create(&py_nspr_io_def); >+#else >+ m = Py_InitModule3("io", module_methods, module_doc); >+#endif >+ >+ if (m == NULL) { >+ MODINITERROR; > } > > TYPE_READY(NetworkAddressType); >@@ -3824,8 +3875,8 @@ > TYPE_READY(SocketType); > > /* Export C API */ >- if (PyModule_AddObject(m, "_C_API", PyCObject_FromVoidPtr((void *)&nspr_io_c_api, NULL)) != 0) >- return; >+ if (PyModule_AddObject(m, "_C_API", PyCapsule_New((void *)&nspr_io_c_api, NULL, NULL)) != 0) >+ MODINITERROR; > > /* Socket types */ > AddIntConstant(PR_AF_INET); >@@ -3891,4 +3942,7 @@ > AddIntConstant(PR_POLL_NVAL); > AddIntConstant(PR_POLL_HUP); > >+#ifdef IS_PY3K >+ return m; >+#endif > } >diff -r e1b1afd424c3 src/py_nspr_io.h >--- a/src/py_nspr_io.h Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nspr_io.h Mon Jul 28 12:32:46 2014 +0200 >@@ -130,13 +130,13 @@ > return -1; > } > >- if (!(PyCObject_Check(c_api_object))) { >+ if (!(PyCapsule_CheckExact(c_api_object))) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; > } > >- if ((api = PyCObject_AsVoidPtr(c_api_object)) == NULL) { >+ if ((api = PyCapsule_GetPointer(c_api_object, NULL)) == NULL) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; >diff -r e1b1afd424c3 src/py_nss.c >--- a/src/py_nss.c Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nss.c Mon Jul 28 12:32:46 2014 +0200 >@@ -50,7 +50,7 @@ > return -1; > } > >- if (!PyString_Check(value)) { >+ if (!PYSTRTYPE_CHECK(value)) { > PyErr_Format(PyExc_TypeError, "classproperty must be a string, not %.200s", > Py_TYPE(value)->tp_name); > return -1; >@@ -247,7 +247,7 @@ > TraceMethodEnter(self); > > NewType_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(NewType_doc, >@@ -288,8 +288,7 @@ > }; > > static PyTypeObject NewTypeType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.NewType", /* tp_name */ > sizeof(NewType), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -354,6 +353,7 @@ > > #define PY_SSIZE_T_CLEAN > #include "Python.h" >+#include "py_2_3_compat.h" > #include "structmember.h" > > #include "py_nspr_common.h" >@@ -453,13 +453,13 @@ > flags &= ~enum; \ > switch(repr_kind) { \ > case AsEnum: \ >- py_flag = PyInt_FromLong(enum); \ >+ py_flag = PYINTTYPE_FROMLONG(enum); \ > break; \ > case AsEnumName: \ >- py_flag = PyString_FromString(#enum); \ >+ py_flag = PYSTRTYPE_FROMSTRING(#enum); \ > break; \ > case AsEnumDescription: \ >- py_flag = PyString_FromString(description); \ >+ py_flag = PYSTRTYPE_FROMSTRING(description); \ > break; \ > default: \ > PyErr_Format(PyExc_ValueError, "Unsupported representation kind (%d)", repr_kind); \ >@@ -478,7 +478,7 @@ > #define BIT_FLAGS_TO_LIST_EPILOGUE() \ > { \ > if (flags) { \ >- if ((py_flag = PyString_FromFormat("unknown bit flags %#x", flags)) == NULL) { \ >+ if ((py_flag = PYSTRTYPE_FROMFORMAT("unknown bit flags %#x", flags)) == NULL) { \ > Py_DECREF(py_flags); \ > return NULL; \ > } \ >@@ -701,14 +701,14 @@ > > if (label) { > tuple_size++; >- if ((py_label = PyString_FromFormat("%s:", label)) == NULL) { >+ if ((py_label = PYSTRTYPE_FROMFORMAT("%s:", label)) == NULL) { > return NULL; > } > } > > if (py_value) { > tuple_size++; >- if (PyString_Check(py_value) || PyUnicode_Check(py_value)) { >+ if (PyBytes_Check(py_value) || PyUnicode_Check(py_value)) { > py_value_str = py_value; > Py_INCREF(py_value_str); > } else { >@@ -723,7 +723,7 @@ > } > > i = 0; >- PyTuple_SetItem(fmt_tuple, i++, PyInt_FromLong(level)); >+ PyTuple_SetItem(fmt_tuple, i++, PYINTTYPE_FROMLONG(level)); > > if (py_label) { > PyTuple_SetItem(fmt_tuple, i++, py_label); >@@ -1038,12 +1038,12 @@ > py_value = PyTuple_GetItem(py_line_fmt_tuple, 2); > } > >- if (!PyInt_Check(py_level)) { >+ if (!PYINTTYPE_CHECK(py_level)) { > PyErr_Format(PyExc_TypeError, "item[0] in the tuple at line_fmt_tuples[%zd] list must be an integer, not %.200s", > i, Py_TYPE(py_level)->tp_name); > goto fail; > } >- line_level = PyInt_AsLong(py_level); >+ line_level = PYINTTYPE_ASLONG(py_level); > if (line_level < 0) { > PyErr_Format(PyExc_TypeError, "item[0] in the tuple at line_fmt_tuples[%zd] list must be a non-negative integer, not %ld", > i, line_level); >@@ -1057,7 +1057,7 @@ > i, Py_TYPE(py_label)->tp_name); > goto fail; > } >- if (PyString_AsStringAndSize(py_string_utf8, &label, &label_len) == -1) { >+ if (PyBytes_AsStringAndSize(py_string_utf8, &label, &label_len) == -1) { > goto fail; > } > } >@@ -1069,7 +1069,7 @@ > i, Py_TYPE(py_value)->tp_name); > goto fail; > } >- if (PyString_AsStringAndSize(py_string_utf8, &value, &value_len) == -1) { >+ if (PyBytes_AsStringAndSize(py_string_utf8, &value, &value_len) == -1) { > goto fail; > } > } >@@ -1157,11 +1157,11 @@ > } > > if (num_lines > 0) formatted_str_len -= 1; /* last line doesn't get a new line appended */ >- if ((py_formatted_str = PyString_FromStringAndSize(NULL, formatted_str_len)) == NULL) { >- goto fail; >- } >- >- formatted_str = PyString_AsString(py_formatted_str); >+ if ((py_formatted_str = PyBytes_FromStringAndSize(NULL, formatted_str_len)) == NULL) { >+ goto fail; >+ } >+ >+ formatted_str = PyBytes_AsString(py_formatted_str); > dst = formatted_str; > > /* >@@ -1191,7 +1191,7 @@ > if (label_len) { > py_label = PyTuple_GetItem(py_line_fmt_tuple, 1); > py_string_utf8 = PyString_UTF8(py_label, "label"); >- label = PyString_AsString(py_string_utf8); >+ label = PyBytes_AsString(py_string_utf8); > > for (src = label, src_end = label + label_len; src < src_end; *dst++ = *src++); > >@@ -1205,7 +1205,7 @@ > if (value_len) { > py_value = PyTuple_GetItem(py_line_fmt_tuple, 2); > py_string_utf8 = PyString_UTF8(py_value, "value"); >- value = PyString_AsString(py_string_utf8); >+ value = PyBytes_AsString(py_string_utf8); > > for (src = value, src_end = value + value_len; src < src_end; *dst++ = *src++); > >@@ -1220,7 +1220,17 @@ > /* > * Done. Sanity check we've written exactly the buffer we allocated. > */ >- assert(formatted_str + PyString_Size(py_formatted_str) == dst); >+ assert(formatted_str + PyBytes_Size(py_formatted_str) == dst); >+#ifdef IS_PY3K >+ { >+ PyObject *tmp = PyUnicode_FromEncodedObject(py_formatted_str, "utf-8", NULL); >+ if (tmp == NULL) { >+ Py_DECREF(py_formatted_str); >+ return NULL; >+ } >+ py_formatted_str = tmp; >+ } >+#endif > return py_formatted_str; > > fail: >@@ -1848,7 +1858,7 @@ > PyObject * > PyString_UTF8(PyObject *obj, char *name) > { >- if (PyString_Check(obj)) { >+ if (PyBytes_Check(obj)) { > Py_INCREF(obj); > return obj; > } >@@ -1920,7 +1930,8 @@ > * If string treat as file path to open and read, > * if file object read from file object. > * >- * Read the contents of a file and return as a PyString object. >+ * Read the contents of a file and return as a PyString (PyBytes in >+ * Python 3) object. > * If file is a string then treat it as a file pathname and open > * and read the contents of that file. If file is a file object > * then read the contents from the file object >@@ -1931,16 +1942,40 @@ > PyObject *py_file=NULL; > PyObject *py_file_contents=NULL; > >- if (PyString_Check(file_arg) || PyUnicode_Check(file_arg)) { >- if ((py_file = PyFile_FromString(PyString_AsString(file_arg), "r")) == NULL) { >- return NULL; >- } >- } else if (PyFile_Check(file_arg)) { >- py_file = file_arg; >- Py_INCREF(py_file); >- } else { >- PyErr_SetString(PyExc_TypeError, "Bad file, must be pathname or file object"); >- return NULL; >+ if (PyBytes_Check(file_arg) || PyUnicode_Check(file_arg)) { >+#ifdef IS_PY3K >+ char *fname = >+ PyBytes_Check(file_arg) ? PyBytes_AsString(file_arg) : PyUnicode_AsUTF8(file_arg); >+ if (fname == NULL) >+ return NULL; >+ PyObject *ioMod = PyImport_ImportModule("io"); >+ >+ // read binary in Python 3 to get PyBytes object >+ // TODOpy3: check that opening file succeeded >+ py_file = PyObject_CallMethod(ioMod, "open", "ss", fname, "rb"); >+ Py_DECREF(ioMod); >+#else >+ py_file = PyFile_FromString(PyString_AsString(file_arg), "r"); >+#endif >+ if (py_file == NULL) >+ return NULL; >+ } else { >+#ifdef IS_PY3K >+ // TODOpy3: is PyIOBase_Type what we really want to check? >+ int checkres = PyObject_IsInstance(file_arg, (PyObject *)&PyIOBase_Type); >+ if (checkres == -1) { >+ return NULL; >+ } else if (checkres == 1) { >+#else >+ if (PyFile_Check(file_arg)) { >+#endif >+ py_file = file_arg; >+ Py_INCREF(py_file); >+ } >+ else { >+ PyErr_SetString(PyExc_TypeError, "Bad file, must be pathname or file object"); >+ return NULL; >+ } > } > > if ((py_file_contents = PyObject_CallMethod(py_file, "read", "")) == NULL) { >@@ -2130,16 +2165,16 @@ > if (table[i].enum_description) { /* only if defined in table */ > switch(repr_kind) { > case AsEnum: >- PyTuple_SetItem(tuple, j++, PyInt_FromLong(table[i].enum_value)); >+ PyTuple_SetItem(tuple, j++, PYINTTYPE_FROMLONG(table[i].enum_value)); > break; > case AsEnumName: >- PyTuple_SetItem(tuple, j++, PyString_FromString(table[i].enum_name)); >+ PyTuple_SetItem(tuple, j++, PYSTRTYPE_FROMSTRING(table[i].enum_name)); > break; > case AsEnumDescription: >- PyTuple_SetItem(tuple, j++, PyString_FromString(table[i].enum_description)); >+ PyTuple_SetItem(tuple, j++, PYSTRTYPE_FROMSTRING(table[i].enum_description)); > break; > case AsIndex: >- PyTuple_SetItem(tuple, j++, PyInt_FromLong(i)); >+ PyTuple_SetItem(tuple, j++, PYINTTYPE_FROMLONG(i)); > break; > default: > PyErr_Format(PyExc_ValueError, "Unsupported representation kind (%d)", repr_kind); >@@ -2503,7 +2538,7 @@ > name = CERTGeneralName_type_string_to_pystr(cur); > break; > case AsTypeEnum: >- name = PyInt_FromLong(cur->type); >+ name = PYINTTYPE_FROMLONG(cur->type); > break; > case AsLabeledString: > name = CERTGeneralName_to_pystr_with_label(cur); >@@ -2769,7 +2804,7 @@ > PyObject *py_value; > int oid_tag; > >- if ((py_name = PyString_FromString(name)) == NULL) { >+ if ((py_name = PYSTRTYPE_FROMSTRING(name)) == NULL) { > return -1; > } > >@@ -2779,13 +2814,13 @@ > } > > if ((py_value = PyDict_GetItem(sec_oid_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "oid tag name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "oid tag name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_name); > Py_DECREF(py_lower_name); > return -1; > } > >- oid_tag = PyInt_AsLong(py_value); >+ oid_tag = PYINTTYPE_ASLONG(py_value); > > Py_DECREF(py_name); > Py_DECREF(py_lower_name); >@@ -2799,7 +2834,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(oid_tag)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(oid_tag)) == NULL) { > return NULL; > } > >@@ -2820,18 +2855,18 @@ > { > int oid_tag = SEC_OID_UNKNOWN; > >- if (PyString_Check(obj) || PyUnicode_Check(obj)) { >+ if (PyBytes_Check(obj) || PyUnicode_Check(obj)) { > PyObject *py_obj_string_utf8 = NULL; > char *type_string; > >- if (PyString_Check(obj)) { >+ if (PyBytes_Check(obj)) { > py_obj_string_utf8 = obj; > Py_INCREF(py_obj_string_utf8); > } else { > py_obj_string_utf8 = PyUnicode_AsUTF8String(obj); > } > >- if ((type_string = PyString_AsString(py_obj_string_utf8)) == NULL) { >+ if ((type_string = PyBytes_AsString(py_obj_string_utf8)) == NULL) { > Py_DECREF(py_obj_string_utf8); > return -1; > } >@@ -2868,8 +2903,8 @@ > } > } > Py_DECREF(py_obj_string_utf8); >- } else if (PyInt_Check(obj)) { >- oid_tag = PyInt_AsLong(obj); >+ } else if (PYINTTYPE_CHECK(obj)) { >+ oid_tag = PYINTTYPE_ASLONG(obj); > } else if (PySecItem_Check(obj)) { > oid_tag = SECOID_FindOIDTag(&((SecItem *)obj)->item); > } else { >@@ -2970,7 +3005,7 @@ > return -1; > } > >- if ((py_name = PyString_FromString(name)) == NULL) { >+ if ((py_name = PYSTRTYPE_FROMSTRING(name)) == NULL) { > return -1; > } > >@@ -2979,7 +3014,7 @@ > return -1; > } > >- if ((py_value = PyInt_FromLong(value)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(value)) == NULL) { > Py_DECREF(py_name); > Py_DECREF(py_lower_name); > return -1; >@@ -3012,7 +3047,9 @@ > if (strlen(name) > prefix_len && > strncasecmp(prefix, name, prefix_len) == 0) { > >- if ((py_name_sans_prefix = PyString_FromString(PyString_AS_STRING(py_lower_name) + prefix_len)) == NULL) { >+ // TODOpy3: I'm not sure, but I don't see a problem with using PyString_AsString >+ // in Python 2 here (the non-macro version) >+ if ((py_name_sans_prefix = PYSTRTYPE_FROMSTRING(PYSTRTYPE_ASSTRING(py_lower_name) + prefix_len)) == NULL) { > Py_DECREF(py_name); > Py_DECREF(py_lower_name); > Py_DECREF(py_value); >@@ -3136,8 +3173,8 @@ > return 1; > } > >- if (PyInt_Check(obj)) { >- LL_I2L(time, PyInt_AsLong(obj)); /* FIXME: should be PyLong_AsLongLong? */ >+ if (PYINTTYPE_CHECK(obj)) { >+ LL_I2L(time, PYINTTYPE_ASLONG(obj)); /* FIXME: should be PyLong_AsLongLong? */ > *param = time; > return 1; > } >@@ -3239,7 +3276,7 @@ > return 1; > } > >- if (PyString_Check(obj)) { >+ if (PyBytes_Check(obj)) { > Py_INCREF(obj); > *param = obj; > return 1; >@@ -3366,12 +3403,12 @@ > } > va_end(va); > >- if ((py_fmt = PyString_FromString(fmt)) == NULL) { >+ if ((py_fmt = PYSTRTYPE_FROMSTRING(fmt)) == NULL) { > Py_DECREF(args); > return NULL; > } > >- result = PyString_Format(py_fmt, args); >+ result = PYSTRTYPE_FORMAT(py_fmt, args); > Py_DECREF(py_fmt); > Py_DECREF(args); > >@@ -3420,10 +3457,10 @@ > line_size = (num_octets * 2) + ((num_octets-1) * separator_len); > if (line_size < 0) line_size = 0; > >- if ((line = PyString_FromStringAndSize(NULL, line_size)) == NULL) { >- return NULL; >- } >- dst = PyString_AS_STRING(line); >+ if ((line = PyBytes_FromStringAndSize(NULL, line_size)) == NULL) { >+ return NULL; >+ } >+ dst = PyBytes_AS_STRING(line); > for (i = 0; i < data_len; i++) { > octet = data[i]; > *dst++ = hex_chars[(octet & 0xF0) >> 4]; >@@ -3431,6 +3468,16 @@ > if (i < data_len-1) > for (src = separator; src < separator_end; *dst++ = *src++); > } >+#ifdef IS_PY3K >+ { >+ PyObject *ret = PyUnicode_FromEncodedObject(line, "utf-8", NULL); >+ Py_DECREF(line); >+ if (ret == NULL) { >+ return NULL; >+ } >+ line = ret; >+ } >+#endif > return line; > } else { > num_lines = (data_len + octets_per_line - 1) / octets_per_line; >@@ -3450,11 +3497,11 @@ > } > > if (line_size < 0) line_size = 0; >- if ((line = PyString_FromStringAndSize(NULL, line_size)) == NULL) { >+ if ((line = PyBytes_FromStringAndSize(NULL, line_size)) == NULL) { > Py_DECREF(lines); > return NULL; > } >- dst = PyString_AS_STRING(line); >+ dst = PyBytes_AS_STRING(line); > for (j = 0; j < num_octets && i < data_len; i++, j++) { > octet = data[i]; > *dst++ = hex_chars[(octet & 0xF0) >> 4]; >@@ -3462,6 +3509,17 @@ > if (i < data_len-1) > for (src = separator; src < separator_end; *dst++ = *src++); > } >+#ifdef IS_PY3K >+ { >+ PyObject *unicode_line = PyUnicode_FromEncodedObject(line, "utf-8", NULL); >+ Py_DECREF(line); >+ if (unicode_line == NULL) { >+ Py_DECREF(lines); >+ return NULL; >+ } >+ line = unicode_line; >+ } >+#endif > PyList_SetItem(lines, line_number++, line); > } > return lines; >@@ -3532,7 +3590,8 @@ > this string will be skipped and considered a separator\n\ > between pairs of hexadecimal characters.\n\ > \n\ >-Parse a string containing hexadecimal data and return a buffer\n\ >+Parse a string containing hexadecimal data and return a string\n\ >+(in Python 2) or bytes (in Python 3)\n\ > object containing the binary octets. Each octet in the string is\n\ > represented as a pair of case insensitive hexadecimal characters\n\ > (0123456789abcdef). Each octet must be a pair of\n\ >@@ -3648,7 +3707,7 @@ > data[n_octets++] = octet; > } > >- if ((py_out_buf = PyString_FromStringAndSize((char *)data, n_octets)) == NULL) { >+ if ((py_out_buf = PyBytes_FromStringAndSize((char *)data, n_octets)) == NULL) { > PyMem_Free(data); > return NULL; > } >@@ -3683,14 +3742,14 @@ > PyObject *py_name = NULL; > > if (!cert_name) { >- return PyString_FromString(""); >+ return PYSTRTYPE_FROMSTRING(""); > } > > if ((name = CERT_NameToAscii(cert_name)) == NULL) { >- return PyString_FromString(""); >- } >- >- py_name = PyString_FromString(name); >+ return PYSTRTYPE_FROMSTRING(""); >+ } >+ >+ py_name = PYSTRTYPE_FROMSTRING(name); > PORT_Free(name); > return py_name; > } >@@ -3706,17 +3765,17 @@ > SECItem tmp; > > if (constructed) { >- py_str = PyString_FromFormat("[%d]", type); >+ py_str = PYSTRTYPE_FROMFORMAT("[%d]", type); > } else { > tmp = *item; > if (sec_strip_tag_and_length(&tmp) == SECSuccess) { > if ((hex_str = raw_data_to_hex(tmp.data, tmp.len, 0, HEX_SEPARATOR_DEFAULT))) { >- py_str = PyString_FromFormat("[%d] %s", type, PyString_AsString(hex_str)); >+ py_str = PYSTRTYPE_FROMFORMAT("[%d] %s", type, PYSTRTYPE_ASSTRING(hex_str)); > Py_DECREF(hex_str); > } > } > if (!py_str) { >- py_str = PyString_FromFormat("[%d]", type); >+ py_str = PYSTRTYPE_FROMFORMAT("[%d]", type); > } > } > >@@ -3744,7 +3803,7 @@ > return raw_data_to_hex(item->data, item->len, 0, HEX_SEPARATOR_DEFAULT); > } > } >- return PyString_FromString("(null)"); >+ return PYSTRTYPE_FROMSTRING("(null)"); > } > > >@@ -3808,9 +3867,9 @@ > } > > if (val) >- return PyString_FromString("True"); >+ return PYSTRTYPE_FROMSTRING("True"); > else >- return PyString_FromString("False"); >+ return PYSTRTYPE_FROMSTRING("False"); > } > > static PyObject * >@@ -3844,7 +3903,7 @@ > bool negative; > > if (!item || !item->len || !item->data) { >- return PyInt_FromLong(0); >+ return PYINTTYPE_FROMLONG(0); > } > > len = item->len; >@@ -3853,21 +3912,21 @@ > negative = octet & 0x80; > > if (negative) { >- if ((l = PyInt_FromLong(-1)) == NULL) { >+ if ((l = PYINTTYPE_FROMLONG(-1)) == NULL) { > goto error; > } > } else { >- if ((l = PyInt_FromLong(0)) == NULL) { >+ if ((l = PYINTTYPE_FROMLONG(0)) == NULL) { > goto error; > } > } > >- if ((eight = PyInt_FromLong(8)) == NULL) { >+ if ((eight = PYINTTYPE_FROMLONG(8)) == NULL) { > return NULL; > } > > while (1) { >- if ((new_bits = PyInt_FromLong(octet)) == NULL) { >+ if ((new_bits = PYINTTYPE_FROMLONG(octet)) == NULL) { > goto error; > } > >@@ -3912,7 +3971,7 @@ > \ > py_long = integer_secitem_to_pylong(&item); \ > py_str = PyObject_Str(py_long); \ >- printf("expect %8s got %8s\n", expect, PyString_AsString(py_str)); \ >+ printf("expect %8s got %8s\n", expect, PYSTRTYPE_ASSTRING(py_str)); \ > Py_DECREF(py_long); \ > Py_DECREF(py_str); \ > } >@@ -3968,10 +4027,10 @@ > PyObject *py_oid_str = NULL; > > if ((oiddata = SECOID_FindOID(oid)) != NULL) { >- return PyString_FromString(oiddata->desc); >+ return PYSTRTYPE_FROMSTRING(oiddata->desc); > } > if ((oid_string = CERT_GetOidString(oid)) != NULL) { >- py_oid_str = PyString_FromString(oid_string); >+ py_oid_str = PYSTRTYPE_FROMSTRING(oid_string); > PR_smprintf_free(oid_string); > return py_oid_str; > } >@@ -3984,7 +4043,7 @@ > SECOidTag oid_tag; > > oid_tag = SECOID_FindOIDTag(oid); >- return PyInt_FromLong(oid_tag); >+ return PYINTTYPE_FROMLONG(oid_tag); > } > > static PyObject * >@@ -3994,9 +4053,9 @@ > PyObject *py_oid_string; > > if ((oid_string = CERT_GetOidString(oid)) == NULL) { >- return PyString_FromString(""); >- } >- if ((py_oid_string = PyString_FromString(oid_string)) == NULL) { >+ return PYSTRTYPE_FROMSTRING(""); >+ } >+ if ((py_oid_string = PYSTRTYPE_FROMSTRING(oid_string)) == NULL) { > PR_smprintf_free(oid_string); > return NULL; > } >@@ -4029,7 +4088,7 @@ > PR_ExplodeTime(pr_time, PR_GMTParameters, &exploded_time); > PR_FormatTime(time_str, sizeof(time_str), time_format, &exploded_time); > >- return PyString_FromString(time_str); >+ return PYSTRTYPE_FROMSTRING(time_str); > } > > >@@ -4046,7 +4105,7 @@ > PR_ExplodeTime(pr_time, PR_GMTParameters, &exploded_time); > PR_FormatTime(time_str, sizeof(time_str), time_format, &exploded_time); > >- return PyString_FromString(time_str); >+ return PYSTRTYPE_FROMSTRING(time_str); > } > > >@@ -4079,7 +4138,7 @@ > PR_ExplodeTime(pr_time, PR_GMTParameters, &exploded_time); > PR_FormatTime(time_str, sizeof(time_str), time_format, &exploded_time); > >- return PyString_FromString(time_str); >+ return PYSTRTYPE_FROMSTRING(time_str); > } > > static PyObject * >@@ -4111,7 +4170,7 @@ > str = raw_data_to_hex(tmp_item.data, tmp_item.len, 0, HEX_SEPARATOR_DEFAULT); > > if (unused_bits) { >- PyString_ConcatAndDel(&str, PyString_FromFormat("(%d least significant bits unused)", unused_bits)); >+ PYSTRTYPE_CONCATANDDEL(&str, PYSTRTYPE_FROMFORMAT("(%d least significant bits unused)", unused_bits)); > } > > return str; >@@ -4129,11 +4188,11 @@ > > escaped_len = ascii_encoded_strnlen((const char *)item->data, item->len); > >- if ((py_str = PyString_FromStringAndSize(NULL, escaped_len)) == NULL) { >- return NULL; >- } >- >- escaped_str = PyString_AS_STRING(py_str); >+ if ((py_str = PyBytes_FromStringAndSize(NULL, escaped_len)) == NULL) { >+ return NULL; >+ } >+ >+ escaped_str = PyBytes_AS_STRING(py_str); > > for (s = (unsigned char *)item->data, len = item->len, dst = escaped_str; > len; >@@ -4146,6 +4205,16 @@ > > *dst = 0; /* shouldn't be necessary, PyString's are always NULL terminated */ > >+#ifdef IS_PY3K >+ { >+ PyObject *tmp = PyUnicode_FromEncodedObject(py_str, "utf-8", NULL); >+ Py_DECREF(py_str); >+ if (tmp == NULL) >+ return NULL; >+ py_str = tmp; >+ } >+#endif >+ > return py_str; > } > >@@ -4240,7 +4309,7 @@ > case SEC_ASN1_UTC_TIME: > return der_utc_time_secitem_to_pystr(item); > case SEC_ASN1_NULL: >- return PyString_FromString("(null)"); >+ return PYSTRTYPE_FROMSTRING("(null)"); > case SEC_ASN1_SET: > case SEC_ASN1_SEQUENCE: > return der_set_or_str_secitem_to_pylist_of_pystr(item); >@@ -4332,7 +4401,7 @@ > obj = der_utc_time_secitem_to_pystr(item); > break; > case SEC_ASN1_NULL: >- obj = PyString_FromString("(null)"); >+ obj = PYSTRTYPE_FROMSTRING("(null)"); > break; > case SEC_ASN1_SET: > case SEC_ASN1_SEQUENCE: >@@ -4424,20 +4493,20 @@ > } > > FMT_LABEL_AND_APPEND(lines, _("Fingerprint (MD5)"), level, fail); >- if ((obj = PyString_FromStringAndSize(NULL, MD5_LENGTH)) == NULL) { >- goto fail; >- } >- if (PK11_HashBuf(SEC_OID_MD5, (unsigned char *)PyString_AsString(obj), >+ if ((obj = PyBytes_FromStringAndSize(NULL, MD5_LENGTH)) == NULL) { >+ goto fail; >+ } >+ if (PK11_HashBuf(SEC_OID_MD5, (unsigned char *)PyBytes_AsString(obj), > item->data, item->len) != SECSuccess) { > set_nspr_error(NULL); > } > APPEND_OBJ_TO_HEX_LINES_AND_CLEAR(lines, obj, level+1, fail); > > FMT_LABEL_AND_APPEND(lines, _("Fingerprint (SHA1)"), level, fail); >- if ((obj = PyString_FromStringAndSize(NULL, SHA1_LENGTH)) == NULL) { >- goto fail; >- } >- if (PK11_HashBuf(SEC_OID_SHA1, (unsigned char *)PyString_AsString(obj), >+ if ((obj = PyBytes_FromStringAndSize(NULL, SHA1_LENGTH)) == NULL) { >+ goto fail; >+ } >+ if (PK11_HashBuf(SEC_OID_SHA1, (unsigned char *)PyBytes_AsString(obj), > item->data, item->len) != SECSuccess) { > set_nspr_error(NULL); > } >@@ -4459,31 +4528,32 @@ > case certOtherName: { > PyObject *py_oid = oid_secitem_to_pystr_desc(&general_name->name.OthName.oid); > if (py_oid) { >- PyObject *result = PyString_FromFormat(_("Other Name (%s)"), PyString_AS_STRING(py_oid)); >+ // TODOpy3: again, using non-macro form seems ok >+ PyObject *result = PYSTRTYPE_FROMFORMAT(_("Other Name (%s)"), PYSTRTYPE_ASSTRING(py_oid)); > Py_DECREF(py_oid); > return result; > } else { >- return PyString_FromString(_("Other Name")); >+ return PYSTRTYPE_FROMSTRING(_("Other Name")); > } > } > case certRFC822Name: >- return PyString_FromString(_("RFC822 Name")); >+ return PYSTRTYPE_FROMSTRING(_("RFC822 Name")); > case certDNSName: >- return PyString_FromString(_("DNS name")); >+ return PYSTRTYPE_FROMSTRING(_("DNS name")); > case certX400Address: >- return PyString_FromString(_("X400 Address")); >+ return PYSTRTYPE_FROMSTRING(_("X400 Address")); > case certDirectoryName: >- return PyString_FromString(_("Directory Name")); >+ return PYSTRTYPE_FROMSTRING(_("Directory Name")); > case certEDIPartyName: >- return PyString_FromString(_("EDI Party")); >+ return PYSTRTYPE_FROMSTRING(_("EDI Party")); > case certURI: >- return PyString_FromString(_("URI")); >+ return PYSTRTYPE_FROMSTRING(_("URI")); > case certIPAddress: >- return PyString_FromString(_("IP Address")); >+ return PYSTRTYPE_FROMSTRING(_("IP Address")); > case certRegisterID: >- return PyString_FromString(_("Registered ID")); >+ return PYSTRTYPE_FROMSTRING(_("Registered ID")); > default: >- return PyString_FromFormat(_("unknown type [%d]"), (int)general_name->type - 1); >+ return PYSTRTYPE_FROMFORMAT(_("unknown type [%d]"), (int)general_name->type - 1); > } > } > >@@ -4531,9 +4601,10 @@ > py_value = CERTGeneralName_to_pystr(general_name); > > if (py_label && py_value) { >- result = PyString_FromFormat("%s: %s", >- PyString_AS_STRING(py_label), >- PyString_AS_STRING(py_value)); >+ // TODOpy3: again, using non-macro form seems ok >+ result = PYSTRTYPE_FROMFORMAT("%s: %s", >+ PYSTRTYPE_ASSTRING(py_label), >+ PYSTRTYPE_ASSTRING(py_value)); > } else if (py_value) { > Py_INCREF(py_value); > result = py_value; >@@ -4556,7 +4627,7 @@ > SECItem *value_item; > > if (!ava) { >- return PyString_FromString(""); >+ return PYSTRTYPE_FROMSTRING(""); > } > > value_buf[0] = 0; >@@ -4593,9 +4664,9 @@ > SECITEM_FreeItem(value_item, PR_TRUE); > > /* Format "name=value" */ >- if ((result = PyString_FromFormat("%s=%s", >- attr_name ? attr_name : oid_name, >- value_buf)) == NULL) { >+ if ((result = PYSTRTYPE_FROMFORMAT("%s=%s", >+ attr_name ? attr_name : oid_name, >+ value_buf)) == NULL) { > if (oid_name) PR_smprintf_free(oid_name); > return NULL; > } >@@ -4618,7 +4689,7 @@ > SECItem *value_item; > > if (!rdn || !(avas = rdn->avas) || *avas == NULL) { >- return PyString_FromString(""); >+ return PYSTRTYPE_FROMSTRING(""); > } > > first = true; >@@ -4661,22 +4732,22 @@ > * together with a "+". Typically there is only one AVA. > */ > if (first) { >- if ((result = PyString_FromFormat("%s=%s", >- attr_name ? attr_name : oid_name, >- value_buf)) == NULL) { >+ if ((result = PYSTRTYPE_FROMFORMAT("%s=%s", >+ attr_name ? attr_name : oid_name, >+ value_buf)) == NULL) { > if (oid_name) PR_smprintf_free(oid_name); > return NULL; > } > } else { > PyObject *temp; > >- if ((temp = PyString_FromFormat("+%s=%s", >- attr_name ? attr_name : oid_name, >- value_buf)) == NULL) { >+ if ((temp = PYSTRTYPE_FROMFORMAT("+%s=%s", >+ attr_name ? attr_name : oid_name, >+ value_buf)) == NULL) { > if (oid_name) PR_smprintf_free(oid_name); > return NULL; > } >- PyString_ConcatAndDel(&result, temp); >+ PYSTRTYPE_CONCATANDDEL(&result, temp); > if (result == NULL) { > if (oid_name) PR_smprintf_free(oid_name); > return NULL; >@@ -4831,7 +4902,7 @@ > return secitem_to_pystr_hex(item); > } > >- return PyString_FromString(buf); >+ return PYSTRTYPE_FROMSTRING(buf); > } > > static PyObject * >@@ -4864,7 +4935,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->item.type); >+ return PYINTTYPE_FROMLONG(self->item.type); > } > > static PyObject * >@@ -4872,7 +4943,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->item.len); >+ return PYINTTYPE_FROMLONG(self->item.len); > } > > static PyObject * >@@ -4880,7 +4951,7 @@ > { > TraceMethodEnter(self); > >- return PyString_FromStringAndSize((const char *)self->item.data, self->item.len); >+ return PyBytes_FromStringAndSize((const char *)self->item.data, self->item.len); > } > > static >@@ -5061,7 +5132,7 @@ > PyMem_FREE(self->item.data); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(SecItem_doc, >@@ -5112,8 +5183,8 @@ > static PyObject * > SecItem_repr(SecItem *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyObject * >@@ -5129,7 +5200,7 @@ > if ((name = CERT_DerNameToAscii(&self->item)) == NULL) { > return set_nspr_error(NULL); > } >- return_value = PyString_FromString(name); >+ return_value = PYSTRTYPE_FROMSTRING(name); > PORT_Free(name); > } > break; >@@ -5142,39 +5213,56 @@ > return return_value; > } > >-static int >-SecItem_compare(SecItem *self, SecItem *other) >+static PyObject * >+SecItem_richcompare(SecItem *self, SecItem *other, int op) > { > if (!PySecItem_Check(other)) { > PyErr_SetString(PyExc_TypeError, "Bad type, must be SecItem"); >- return -1; >+ return NULL; > } > > if (self->item.data == NULL && other->item.data == NULL) { >- return 0; >- } >- >- if (self->item.len == 0 && other->item.len == 0) { >- return 0; >- } >- >- if (self->item.len > other->item.len) { >- return 1; >- } >- >- if (self->item.len < other->item.len) { >- return -1; >- } >- >- if (self->item.data != NULL && other->item.data != NULL) { >- return memcmp(self->item.data, other->item.data, self->item.len); >- } >- >- return 0; >+ switch (op) { >+ case Py_LE: case Py_EQ: case Py_GE: Py_RETURN_TRUE; >+ default: Py_RETURN_FALSE; >+ } >+ } >+ >+ // TODOpy3: is this correct? >+ return PyObject_RichCompare( >+ PyBytes_FromString((const char *)self->item.data), >+ PyBytes_FromString((const char *)other->item.data), >+ op); > } > > /* =========================== Buffer Protocol ========================== */ > >+#ifdef IS_PY3K >+static int >+SecItem_buffer_getbuf(SecItem *self, Py_buffer *view, int flags) >+{ >+ // TODOpy3: is readonly == 0 correct? >+ if (PyBuffer_FillInfo(view, (PyObject *)self, self->item.data, >+ self->item.len, 0, flags) < 0) >+ return -1; >+ >+ // TODOpy3: increment exports number (can't resize when exporting) ? >+ // see e.g. Modules/mmapmodule.c from python3 >+ // - figure out if it's needed at all >+ return 0; >+} >+ >+static void >+SecItem_buffer_releasebuf(SecItem *self, Py_buffer *view) >+{ >+ // TODOpy3: decrement exports number >+} >+ >+static PyBufferProcs SecItem_as_buffer = { >+ (getbufferproc)SecItem_buffer_getbuf, >+ (releasebufferproc)SecItem_buffer_releasebuf >+}; >+#else > static Py_ssize_t > SecItem_buffer_getbuf(PyObject *obj, Py_ssize_t index, void **ptr) > { >@@ -5201,6 +5289,7 @@ > SecItem_buffer_getsegcount, /* bf_getsegcount */ > NULL, /* bf_getcharbuffer */ > }; >+#endif > > static Py_ssize_t > SecItem_length(SecItem *self) >@@ -5218,7 +5307,7 @@ > return NULL; > } > octet = self->item.data[i]; >- return PyString_FromStringAndSize(&octet, 1); >+ return PyBytes_FromStringAndSize(&octet, 1); > } > > /* slice a[i:j] consists of octets a[i] ... a[j-1], j -- may be negative! */ >@@ -5233,7 +5322,7 @@ > j = SecItem_GET_SIZE(a); > if (j < i) > j = i; >- return PyString_FromStringAndSize((const char *)(a->item.data + i), j-i); >+ return PyBytes_FromStringAndSize((const char *)(a->item.data + i), j-i); > } > > static PyObject* >@@ -5253,21 +5342,21 @@ > unsigned char* dst; > PyObject* result; > >- if (PySlice_GetIndicesEx((PySliceObject*)item, SecItem_GET_SIZE(self), >+ if (PySlice_GetIndicesEx((PYSLICE_GETINDICESEX_ARGTYPE*)item, SecItem_GET_SIZE(self), > &start, &stop, &step, &slice_len) < 0) { > return NULL; > } > > if (slice_len <= 0) { >- return PyString_FromStringAndSize("", 0); >+ return PyBytes_FromStringAndSize("", 0); > } else if (step == 1) { >- return PyString_FromStringAndSize((char *)self->item.data + start, slice_len); >+ return PyBytes_FromStringAndSize((char *)self->item.data + start, slice_len); > } else { > src = self->item.data; >- if ((result = PyString_FromStringAndSize(NULL, slice_len)) == NULL) { >+ if ((result = PyBytes_FromStringAndSize(NULL, slice_len)) == NULL) { > return NULL; > } >- dst = (unsigned char *)PyString_AsString(result); >+ dst = (unsigned char *)PyBytes_AsString(result); > for (cur = start, i = 0; i < slice_len; cur += step, i++) { > dst[i] = src[cur]; > } >@@ -5300,8 +5389,7 @@ > }; > > static PyTypeObject SecItemType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.SecItem", /* tp_name */ > sizeof(SecItem), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -5309,7 +5397,7 @@ > 0, /* tp_print */ > 0, /* tp_getattr */ > 0, /* tp_setattr */ >- (cmpfunc)SecItem_compare, /* tp_compare */ >+ 0, /* tp_reserved */ > (reprfunc)SecItem_repr, /* tp_repr */ > 0, /* tp_as_number */ > &SecItem_as_sequence, /* tp_as_sequence */ >@@ -5324,7 +5412,7 @@ > SecItem_doc, /* tp_doc */ > 0, /* tp_traverse */ > 0, /* tp_clear */ >- 0, /* tp_richcompare */ >+ SecItem_richcompare, /* tp_richcompare */ > 0, /* tp_weaklistoffset */ > 0, /* tp_iter */ > 0, /* tp_iternext */ >@@ -5481,7 +5569,7 @@ > if (params.hashAlg) { > obj = oid_secitem_to_pystr_desc(¶ms.hashAlg->algorithm); > } else { >- obj = PyString_FromString("default, SHA-1"); >+ obj = PYSTRTYPE_FROMSTRING("default, SHA-1"); > } > FMT_OBJ_AND_APPEND(lines, _("Hash algorithm"), obj, level, fail); > Py_CLEAR(obj); >@@ -5493,11 +5581,11 @@ > ¶ms.maskAlg->parameters) == SECSuccess) { > obj1 = oid_secitem_to_pystr_desc(&mask_hash_alg.algorithm); > } else { >- obj1 = PyString_FromString("Invalid mask generation algorithm parameters"); >- } >- } else { >- obj = PyString_FromString("default, MGF1"); >- obj1 = PyString_FromString("default, SHA-1"); >+ obj1 = PYSTRTYPE_FROMSTRING("Invalid mask generation algorithm parameters"); >+ } >+ } else { >+ obj = PYSTRTYPE_FROMSTRING("default, MGF1"); >+ obj1 = PYSTRTYPE_FROMSTRING("default, SHA-1"); > } > FMT_OBJ_AND_APPEND(lines, _("Mask Algorithm"), obj, level, fail); > Py_CLEAR(obj); >@@ -5508,7 +5596,7 @@ > if (params.saltLength.data) { > obj = integer_secitem_to_pystr(¶ms.saltLength); > } else { >- obj = PyString_FromString("default, 20"); >+ obj = PYSTRTYPE_FROMSTRING("default, 20"); > } > FMT_OBJ_AND_APPEND(lines, _("Salt length"), obj, level, fail); > Py_CLEAR(obj); >@@ -5870,7 +5958,7 @@ > > AlgorithmID_clear(self); > SECOID_DestroyAlgorithmID(&self->id, PR_FALSE); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AlgorithmID_doc, >@@ -5887,13 +5975,12 @@ > static PyObject * > AlgorithmID_repr(AlgorithmID *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject AlgorithmIDType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.AlgorithmID", /* tp_name */ > sizeof(AlgorithmID), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -5977,7 +6064,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->params.keySizeInBits); >+ return PYINTTYPE_FROMLONG(self->params.keySizeInBits); > > } > >@@ -5991,13 +6078,13 @@ > return -1; > } > >- if (!PyInt_Check(value)) { >+ if (!PYINTTYPE_CHECK(value)) { > PyErr_Format(PyExc_TypeError, "key_size must be a integer, not %.200s", > Py_TYPE(value)->tp_name); > return -1; > } > >- self->params.keySizeInBits = PyInt_AsLong(value); >+ self->params.keySizeInBits = PYINTTYPE_ASLONG(value); > > return 0; > } >@@ -6007,7 +6094,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->params.keySizeInBits); >+ return PYINTTYPE_FROMLONG(self->params.keySizeInBits); > > } > >@@ -6021,13 +6108,13 @@ > return -1; > } > >- if (!PyInt_Check(value)) { >+ if (!PYINTTYPE_CHECK(value)) { > PyErr_Format(PyExc_TypeError, "public_exponent must be a integer, not %.200s", > Py_TYPE(value)->tp_name); > return -1; > } > >- self->params.pe = PyInt_AsLong(value); >+ self->params.pe = PYINTTYPE_ASLONG(value); > > return 0; > } >@@ -6075,7 +6162,7 @@ > { > TraceMethodEnter(self); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(RSAGenParams_doc, >@@ -6114,14 +6201,13 @@ > { > TraceMethodEnter(self); > >- return PyString_FromFormat("key_size=%d public_exponent=%lu", >- self->params.keySizeInBits, >- self->params.pe); >+ return PYSTRTYPE_FROMFORMAT("key_size=%d public_exponent=%lu", >+ self->params.keySizeInBits, >+ self->params.pe); > } > > static PyTypeObject RSAGenParamsType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.RSAGenParams", /* tp_name */ > sizeof(RSAGenParams), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -6306,7 +6392,7 @@ > PORT_FreeArena(self->params.arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(KEYPQGParams_doc, >@@ -6384,13 +6470,12 @@ > static PyObject * > KEYPQGParams_repr(KEYPQGParams *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject KEYPQGParamsType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.KEYPQGParams", /* tp_name */ > sizeof(KEYPQGParams), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -6617,7 +6702,7 @@ > TraceMethodEnter(self); > > RSAPublicKey_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(RSAPublicKey_doc, >@@ -6634,13 +6719,12 @@ > static PyObject * > RSAPublicKey_repr(RSAPublicKey *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject RSAPublicKeyType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.RSAPublicKey", /* tp_name */ > sizeof(RSAPublicKey), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -6848,7 +6932,7 @@ > TraceMethodEnter(self); > > DSAPublicKey_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(DSAPublicKey_doc, >@@ -6865,13 +6949,12 @@ > static PyObject * > DSAPublicKey_repr(DSAPublicKey *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject DSAPublicKeyType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.DSAPublicKey", /* tp_name */ > sizeof(DSAPublicKey), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -7117,7 +7200,7 @@ > > SignedData_clear(self); > PORT_FreeArena(self->arena, PR_FALSE); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(SignedData_doc, >@@ -7134,13 +7217,12 @@ > static PyObject * > SignedData_repr(SignedData *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject SignedDataType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.SignedData", /* tp_name */ > sizeof(SignedData), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -7238,7 +7320,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->pk->keyType); >+ return PYINTTYPE_FROMLONG(self->pk->keyType); > } > > static PyObject * >@@ -7246,7 +7328,7 @@ > { > TraceMethodEnter(self); > >- return PyString_FromString(key_type_str(self->pk->keyType)); >+ return PYSTRTYPE_FROMSTRING(key_type_str(self->pk->keyType)); > } > > static PyObject * >@@ -7416,7 +7498,7 @@ > > PublicKey_clear(self); > SECKEY_DestroyPublicKey(self->pk); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PublicKey_doc, >@@ -7433,13 +7515,12 @@ > static PyObject * > PublicKey_repr(PublicKey *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject PublicKeyType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PublicKey", /* tp_name */ > sizeof(PublicKey), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -7664,7 +7745,7 @@ > TraceMethodEnter(self); > > SubjectPublicKeyInfo_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(SubjectPublicKeyInfo_doc, >@@ -7681,13 +7762,12 @@ > static PyObject * > SubjectPublicKeyInfo_repr(SubjectPublicKeyInfo *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject SubjectPublicKeyInfoType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.SubjectPublicKeyInfo", /* tp_name */ > sizeof(SubjectPublicKeyInfo), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -7963,7 +8043,7 @@ > { > TraceMethodEnter(self); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertDB_doc, >@@ -7977,8 +8057,7 @@ > } > > static PyTypeObject CertDBType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertDB", /* tp_name */ > sizeof(CertDB), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -8355,7 +8434,7 @@ > TraceMethodEnter(self); > > CertificateExtension_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertificateExtension_doc, >@@ -8369,8 +8448,7 @@ > } > > static PyTypeObject CertificateExtensionType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertificateExtension", /* tp_name */ > sizeof(CertificateExtension), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -8510,7 +8588,7 @@ > Py_RETURN_NONE; > } > >- py_cn = PyString_FromString(cn); >+ py_cn = PYSTRTYPE_FROMSTRING(cn); > PORT_Free(cn); > > return py_cn; >@@ -8565,7 +8643,7 @@ > TraceMethodEnter(self); > > der = self->cert->derCert; >- return PyString_FromStringAndSize((char *)der.data, der.len); >+ return PyBytes_FromStringAndSize((char *)der.data, der.len); > } > > static PyObject * >@@ -8621,7 +8699,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->cert->nsCertType); >+ return PYINTTYPE_FROMLONG(self->cert->nsCertType); > } > > static >@@ -8706,7 +8784,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(NSS_FindCertKEAType(self->cert)); >+ return PYINTTYPE_FROMLONG(NSS_FindCertKEAType(self->cert)); > } > > >@@ -8751,7 +8829,7 @@ > return set_nspr_error(NULL); > } > >- py_nickname = PyString_FromString(nickname); >+ py_nickname = PYSTRTYPE_FROMSTRING(nickname); > PR_smprintf_free(nickname); > return py_nickname; > } >@@ -8889,7 +8967,7 @@ > > validity = CERT_CheckCertValidTimes(self->cert, pr_time, allow_override); > >- return PyInt_FromLong(validity); >+ return PYINTTYPE_FROMLONG(validity); > } > > PyDoc_STRVAR(Certificate_is_ca_cert_doc, >@@ -9023,7 +9101,7 @@ > Py_END_ALLOW_THREADS > Py_DECREF(pin_args); > >- return PyInt_FromLong(returned_usages); >+ return PYINTTYPE_FROMLONG(returned_usages); > } > > PyDoc_STRVAR(Certificate_verify_doc, >@@ -9135,7 +9213,7 @@ > Py_END_ALLOW_THREADS > Py_DECREF(pin_args); > >- return PyInt_FromLong(returned_usages); >+ return PYINTTYPE_FROMLONG(returned_usages); > } > > PyDoc_STRVAR(Certificate_verify_with_log_doc, >@@ -9438,7 +9516,7 @@ > py_oid_name = PyObject_Str(py_oid); > } > PyErr_Format(PyExc_KeyError, "no extension with OID %s found", >- PyString_AsString(py_oid_name)); >+ PYSTRTYPE_ASSTRING(py_oid_name)); > Py_DECREF(py_oid_name); > return NULL; > } >@@ -9558,7 +9636,7 @@ > if ((obj = Certificate_get_version(self, NULL)) == NULL) { > goto fail; > } >- if ((obj1 = PyInt_FromLong(1)) == NULL) { >+ if ((obj1 = PYINTTYPE_FROMLONG(1)) == NULL) { > goto fail; > } > if ((obj2 = PyNumber_Add(obj, obj1)) == NULL) { >@@ -9630,7 +9708,7 @@ > } > > len = PyTuple_Size(extensions); >- if ((obj = PyString_FromFormat("Signed Extensions: (%zd total)", len)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Signed Extensions: (%zd total)", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+1, fail); >@@ -9769,7 +9847,7 @@ > CERT_DestroyCertificate(self->cert); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(Certificate_doc, >@@ -9838,7 +9916,7 @@ > if (CERT_ImportCerts(certdb_handle, certUsageUserCertImport, > n_certs, &der_certs, &certs, > perm, PR_FALSE, >- py_nickname ? PyString_AsString(py_nickname) : NULL) != SECSuccess) { >+ py_nickname ? PYSTRTYPE_ASSTRING(py_nickname) : NULL) != SECSuccess) { > Py_BLOCK_THREADS > set_nspr_error(NULL); > result = -1; >@@ -9869,13 +9947,12 @@ > static PyObject * > Certificate_repr(Certificate *self) > { >- return PyString_FromFormat("<%s object at %p Certificate %p>", >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p Certificate %p>", > Py_TYPE(self)->tp_name, self, self->cert); > } > > static PyTypeObject CertificateType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.Certificate", /* tp_name */ > sizeof(Certificate), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -10044,7 +10121,7 @@ > if (self->private_key) > SECKEY_DestroyPrivateKey(self->private_key); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PrivateKey_doc, >@@ -10058,8 +10135,7 @@ > } > > static PyTypeObject PrivateKeyType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PrivateKey", /* tp_name */ > sizeof(PrivateKey), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -10182,7 +10258,7 @@ > if (self->signed_crl) > SEC_DestroyCrl(self->signed_crl); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(SignedCRL_doc, >@@ -10196,8 +10272,7 @@ > } > > static PyTypeObject SignedCRLType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.SignedCRL", /* tp_name */ > sizeof(SignedCRL), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -10282,7 +10357,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(CERT_GetAVATag(self->ava)); >+ return PYINTTYPE_FROMLONG(CERT_GetAVATag(self->ava)); > } > > static PyObject * >@@ -10360,28 +10435,38 @@ > return -2; > } > >- int_cmp_result = strcasecmp(PyString_AS_STRING(a_val_str), >- PyString_AS_STRING(b_val_str)); >+ // TODOpy3: again, using non-macro form seems ok >+ int_cmp_result = strcasecmp(PYSTRTYPE_ASSTRING(a_val_str), >+ PYSTRTYPE_ASSTRING(b_val_str)); > Py_DECREF(a_val_str); > Py_DECREF(b_val_str); > return (int_cmp_result == 0) ? 0 : ((int_cmp_result < 0) ? -1 : 1); > } > >-static int >-AVA_compare(AVA *self, AVA *other) >-{ >- int cmp_result; >+static PyObject * >+AVA_richcompare(AVA *self, AVA *other, int op) >+{ >+ int cmp_result, cmp = 0; >+ PyObject *res; > > if (!PyAVA_Check(other)) { > PyErr_SetString(PyExc_TypeError, "Bad type, must be AVA"); >- return -1; >+ return NULL; > } > > cmp_result = CERTAVA_compare(self->ava, other->ava); >- if (cmp_result == -2) { >- return -1; >- } >- return cmp_result; >+ switch (op) { >+ case Py_EQ: cmp = cmp_result == 0; break; >+ case Py_NE: cmp = cmp_result != 0; break; >+ case Py_LT: cmp = cmp_result < 0; break; >+ case Py_LE: cmp = cmp_result <= 0; break; >+ case Py_GT: cmp = cmp_result > 0; break; >+ case Py_GE: cmp = cmp_result >= 0; break; >+ } >+ >+ res = cmp ? Py_True : Py_False; >+ Py_INCREF(res); >+ return res; > } > > static PyMethodDef AVA_methods[] = { >@@ -10421,7 +10506,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AVA_doc, >@@ -10501,20 +10586,20 @@ > if (oid_tag == SEC_OID_UNKNOWN) { > PyObject *type_str = PyObject_Str(py_type); > PyErr_Format(PyExc_ValueError, "unable to convert \"%s\" to known OID", >- PyString_AsString(type_str)); >+ PYSTRTYPE_ASSTRING(type_str)); > Py_DECREF(type_str); > return -1; > } > >- if (PyString_Check(py_value) || PyUnicode_Check(py_value)) { >- if (PyString_Check(py_value)) { >+ if (PyBytes_Check(py_value) || PyUnicode_Check(py_value)) { >+ if (PyBytes_Check(py_value)) { > py_value_utf8 = py_value; > Py_INCREF(py_value_utf8); > } else { > py_value_utf8 = PyUnicode_AsUTF8String(py_value); > } > >- if ((value_string = PyString_AsString(py_value_utf8)) == NULL) { >+ if ((value_string = PyBytes_AsString(py_value_utf8)) == NULL) { > Py_DECREF(py_value_utf8); > return -1; > } >@@ -10542,15 +10627,14 @@ > PyObject *py_value_str; > > if ((py_value_str = CERTAVA_value_to_pystr(self->ava)) == NULL) { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > return py_value_str; > } > > static PyTypeObject AVAType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.AVA", /* tp_name */ > sizeof(AVA), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -10558,7 +10642,7 @@ > 0, /* tp_print */ > 0, /* tp_getattr */ > 0, /* tp_setattr */ >- (cmpfunc)AVA_compare, /* tp_compare */ >+ 0, /* tp_reserved */ > (reprfunc)AVA_repr, /* tp_repr */ > 0, /* tp_as_number */ > 0, /* tp_as_sequence */ >@@ -10573,7 +10657,7 @@ > AVA_doc, /* tp_doc */ > 0, /* tp_traverse */ > 0, /* tp_clear */ >- 0, /* tp_richcompare */ >+ AVA_richcompare, /* tp_richcompare */ > 0, /* tp_weaklistoffset */ > 0, /* tp_iter */ > 0, /* tp_iternext */ >@@ -10683,21 +10767,31 @@ > return 0; > } > >-static int >-RDN_compare(RDN *self, RDN *other) >-{ >- int cmp_result; >+static PyObject * >+RDN_richcompare(RDN *self, RDN *other, int op) >+{ >+ int cmp_result, cmp = 0; >+ PyObject *res; > > if (!PyRDN_Check(other)) { > PyErr_SetString(PyExc_TypeError, "Bad type, must be RDN"); >- return -1; >+ return NULL; > } > > cmp_result = CERTRDN_compare(self->rdn, other->rdn); >- if (cmp_result == -2) { >- return -1; >- } >- return cmp_result; >+ // TODOpy3: is this correct? >+ switch (op) { >+ case Py_EQ: cmp = cmp_result == 0; break; >+ case Py_NE: cmp = cmp_result != 0; break; >+ case Py_LT: cmp = cmp_result < 0; break; >+ case Py_LE: cmp = cmp_result <= 0; break; >+ case Py_GT: cmp = cmp_result > 0; break; >+ case Py_GE: cmp = cmp_result >= 0; break; >+ } >+ >+ res = cmp ? Py_True : Py_False; >+ Py_INCREF(res); >+ return res; > } > > PyDoc_STRVAR(RDN_has_key_doc, >@@ -10838,7 +10932,7 @@ > Py_ssize_t start, stop, step, slicelength, cur, i; > PyObject* py_ava; > >- if (PySlice_GetIndicesEx((PySliceObject*)item, RDN_length(self), >+ if (PySlice_GetIndicesEx((PYSLICE_GETINDICESEX_ARGTYPE*)item, RDN_length(self), > &start, &stop, &step, &slicelength) < 0) { > return NULL; > } >@@ -10860,7 +10954,7 @@ > } > return result; > } >- } else if (PyString_Check(item) || PyUnicode_Check(item) || PySecItem_Check(item)) { >+ } else if (PyBytes_Check(item) || PyUnicode_Check(item) || PySecItem_Check(item)) { > int oid_tag; > > if ((oid_tag = get_oid_tag_from_object(item)) == -1) { >@@ -10868,8 +10962,9 @@ > } > > if (oid_tag == SEC_OID_UNKNOWN) { >- if (PyString_Check(item) || PyUnicode_Check(item)) { >- char *name = PyString_AsString(item); >+ if (PyBytes_Check(item) || PyUnicode_Check(item)) { >+ char *name = >+ PyBytes_Check(item) ? PyBytes_AsString(item) : PYUNICODE_ASUTF8(item); > PyErr_Format(PyExc_KeyError, "oid name unknown: \"%s\"", name); > return NULL; > } else { >@@ -10884,8 +10979,9 @@ > > if (PyList_Size(result) == 0) { > Py_DECREF(result); >- if (PyString_Check(item) || PyUnicode_Check(item)) { >- char *name = PyString_AsString(item); >+ if (PyBytes_Check(item) || PyUnicode_Check(item)) { >+ char *name = >+ PyBytes_Check(item) ? PyBytes_AsString(item) : PYUNICODE_ASUTF8(item); > PyErr_Format(PyExc_KeyError, "oid name not found: \"%s\"", name); > return NULL; > } else { >@@ -10949,7 +11045,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(RDN_doc, >@@ -11086,8 +11182,7 @@ > }; > > static PyTypeObject RDNType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.RDN", /* tp_name */ > sizeof(RDN), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -11095,7 +11190,7 @@ > 0, /* tp_print */ > 0, /* tp_getattr */ > 0, /* tp_setattr */ >- (cmpfunc)RDN_compare, /* tp_compare */ >+ 0, /* tp_reserved */ > (reprfunc)RDN_repr, /* tp_repr */ > 0, /* tp_as_number */ > &RDN_as_sequence, /* tp_as_sequence */ >@@ -11110,7 +11205,7 @@ > RDN_doc, /* tp_doc */ > 0, /* tp_traverse */ > 0, /* tp_clear */ >- 0, /* tp_richcompare */ >+ RDN_richcompare, /* tp_richcompare */ > 0, /* tp_weaklistoffset */ > 0, /* tp_iter */ > 0, /* tp_iternext */ >@@ -11279,7 +11374,7 @@ > Py_ssize_t start, stop, step, slicelength, cur, i; > PyObject* py_ava; > >- if (PySlice_GetIndicesEx((PySliceObject*)item, DN_length(self), >+ if (PySlice_GetIndicesEx((PYSLICE_GETINDICESEX_ARGTYPE*)item, DN_length(self), > &start, &stop, &step, &slicelength) < 0) { > return NULL; > } >@@ -11301,7 +11396,7 @@ > } > return result; > } >- } else if (PyString_Check(item) || PyUnicode_Check(item) || PySecItem_Check(item)) { >+ } else if (PyBytes_Check(item) || PyUnicode_Check(item) || PySecItem_Check(item)) { > int oid_tag; > > if ((oid_tag = get_oid_tag_from_object(item)) == -1) { >@@ -11309,8 +11404,9 @@ > } > > if (oid_tag == SEC_OID_UNKNOWN) { >- if (PyString_Check(item) || PyUnicode_Check(item)) { >- char *name = PyString_AsString(item); >+ if (PyBytes_Check(item) || PyUnicode_Check(item)) { >+ char *name = >+ PyBytes_Check(item) ? PyBytes_AsString(item) : PYUNICODE_ASUTF8(item); > PyErr_Format(PyExc_KeyError, "oid name unknown: \"%s\"", name); > return NULL; > } else { >@@ -11325,8 +11421,9 @@ > > if (PyList_Size(result) == 0) { > Py_DECREF(result); >- if (PyString_Check(item) || PyUnicode_Check(item)) { >- char *name = PyString_AsString(item); >+ if (PyBytes_Check(item) || PyUnicode_Check(item)) { >+ char *name = >+ PyBytes_Check(item) ? PyBytes_AsString(item) : PYUNICODE_ASUTF8(item); > PyErr_Format(PyExc_KeyError, "oid name not found: \"%s\"", name); > return NULL; > } else { >@@ -11432,7 +11529,7 @@ > if ((value = CERT_GetCertEmailAddress(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11445,7 +11542,7 @@ > if ((value = CERT_GetCommonName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11458,7 +11555,7 @@ > if ((value = CERT_GetCountryName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11471,7 +11568,7 @@ > if ((value = CERT_GetLocalityName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11484,7 +11581,7 @@ > if ((value = CERT_GetStateName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11497,7 +11594,7 @@ > if ((value = CERT_GetOrgName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11510,7 +11607,7 @@ > if ((value = CERT_GetOrgUnitName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11523,7 +11620,7 @@ > if ((value = CERT_GetDomainComponentName(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static PyObject * >@@ -11536,7 +11633,7 @@ > if ((value = CERT_GetCertUid(&self->name)) == NULL) { > Py_RETURN_NONE; > } >- return PyString_FromString(value); >+ return PYSTRTYPE_FROMSTRING(value); > } > > static >@@ -11568,15 +11665,31 @@ > > /* ============================== Class Methods ============================= */ > >-static int >-DN_compare(DN *self, DN *other) >-{ >+static PyObject * >+DN_richcompare(DN *self, DN *other, int op) >+{ >+ int cmp_result, cmp = 0; >+ PyObject *res; >+ > if (!PyDN_Check(other)) { > PyErr_SetString(PyExc_TypeError, "Bad type, must be DN"); >- return -1; >- } >- >- return CERT_CompareName(&self->name, &other->name); >+ return NULL; >+ } >+ >+ cmp_result = CERT_CompareName(&self->name, &other->name); >+ // TODOpy3: is this correct? >+ switch (op) { >+ case Py_EQ: cmp = cmp_result == 0; break; >+ case Py_NE: cmp = cmp_result != 0; break; >+ case Py_LT: cmp = cmp_result < 0; break; >+ case Py_LE: cmp = cmp_result <= 0; break; >+ case Py_GT: cmp = cmp_result > 0; break; >+ case Py_GE: cmp = cmp_result >= 0; break; >+ } >+ >+ res = cmp ? Py_True : Py_False; >+ Py_INCREF(res); >+ return res; > } > > PyDoc_STRVAR(DN_add_rdn_doc, >@@ -11648,7 +11761,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(DN_doc, >@@ -11771,10 +11884,11 @@ > > if (PyTuple_GET_SIZE(args) > 0) { > item = PyTuple_GetItem(args, 0); >- if (PyString_Check(item) || PyUnicode_Check(item)) { >- char *ascii_name; >- >- if ((ascii_name = PyString_AsString(item)) == NULL) { >+ if (PyBytes_Check(item) || PyUnicode_Check(item)) { >+ char *ascii_name = >+ PyBytes_Check(item) ? PyBytes_AsString(item) : PYUNICODE_ASUTF8(item); >+ >+ if (ascii_name == NULL) { > return -1; > } > >@@ -11879,8 +11993,7 @@ > }; > > static PyTypeObject DNType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.DN", /* tp_name */ > sizeof(DN), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -11888,7 +12001,7 @@ > 0, /* tp_print */ > 0, /* tp_getattr */ > 0, /* tp_setattr */ >- (cmpfunc)DN_compare, /* tp_compare */ >+ 0, /* tp_reserved */ > (reprfunc)DN_repr, /* tp_repr */ > 0, /* tp_as_number */ > &DN_as_sequence, /* tp_as_sequence */ >@@ -11903,7 +12016,7 @@ > DN_doc, /* tp_doc */ > 0, /* tp_traverse */ > 0, /* tp_clear */ >- 0, /* tp_richcompare */ >+ DN_richcompare, /* tp_richcompare */ > 0, /* tp_weaklistoffset */ > 0, /* tp_iter */ > 0, /* tp_iternext */ >@@ -11973,7 +12086,7 @@ > if (!self->name) { > return PyErr_Format(PyExc_ValueError, "%s is uninitialized", Py_TYPE(self)->tp_name); > } >- return PyInt_FromLong(self->name->type); >+ return PYINTTYPE_FROMLONG(self->name->type); > } > > static PyObject * >@@ -12073,7 +12186,7 @@ > name = CERTGeneralName_type_string_to_pystr(self->name); > break; > case AsTypeEnum: >- name = PyInt_FromLong(self->name->type); >+ name = PYINTTYPE_FROMLONG(self->name->type); > break; > case AsLabeledString: > name = CERTGeneralName_to_pystr_with_label(self->name); >@@ -12124,7 +12237,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(GeneralName_doc, >@@ -12162,8 +12275,8 @@ > } > > if ((result = CERTGeneralName_to_pystr_with_label(self->name)) == NULL) { >- result = PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ result = PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > return result; >@@ -12218,8 +12331,7 @@ > }; > > static PyTypeObject GeneralNameType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.GeneralName", /* tp_name */ > sizeof(GeneralName), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -12378,7 +12490,7 @@ > } > > for (i = 0; i < len; i++) { >- if ((py_nickname = PyString_FromString(cert_nicknames->nicknames[i])) == NULL) { >+ if ((py_nickname = PYSTRTYPE_FROMSTRING(cert_nicknames->nicknames[i])) == NULL) { > CERT_FreeNicknames(cert_nicknames); > return NULL; > } >@@ -12397,7 +12509,7 @@ > hash_alg : int\n\ > hash algorithm enumeration (SEC_OID_*)\n\ > e.g.: SEC_OID_MD5, SEC_OID_SHA1, SEC_OID_SHA256, SEC_OID_SHA512, etc.\n\ >- data : buffer or string\n\ >+ data : buffer or string in Python 2, bytes in Python 3\n\ > buffer the digest will be computed for\n\ > \n\ > Computes a digest according to the hash_alg type.\n\ >@@ -12419,7 +12531,7 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "kt#:hash_buf", >+ if (!PyArg_ParseTuple(args, "k" BYTES_FORMAT_STRING ":hash_buf", > &hash_alg, &in_data, &in_data_len)) { > return NULL; > } >@@ -12431,11 +12543,11 @@ > > out_buf_len = hash_len; > >- if ((py_out_buf = PyString_FromStringAndSize(NULL, out_buf_len)) == NULL) { >- return NULL; >- } >- >- if ((out_buf = PyString_AsString(py_out_buf)) == NULL) { >+ if ((py_out_buf = PyBytes_FromStringAndSize(NULL, out_buf_len)) == NULL) { >+ return NULL; >+ } >+ >+ if ((out_buf = PyBytes_AsString(py_out_buf)) == NULL) { > return NULL; > } > >@@ -12450,7 +12562,7 @@ > "md5_digest(data) --> digest\n\ > \n\ > :Parameters:\n\ >- data : buffer or string\n\ >+ data : buffer or string in Python 2, bytes in Python 3\n\ > buffer the digest will be computed for\n\ > \n\ > Returns 16 octet MD5 digest data as buffer object.\n\ >@@ -12468,15 +12580,15 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:md5_digest", &in_data, &in_data_len)) { >- return NULL; >- } >- >- if ((py_out_buf = PyString_FromStringAndSize(NULL, MD5_LENGTH)) == NULL) { >- return NULL; >- } >- >- if ((out_buf = PyString_AsString(py_out_buf)) == NULL) { >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":md5_digest", &in_data, &in_data_len)) { >+ return NULL; >+ } >+ >+ if ((py_out_buf = PyBytes_FromStringAndSize(NULL, MD5_LENGTH)) == NULL) { >+ return NULL; >+ } >+ >+ if ((out_buf = PyBytes_AsString(py_out_buf)) == NULL) { > return NULL; > } > >@@ -12491,7 +12603,7 @@ > "sha1_digest(data) --> digest\n\ > \n\ > :Parameters:\n\ >- data : buffer or string\n\ >+ data : buffer or string in Python 2, bytes in Python 3\n\ > buffer the digest will be computed for\n\ > \n\ > Returns 20 octet SHA1 digest data as buffer object.\n\ >@@ -12509,15 +12621,15 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:sha1_digest", &in_data, &in_data_len)) { >- return NULL; >- } >- >- if ((py_out_buf = PyString_FromStringAndSize(NULL, SHA1_LENGTH)) == NULL) { >- return NULL; >- } >- >- if ((out_buf = PyString_AsString(py_out_buf)) == NULL) { >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":sha1_digest", &in_data, &in_data_len)) { >+ return NULL; >+ } >+ >+ if ((py_out_buf = PyBytes_FromStringAndSize(NULL, SHA1_LENGTH)) == NULL) { >+ return NULL; >+ } >+ >+ if ((out_buf = PyBytes_AsString(py_out_buf)) == NULL) { > return NULL; > } > >@@ -12532,7 +12644,7 @@ > "sha256_digest(data) --> digest\n\ > \n\ > :Parameters:\n\ >- data : buffer or string\n\ >+ data : buffer or string in Python 2, bytes in Python 3\n\ > buffer the digest will be computed for\n\ > \n\ > Returns 32 octet SHA256 digest data as buffer object.\n\ >@@ -12551,15 +12663,15 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:sha256_digest", &in_data, &in_data_len)) { >- return NULL; >- } >- >- if ((py_out_buf = PyString_FromStringAndSize(NULL, SHA256_LENGTH)) == NULL) { >- return NULL; >- } >- >- if ((out_buf = PyString_AsString(py_out_buf)) == NULL) { >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":sha256_digest", &in_data, &in_data_len)) { >+ return NULL; >+ } >+ >+ if ((py_out_buf = PyBytes_FromStringAndSize(NULL, SHA256_LENGTH)) == NULL) { >+ return NULL; >+ } >+ >+ if ((out_buf = PyBytes_AsString(py_out_buf)) == NULL) { > return NULL; > } > >@@ -12574,7 +12686,7 @@ > "sha512_digest(data) --> digest\n\ > \n\ > :Parameters:\n\ >- data : buffer or string\n\ >+ data : buffer or string in Python 2, bytes in Python 3\n\ > buffer the digest will be computed for\n\ > \n\ > Returns 64 octet SHA512 digest data as buffer object.\n\ >@@ -12592,15 +12704,15 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:sha512_digest", &in_data, &in_data_len)) { >- return NULL; >- } >- >- if ((py_out_buf = PyString_FromStringAndSize(NULL, SHA512_LENGTH)) == NULL) { >- return NULL; >- } >- >- if ((out_buf = PyString_AsString(py_out_buf)) == NULL) { >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":sha512_digest", &in_data, &in_data_len)) { >+ return NULL; >+ } >+ >+ if ((py_out_buf = PyBytes_FromStringAndSize(NULL, SHA512_LENGTH)) == NULL) { >+ return NULL; >+ } >+ >+ if ((out_buf = PyBytes_AsString(py_out_buf)) == NULL) { > return NULL; > } > >@@ -12628,7 +12740,7 @@ > Py_RETURN_NONE; > } > >- return PyString_FromString(slot_name); >+ return PYSTRTYPE_FROMSTRING(slot_name); > } > > static PyObject * >@@ -12642,7 +12754,7 @@ > Py_RETURN_NONE; > } > >- return PyString_FromString(token_name); >+ return PYSTRTYPE_FROMSTRING(token_name); > } > > static >@@ -12872,7 +12984,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(PK11_GetDisabledReason(self->slot)); >+ return PYINTTYPE_FROMLONG(PK11_GetDisabledReason(self->slot)); > } > > PyDoc_STRVAR(PK11Slot_user_disable_doc, >@@ -13040,7 +13152,7 @@ > TraceMethodEnter(self); > > mechanism = PK11_GetBestWrapMechanism(self->slot); >- return PyInt_FromLong(mechanism); >+ return PYINTTYPE_FROMLONG(mechanism); > } > > >@@ -13068,7 +13180,7 @@ > return NULL; > > length = PK11_GetBestKeyLength(self->slot, mechanism); >- return PyInt_FromLong(length); >+ return PYINTTYPE_FROMLONG(length); > } > > PyDoc_STRVAR(PK11Slot_key_gen_doc, >@@ -13209,7 +13321,7 @@ > PyObject *mechanism_name = key_mechanism_type_to_pystr(mechanism); > > PyErr_Format(PyExc_TypeError, "key_params for %s mechanism must be %.50s, not %.50s", >- mechanism_name ? PyString_AsString(mechanism_name) : "unknown", >+ mechanism_name ? PYSTRTYPE_ASSTRING(mechanism_name) : "unknown", > RSAGenParamsType.tp_name, Py_TYPE(py_key_params)->tp_name); > Py_XDECREF(mechanism_name); > goto fail; >@@ -13221,7 +13333,7 @@ > PyObject *mechanism_name = key_mechanism_type_to_pystr(mechanism); > > PyErr_Format(PyExc_TypeError, "key_params for %s mechanism must be %.50s, not %.50s", >- mechanism_name ? PyString_AsString(mechanism_name) : "unknown", >+ mechanism_name ? PYSTRTYPE_ASSTRING(mechanism_name) : "unknown", > KEYPQGParamsType.tp_name, Py_TYPE(py_key_params)->tp_name); > Py_XDECREF(mechanism_name); > goto fail; >@@ -13346,7 +13458,7 @@ > if (NSS_IsInitialized()) { > PK11_FreeSlot(self->slot); > } >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PK11Slot_doc, >@@ -13366,8 +13478,7 @@ > } > > static PyTypeObject PK11SlotType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PK11Slot", /* tp_name */ > sizeof(PK11Slot), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -13435,7 +13546,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(PK11_GetMechanism(self->pk11_sym_key)); >+ return PYINTTYPE_FROMLONG(PK11_GetMechanism(self->pk11_sym_key)); > } > > static PyObject * >@@ -13450,10 +13561,10 @@ > } > > if ((sec_item = PK11_GetKeyData(self->pk11_sym_key)) == NULL) { >- return PyString_FromStringAndSize("", 0); >- } >- >- return PyString_FromStringAndSize((const char *)sec_item->data, sec_item->len); >+ return PyBytes_FromStringAndSize("", 0); >+ } >+ >+ return PyBytes_FromStringAndSize((const char *)sec_item->data, sec_item->len); > } > > static PyObject * >@@ -13461,7 +13572,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(PK11_GetKeyLength(self->pk11_sym_key)); >+ return PYINTTYPE_FROMLONG(PK11_GetKeyLength(self->pk11_sym_key)); > } > > static PyObject * >@@ -13633,8 +13744,8 @@ > static PyObject * > PK11SymKey_repr(PyPK11SymKey *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyObject * >@@ -13661,7 +13772,7 @@ > PK11_FreeSymKey(self->pk11_sym_key); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PK11SymKey_doc, >@@ -13676,8 +13787,7 @@ > } > > static PyTypeObject PK11SymKeyType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PK11SymKey", /* tp_name */ > sizeof(PyPK11SymKey), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -13843,7 +13953,7 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:digest_op", &buffer, &buffer_len)) >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":digest_op", &buffer, &buffer_len)) > return NULL; > > if (PK11_DigestOp(self->pk11_context, buffer, buffer_len) != SECSuccess) { >@@ -13856,7 +13966,8 @@ > PyDoc_STRVAR(PK11Context_cipher_op_doc, > "cipher_op(data) -> data\n\ > :Parameters:\n\ >- data : any read buffer compatible object (e.g. buffer or string)\n\ >+ data : any read buffer compatible object (e.g. buffer or string\n\ >+ in Python 2, bytes in Python 3)\n\ > raw data to compute digest from\n\ > \n\ > Execute a digest/signature operation.\n\ >@@ -13873,7 +13984,7 @@ > > TraceMethodEnter(self); > >- if (!PyArg_ParseTuple(args, "t#:cipher_op", &in_buf, &in_buf_len)) >+ if (!PyArg_ParseTuple(args, BYTES_FORMAT_STRING ":cipher_op", &in_buf, &in_buf_len)) > return NULL; > > /* >@@ -13897,10 +14008,10 @@ > > out_buf_alloc_len = suggested_out_len; > >- if ((py_out_string = PyString_FromStringAndSize(NULL, out_buf_alloc_len)) == NULL) { >- return NULL; >- } >- out_buf = PyString_AsString(py_out_string); >+ if ((py_out_string = PyBytes_FromStringAndSize(NULL, out_buf_alloc_len)) == NULL) { >+ return NULL; >+ } >+ out_buf = PyBytes_AsString(py_out_string); > > /* > * Now that we have both the input and output buffers perform the cipher operation. >@@ -13912,7 +14023,7 @@ > } > > if (actual_out_len != out_buf_alloc_len) { >- if (_PyString_Resize(&py_out_string, actual_out_len) < 0) { >+ if (_PyBytes_Resize(&py_out_string, actual_out_len) < 0) { > return NULL; > } > } >@@ -13979,10 +14090,10 @@ > > out_buf_alloc_len = suggested_out_len; > >- if ((py_out_string = PyString_FromStringAndSize(NULL, out_buf_alloc_len)) == NULL) { >- return NULL; >- } >- out_buf = PyString_AsString(py_out_string); >+ if ((py_out_string = PyBytes_FromStringAndSize(NULL, out_buf_alloc_len)) == NULL) { >+ return NULL; >+ } >+ out_buf = PyBytes_AsString(py_out_string); > > /* > * Now that we have the output buffer perform the cipher operation. >@@ -13994,7 +14105,7 @@ > } > > if (actual_out_len != out_buf_alloc_len) { >- if (_PyString_Resize(&py_out_string, actual_out_len) < 0) { >+ if (_PyBytes_Resize(&py_out_string, actual_out_len) < 0) { > return NULL; > } > } >@@ -14005,8 +14116,8 @@ > static PyObject * > PK11Context_repr(PyPK11Context *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyObject * >@@ -14054,7 +14165,7 @@ > PK11_DestroyContext(self->pk11_context, PR_TRUE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PK11Context_doc, >@@ -14069,8 +14180,7 @@ > } > > static PyTypeObject PK11ContextType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PK11Context", /* tp_name */ > sizeof(PyPK11Context), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -14272,7 +14382,7 @@ > } > len = PyTuple_GET_SIZE(obj); > >- if ((obj1 = PyString_FromFormat("General Names: [%zd total]", len)) == NULL) { >+ if ((obj1 = PYSTRTYPE_FROMFORMAT("General Names: [%zd total]", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj1, level, fail); >@@ -14353,11 +14463,11 @@ > PyObject *sep = NULL; > > if (!self->pt) { >- return PyString_FromFormat("<%s object at %p>", >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", > Py_TYPE(self)->tp_name, self); > } > >- if ((sep = PyString_FromString(", ")) == NULL) { >+ if ((sep = PYSTRTYPE_FROMSTRING(", ")) == NULL) { > goto exit; > } > >@@ -14367,12 +14477,12 @@ > } > > /* Paste them all together with ", " between. */ >- if ((name_str = _PyString_Join(sep, names)) == NULL) { >+ if ((name_str = PYSTRTYPE_JOIN(sep, names)) == NULL) { > goto exit; > } > >- name_desc = PyString_FromFormat(_("General Name List: [%s]"), >- PyString_AsString(name_str)); >+ name_desc = PYSTRTYPE_FROMFORMAT(_("General Name List: [%s]"), >+ PYSTRTYPE_ASSTRING(name_str)); > > } else if (self->pt->distPointType == relativeDistinguishedName) { > >@@ -14384,8 +14494,8 @@ > goto exit; > } > >- name_desc = PyString_FromFormat(_("Relative Distinguished Name: %s"), >- PyString_AsString(name_str)); >+ name_desc = PYSTRTYPE_FROMFORMAT(_("Relative Distinguished Name: %s"), >+ PYSTRTYPE_ASSTRING(name_str)); > > } else { > PyErr_Format(PyExc_ValueError, "unknown distribution point type (%d), " >@@ -14406,14 +14516,14 @@ > goto exit; > } > >- if ((reasons_str = _PyString_Join(sep, reasons)) == NULL) { >- goto exit; >- } >- >- result = PyString_FromFormat("%s, Issuer: %s, Reasons: [%s]", >- PyString_AsString(name_desc), >- PyString_AsString(crl_issuer_str), >- PyString_AsString(reasons_str)); >+ if ((reasons_str = PYSTRTYPE_JOIN(sep, reasons)) == NULL) { >+ goto exit; >+ } >+ >+ result = PYSTRTYPE_FROMFORMAT("%s, Issuer: %s, Reasons: [%s]", >+ PYSTRTYPE_ASSTRING(name_desc), >+ PYSTRTYPE_ASSTRING(crl_issuer_str), >+ PYSTRTYPE_ASSTRING(reasons_str)); > > exit: > Py_XDECREF(rdn); >@@ -14470,7 +14580,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CRLDistributionPt_doc, >@@ -14518,8 +14628,7 @@ > > > static PyTypeObject CRLDistributionPtType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CRLDistributionPoint", /* tp_name */ > sizeof(CRLDistributionPt), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -14617,14 +14726,14 @@ > > // > len = PyObject_Size((PyObject *)self); >- if ((obj = PyString_FromFormat("CRL Distribution Points: [%zd total]", len)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("CRL Distribution Points: [%zd total]", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level, fail); > Py_CLEAR(obj); > > for (i = 0; i < len; i++) { >- if ((obj = PyString_FromFormat("Point [%zd]:", i+1)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Point [%zd]:", i+1)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+1, fail); >@@ -14791,7 +14900,7 @@ > TraceMethodEnter(self); > > CRLDistributionPts_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CRLDistributionPts_doc, >@@ -14815,7 +14924,7 @@ > static PyObject * > CRLDistributionPts_repr(CRLDistributionPts *self) > { >- return PyString_FromFormat("<%s object at %p>", >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", > Py_TYPE(self)->tp_name, self); > } > >@@ -14833,8 +14942,7 @@ > }; > > static PyTypeObject CRLDistributionPtsType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CRLDistributionPts", /* tp_name */ > sizeof(CRLDistributionPts), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -15044,7 +15152,7 @@ > TraceMethodEnter(self); > > PORT_FreeArena(self->arena, PR_FALSE); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AuthorityInfoAccess_doc, >@@ -15068,8 +15176,7 @@ > } > > static PyTypeObject AuthorityInfoAccessType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.AuthorityInfoAccess", /* tp_name */ > sizeof(AuthorityInfoAccess), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -15156,7 +15263,7 @@ > } > > len = PyObject_Size((PyObject *)self); >- if ((obj = PyString_FromFormat("Authority Information Access: [%zd total]", len)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Authority Information Access: [%zd total]", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level, fail); >@@ -15164,7 +15271,7 @@ > > > for (i = 0; i < len; i++) { >- if ((obj = PyString_FromFormat("Info [%zd]:", i+1)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Info [%zd]:", i+1)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+1, fail); >@@ -15337,7 +15444,7 @@ > > AuthorityInfoAccesses_clear(self); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AuthorityInfoAccesses_doc, >@@ -15385,8 +15492,7 @@ > }; > > static PyTypeObject AuthorityInfoAccessesType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.AuthorityInfoAccesses", /* tp_name */ > sizeof(AuthorityInfoAccesses), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -15595,7 +15701,7 @@ > goto fail; > } > len = PyObject_Size(obj); >- if ((obj1 = PyString_FromFormat("General Names: [%zd total]", len)) == NULL) { >+ if ((obj1 = PYSTRTYPE_FROMFORMAT("General Names: [%zd total]", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj1, level, fail); >@@ -15673,7 +15779,7 @@ > PORT_FreeArena(self->arena, PR_FALSE); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(AuthKeyID_doc, >@@ -15737,11 +15843,11 @@ > PyObject *serial_number_str = NULL; > > if (!self->auth_key_id) { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >- } >- >- if ((sep = PyString_FromString(", ")) == NULL) { >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); >+ } >+ >+ if ((sep = PYSTRTYPE_FROMSTRING(", ")) == NULL) { > goto exit; > } > >@@ -15750,7 +15856,7 @@ > } > > /* Paste them all together with ", " between. */ >- if ((name_str = _PyString_Join(sep, names)) == NULL) { >+ if ((name_str = PYSTRTYPE_JOIN(sep, names)) == NULL) { > goto exit; > } > >@@ -15770,10 +15876,10 @@ > goto exit; > } > >- result = PyString_FromFormat("ID: %s, Serial Number: %s, Issuer: [%s]", >- PyString_AsString(key_id_str), >- PyString_AsString(serial_number_str), >- PyString_AsString(name_str)); >+ result = PYSTRTYPE_FROMFORMAT("ID: %s, Serial Number: %s, Issuer: [%s]", >+ PYSTRTYPE_ASSTRING(key_id_str), >+ PYSTRTYPE_ASSTRING(serial_number_str), >+ PYSTRTYPE_ASSTRING(name_str)); > > > exit: >@@ -15788,8 +15894,7 @@ > } > > static PyTypeObject AuthKeyIDType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.AuthKeyID", /* tp_name */ > sizeof(AuthKeyID), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -15894,7 +15999,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->bc.pathLenConstraint); >+ return PYINTTYPE_FROMLONG(self->bc.pathLenConstraint); > > return NULL; > } >@@ -15936,7 +16041,7 @@ > FMT_OBJ_AND_APPEND(lines, _("Is CA"), obj, level, fail); > Py_CLEAR(obj); > >- if ((obj = PyString_FromFormat("%d", self->bc.pathLenConstraint)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("%d", self->bc.pathLenConstraint)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, _("Path Length"), obj, level, fail); >@@ -15989,7 +16094,7 @@ > { > TraceMethodEnter(self); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(BasicConstraints_doc, >@@ -16019,20 +16124,19 @@ > static PyObject * > BasicConstraints_repr(BasicConstraints *self) > { >- return PyString_FromFormat("<%s object at %p>", >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", > Py_TYPE(self)->tp_name, self); > } > > static PyObject * > BasicConstraints_str(BasicConstraints *self) > { >- return PyString_FromFormat("is_ca=%s path_len=%d", >+ return PYSTRTYPE_FROMFORMAT("is_ca=%s path_len=%d", > self->bc.isCA ? "True" : "False", self->bc.pathLenConstraint); > } > > static PyTypeObject BasicConstraintsType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.BasicConstraints", /* tp_name */ > sizeof(BasicConstraints), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -16198,14 +16302,14 @@ > FMT_OBJ_AND_APPEND(lines, _("Type"), obj, level, fail); > Py_CLEAR(obj); > >- if ((obj = PyString_FromFormat("Values (%zd total)", self->n_values)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Values (%zd total)", self->n_values)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level, fail); > Py_CLEAR(obj); > > for (i = 0; i < self->n_values; i++) { >- if ((obj = PyString_FromFormat("Value [%zd]", i)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Value [%zd]", i)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+1, fail); >@@ -16315,7 +16419,7 @@ > TraceMethodEnter(self); > > PORT_FreeArena(self->arena, PR_FALSE); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertAttribute_doc, >@@ -16353,8 +16457,7 @@ > }; > > static PyTypeObject CertAttributeType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertAttribute", /* tp_name */ > sizeof(CertAttribute), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -16696,14 +16799,14 @@ > } > > len = PyTuple_Size(attributes); >- if ((obj = PyString_FromFormat("Attributes: (%zd total)", len)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Attributes: (%zd total)", len)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+1, fail); > Py_CLEAR(obj); > > for (i = 0; i < len; i++) { >- if ((obj = PyString_FromFormat("Attribute [%zd]", i)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT("Attribute [%zd]", i)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, NULL, obj, level+2, fail); >@@ -16797,7 +16900,7 @@ > if (self->arena) { > PORT_FreeArena(self->arena, PR_FALSE); > } >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertificateRequest_doc, >@@ -16834,13 +16937,12 @@ > static PyObject * > CertificateRequest_repr(CertificateRequest *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject CertificateRequestType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertificateRequest", /* tp_name */ > sizeof(CertificateRequest), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -16922,7 +17024,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->params.minPWLen); >+ return PYINTTYPE_FROMLONG(self->params.minPWLen); > } > > static int >@@ -16935,12 +17037,12 @@ > return -1; > } > >- if (!PyInt_Check(value)) { >+ if (!PYINTTYPE_CHECK(value)) { > PyErr_SetString(PyExc_TypeError, "The min_password_len attribute value must be an integer"); > return -1; > } > >- self->params.minPWLen = PyInt_AsLong(value); >+ self->params.minPWLen = PYINTTYPE_ASLONG(value); > > return 0; > } >@@ -17544,7 +17646,7 @@ > PyMem_Free(self->params.FIPSSlotDescription); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(InitParameters_doc, >@@ -17715,7 +17817,7 @@ > } > > >- if ((fmt = PyString_FromString(fmt_str)) == NULL) { >+ if ((fmt = PYSTRTYPE_FROMSTRING(fmt_str)) == NULL) { > goto fail; > } > >@@ -17741,7 +17843,7 @@ > PyTuple_SetItem(args, 8, py_db_slot_description); Py_INCREF(py_db_slot_description); > PyTuple_SetItem(args, 9, py_fips_slot_description); Py_INCREF(py_fips_slot_description); > >- if ((result = PyString_Format(fmt, args)) == NULL) { >+ if ((result = PYSTRTYPE_FORMAT(fmt, args)) == NULL) { > goto fail; > } > >@@ -17767,8 +17869,7 @@ > } > > static PyTypeObject InitParametersType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.InitParameters", /* tp_name */ > sizeof(InitParameters), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -17870,7 +17971,7 @@ > */ > NSS_ShutdownContext(self->context); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(InitContext_doc, >@@ -17880,13 +17981,12 @@ > static PyObject * > InitContext_repr(InitContext *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject InitContextType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.InitContext", /* tp_name */ > sizeof(InitContext), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -17954,7 +18054,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->type); >+ return PYINTTYPE_FROMLONG(self->type); > } > > static PyObject * >@@ -18154,7 +18254,7 @@ > TraceMethodEnter(self); > > PKCS12DecodeItem_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PKCS12DecodeItem_doc, >@@ -18179,13 +18279,12 @@ > static PyObject * > PKCS12DecodeItem_repr(PKCS12DecodeItem *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PyTypeObject PKCS12DecodeItemType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PKCS12DecodeItem", /* tp_name */ > sizeof(PKCS12DecodeItem), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -18357,7 +18456,7 @@ > py_old_nickname = Py_None; > Py_INCREF(py_old_nickname); > } else { >- py_old_nickname = PyString_FromStringAndSize((char *)old_nickname->data, old_nickname->len); >+ py_old_nickname = PyBytes_FromStringAndSize((char *)old_nickname->data, old_nickname->len); > } > > cert = (CERTCertificate*)arg; >@@ -18388,7 +18487,7 @@ > py_new_nickname = PyTuple_GetItem(result, 0); > py_cancel = PyTuple_GetItem(result, 1); > >- if (!(PyString_Check(py_new_nickname) || PyUnicode_Check(py_new_nickname) || >+ if (!(PyBytes_Check(py_new_nickname) || PyUnicode_Check(py_new_nickname) || > PyNone_Check(py_new_nickname))) { > PySys_WriteStderr("Error, PKCS12 nickname collision callback expected 1st returned item to be string or None.\n"); > goto exit; >@@ -18401,8 +18500,8 @@ > goto exit; > } > >- if (PyString_Check(py_new_nickname) || PyUnicode_Check(py_new_nickname)) { >- if (PyString_Check(py_new_nickname)) { >+ if (PyBytes_Check(py_new_nickname) || PyUnicode_Check(py_new_nickname)) { >+ if (PyBytes_Check(py_new_nickname)) { > py_new_nickname_utf8 = py_new_nickname; > Py_INCREF(py_new_nickname_utf8); > } else { >@@ -18414,8 +18513,8 @@ > goto exit; > } > >- returned_nickname->data = (unsigned char *)PORT_Strdup(PyString_AsString(py_new_nickname_utf8)); >- returned_nickname->len = PyString_Size(py_new_nickname_utf8); >+ returned_nickname->data = (unsigned char *)PORT_Strdup(PyBytes_AsString(py_new_nickname_utf8)); >+ returned_nickname->len = PyBytes_Size(py_new_nickname_utf8); > } > > >@@ -18683,7 +18782,7 @@ > } > > PKCS12Decoder_clear(self); >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(PKCS12Decoder_doc, >@@ -18778,8 +18877,8 @@ > > /* decode the item */ > if (SEC_PKCS12DecoderUpdate(self->decoder_ctx, >- (unsigned char *)PyString_AS_STRING(py_file_contents), >- PyString_GET_SIZE(py_file_contents)) != SECSuccess) { >+ (unsigned char *)PyBytes_AS_STRING(py_file_contents), >+ PyBytes_GET_SIZE(py_file_contents)) != SECSuccess) { > set_nspr_error("PKCS12 decoding failed"); > result = -1; > goto exit; >@@ -18839,8 +18938,8 @@ > static PyObject * > PKCS12Decoder_repr(PKCS12Decoder *self) > { >- return PyString_FromFormat("<%s object at %p>", >- Py_TYPE(self)->tp_name, self); >+ return PYSTRTYPE_FROMFORMAT("<%s object at %p>", >+ Py_TYPE(self)->tp_name, self); > } > > static PySequenceMethods PKCS12Decoder_as_sequence = { >@@ -18857,8 +18956,7 @@ > }; > > static PyTypeObject PKCS12DecoderType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.PKCS12Decoder", /* tp_name */ > sizeof(PKCS12Decoder), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -18918,7 +19016,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->node.error); >+ return PYINTTYPE_FROMLONG(self->node.error); > } > > static PyObject * >@@ -18926,7 +19024,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->node.depth); >+ return PYINTTYPE_FROMLONG(self->node.depth); > } > > static >@@ -18962,14 +19060,14 @@ > node = &self->node; > > if ((error_desc = lookup_nspr_error(node->error)) == NULL) { >- if ((obj = PyString_FromFormat(_("Unknown error code %ld (%#lx)"), >- node->error, node->error)) == NULL) { >- goto fail; >- } >- } else { >- if ((obj = PyString_FromFormat("[%s] %s", >- error_desc->name, >- error_desc->string)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT(_("Unknown error code %ld (%#lx)"), >+ node->error, node->error)) == NULL) { >+ goto fail; >+ } >+ } else { >+ if ((obj = PYSTRTYPE_FROMFORMAT("[%s] %s", >+ error_desc->name, >+ error_desc->string)) == NULL) { > goto fail; > } > } >@@ -19060,7 +19158,7 @@ > } > Py_CLEAR(py_cert); > >- if ((obj = PyInt_FromLong(node->depth)) == NULL){ >+ if ((obj = PYINTTYPE_FROMLONG(node->depth)) == NULL){ > goto fail; > } > FMT_OBJ_AND_APPEND(lines, _("Depth"), obj, level, fail); >@@ -19133,7 +19231,7 @@ > CERT_DestroyCertificate(self->node.cert); > } > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertVerifyLogNode_doc, >@@ -19145,8 +19243,7 @@ > "); > > static PyTypeObject CertVerifyLogNodeType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertVerifyLogNode", /* tp_name */ > sizeof(CertVerifyLogNode), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -19219,7 +19316,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(self->log.count); >+ return PYINTTYPE_FROMLONG(self->log.count); > } > > static >@@ -19256,7 +19353,7 @@ > return NULL; > } > >- if ((obj = PyInt_FromLong(self->log.count)) == NULL) { >+ if ((obj = PYINTTYPE_FROMLONG(self->log.count)) == NULL) { > goto fail; > } > FMT_OBJ_AND_APPEND(lines, _("Validation Errors"), obj, level, fail); >@@ -19274,10 +19371,10 @@ > if (depth != node->depth) { > depth = node->depth; > >- if ((obj = PyString_FromFormat(_("Certificate at chain depth %u"), node->depth)) == NULL) { >+ if ((obj = PYSTRTYPE_FROMFORMAT(_("Certificate at chain depth %u"), node->depth)) == NULL) { > goto fail; > } >- FMT_LABEL_AND_APPEND(lines, PyString_AsString(obj), level, fail); >+ FMT_LABEL_AND_APPEND(lines, PYSTRTYPE_ASSTRING(obj), level, fail); > Py_CLEAR(obj); > > if ((py_cert = (Certificate *)Certificate_new_from_CERTCertificate(node->cert, true)) == NULL) { >@@ -19294,10 +19391,10 @@ > FMT_LABEL_AND_APPEND(lines, NULL, level, fail); > } > >- if ((obj = PyString_FromFormat(_("Validation Error #%zd"), i+1)) == NULL) { >- goto fail; >- } >- FMT_LABEL_AND_APPEND(lines, PyString_AsString(obj), level+1, fail); >+ if ((obj = PYSTRTYPE_FROMFORMAT(_("Validation Error #%zd"), i+1)) == NULL) { >+ goto fail; >+ } >+ FMT_LABEL_AND_APPEND(lines, PYSTRTYPE_ASSTRING(obj), level+1, fail); > Py_CLEAR(obj); > > if (CertVerifyLogNodeError_format_lines(py_node, level+2, lines) == NULL) { >@@ -19413,7 +19510,7 @@ > } > PORT_FreeArena(self->log.arena, PR_FALSE); > >- self->ob_type->tp_free((PyObject*)self); >+ Py_TYPE(self)->tp_free((PyObject*)self); > } > > PyDoc_STRVAR(CertVerifyLog_doc, >@@ -19437,8 +19534,7 @@ > }; > > static PyTypeObject CertVerifyLogType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.nss.CertVerifyLog", /* tp_name */ > sizeof(CertVerifyLog), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -19558,11 +19654,11 @@ > goto exit; > } > >- if (PyString_Check(result) || PyUnicode_Check(result)) { >+ if (PyBytes_Check(result) || PyUnicode_Check(result)) { > PyObject *py_password = NULL; > > if ((py_password = PyString_UTF8(result, "PK11 password callback result")) != NULL) { >- password = PORT_Strdup(PyString_AsString(py_password)); >+ password = PORT_Strdup(PyBytes_AsString(py_password)); > Py_DECREF(py_password); > } else { > goto exit; >@@ -19996,7 +20092,7 @@ > return set_nspr_error(NULL); > } > >- res = PyString_FromStringAndSize((char *)buf, num_bytes); >+ res = PyBytes_FromStringAndSize((char *)buf, num_bytes); > PyMem_Free(buf); > return res; > } >@@ -20115,7 +20211,7 @@ > } > Py_END_ALLOW_THREADS > >- return PyString_FromString(nss_version); >+ return PYSTRTYPE_FROMSTRING(nss_version); > } > > PyDoc_STRVAR(nss_nss_version_check_doc, >@@ -20916,7 +21012,7 @@ > return set_nspr_error(NULL); > } > >- return PyString_FromString(oiddata->desc); >+ return PYSTRTYPE_FROMSTRING(oiddata->desc); > } > > >@@ -20996,7 +21092,7 @@ > return NULL; > } > >- result = PyInt_FromLong(oid_tag); >+ result = PYINTTYPE_FROMLONG(oid_tag); > return result; > } > >@@ -21050,7 +21146,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(mechanism)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(mechanism)) == NULL) { > PyErr_SetString(PyExc_MemoryError, "unable to create object"); > return NULL; > } >@@ -21119,7 +21215,7 @@ > } > > if ((py_value = PyDict_GetItem(ckm_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "mechanism name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "mechanism name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_lower_name); > return NULL; > } >@@ -21136,7 +21232,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(type)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(type)) == NULL) { > PyErr_SetString(PyExc_MemoryError, "unable to create object"); > return NULL; > } >@@ -21205,7 +21301,7 @@ > } > > if ((py_value = PyDict_GetItem(cka_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "attribute name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "attribute name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_lower_name); > return NULL; > } >@@ -21236,7 +21332,7 @@ > if (!PyArg_ParseTuple(args, "k:pk11_disabled_reason_str", &reason)) > return NULL; > >- return PyString_FromString(pk11_disabled_reason_str(reason)); >+ return PYSTRTYPE_FROMSTRING(pk11_disabled_reason_str(reason)); > } > > PyDoc_STRVAR(pk11_disabled_reason_name_doc, >@@ -21259,7 +21355,7 @@ > if (!PyArg_ParseTuple(args, "k:pk11_disabled_reason_name", &reason)) > return NULL; > >- return PyString_FromString(pk11_disabled_reason_name(reason)); >+ return PYSTRTYPE_FROMSTRING(pk11_disabled_reason_name(reason)); > } > > PyDoc_STRVAR(pk11_pk11_logout_all_doc, >@@ -21749,7 +21845,7 @@ > return NULL; > } > >- return PyInt_FromLong(mechanism); >+ return PYINTTYPE_FROMLONG(mechanism); > } > > PyDoc_STRVAR(pk11_mechanism_to_algtag_doc, >@@ -21778,7 +21874,7 @@ > return NULL; > } > >- return PyInt_FromLong(algtag); >+ return PYINTTYPE_FROMLONG(algtag); > } > PyDoc_STRVAR(pk11_get_iv_length_doc, > "get_iv_length(mechanism) -> algtag\n\ >@@ -21802,7 +21898,7 @@ > > iv_length = PK11_GetIVLength(mechanism); > >- return PyInt_FromLong(iv_length); >+ return PYINTTYPE_FROMLONG(iv_length); > } > > PyDoc_STRVAR(pk11_get_block_size_doc, >@@ -21832,7 +21928,7 @@ > > block_size = PK11_GetBlockSize(mechanism, py_sec_param ? &py_sec_param->item : NULL); > >- return PyInt_FromLong(block_size); >+ return PYINTTYPE_FROMLONG(block_size); > } > > PyDoc_STRVAR(pk11_get_pad_mechanism_doc, >@@ -21858,7 +21954,7 @@ > > pad_mechanism = PK11_GetPadMechanism(mechanism); > >- return PyInt_FromLong(pad_mechanism); >+ return PYINTTYPE_FROMLONG(pad_mechanism); > } > > PyDoc_STRVAR(pk11_import_crl_doc, >@@ -22036,14 +22132,14 @@ > } > > if (ascii) { >- if ((py_sec_item = base64_to_SecItem(PyString_AsString(py_file_contents))) == NULL) { >+ if ((py_sec_item = base64_to_SecItem(PyBytes_AsString(py_file_contents))) == NULL) { > goto fail; > } > } else { > SECItem der; > >- der.data = (unsigned char *)PyString_AsString(py_file_contents); >- der.len = PyString_GET_SIZE(py_file_contents); >+ der.data = (unsigned char *)PyBytes_AsString(py_file_contents); >+ der.len = PyBytes_GET_SIZE(py_file_contents); > der.type = siBuffer; > > if ((py_sec_item = SecItem_new_from_SECItem(&der, SECITEM_unknown)) == NULL) { >@@ -22285,7 +22381,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(reason)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(reason)) == NULL) { > PyErr_SetString(PyExc_MemoryError, "unable to create object"); > return NULL; > } >@@ -22354,7 +22450,7 @@ > } > > if ((py_value = PyDict_GetItem(crl_reason_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "CRL reason name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "CRL reason name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_lower_name); > return NULL; > } >@@ -22371,7 +22467,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(cipher)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(cipher)) == NULL) { > PyErr_SetString(PyExc_MemoryError, "unable to create object"); > return NULL; > } >@@ -22440,7 +22536,7 @@ > } > > if ((py_value = PyDict_GetItem(pkcs12_cipher_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "PKCS12 cipher name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "PKCS12 cipher name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_lower_name); > return NULL; > } >@@ -22507,7 +22603,7 @@ > cipher_tag = tag; > } > >- return PyInt_FromLong(cipher_tag); >+ return PYINTTYPE_FROMLONG(cipher_tag); > } > > static PyObject * >@@ -22516,7 +22612,7 @@ > PyObject *py_value; > PyObject *py_name; > >- if ((py_value = PyInt_FromLong(type)) == NULL) { >+ if ((py_value = PYINTTYPE_FROMLONG(type)) == NULL) { > PyErr_SetString(PyExc_MemoryError, "unable to create object"); > return NULL; > } >@@ -22585,7 +22681,7 @@ > } > > if ((py_value = PyDict_GetItem(general_name_name_to_value, py_lower_name)) == NULL) { >- PyErr_Format(PyExc_KeyError, "GeneralName type name not found: %s", PyString_AsString(py_name)); >+ PyErr_Format(PyExc_KeyError, "GeneralName type name not found: %s", PYSTRTYPE_ASSTRING(py_name)); > Py_DECREF(py_lower_name); > return NULL; > } >@@ -22781,10 +22877,10 @@ > > if (SEC_PKCS12EnableCipher(cipher, enabled ? PR_TRUE : PR_FALSE) != SECSuccess) { > PyObject *py_cipher_name = pkcs12_cipher_to_pystr(cipher); >- PyObject *py_err_msg = PyString_FromFormat("Failed to %s %s (%lx) pkcs12 cipher", >- enabled ? _("enable") : _("disable"), >- PyString_AsString(py_cipher_name), cipher); >- set_nspr_error("%s", PyString_AsString(py_err_msg)); >+ PyObject *py_err_msg = PYSTRTYPE_FROMFORMAT("Failed to %s %s (%lx) pkcs12 cipher", >+ enabled ? _("enable") : _("disable"), >+ PYSTRTYPE_ASSTRING(py_cipher_name), cipher); >+ set_nspr_error("%s", PYSTRTYPE_ASSTRING(py_err_msg)); > Py_DECREF(py_cipher_name); > Py_DECREF(py_err_msg); > return NULL; >@@ -22823,9 +22919,9 @@ > cipher = all_ciphers[i]; > if (SEC_PKCS12EnableCipher(cipher, PR_TRUE) != SECSuccess) { > PyObject *py_cipher_name = pkcs12_cipher_to_pystr(cipher); >- PyObject *py_err_msg = PyString_FromFormat("Failed to enable %s (%lx) pkcs12 cipher", >- PyString_AsString(py_cipher_name), cipher); >- set_nspr_error("%s", PyString_AsString(py_err_msg)); >+ PyObject *py_err_msg = PYSTRTYPE_FROMFORMAT("Failed to enable %s (%lx) pkcs12 cipher", >+ PYSTRTYPE_ASSTRING(py_cipher_name), cipher); >+ set_nspr_error("%s", PYSTRTYPE_ASSTRING(py_err_msg)); > Py_DECREF(py_cipher_name); > Py_DECREF(py_err_msg); > return NULL; >@@ -22884,12 +22980,12 @@ > return; > } > >- if ((py_new_string = PyString_FromStringAndSize(buf, len)) == NULL) { >+ if ((py_new_string = PyBytes_FromStringAndSize(buf, len)) == NULL) { > Py_CLEAR(*py_encoded_buf); > return; > } > >- PyString_ConcatAndDel(py_encoded_buf, py_new_string); >+ PyBytes_ConcatAndDel(py_encoded_buf, py_new_string); > } > > PyDoc_STRVAR(pkcs12_export_doc, >@@ -23115,7 +23211,7 @@ > } > } > >- if ((py_encoded_buf = PyString_FromStringAndSize(NULL, 0)) == NULL) { >+ if ((py_encoded_buf = PyBytes_FromStringAndSize(NULL, 0)) == NULL) { > goto exit; > } > >@@ -23496,8 +23592,8 @@ > } > > if (CERT_SetOCSPDefaultResponder(py_certdb->handle, >- PyString_AsString(py_url_utf8), >- PyString_AsString(py_nickname_utf8)) != SECSuccess) { >+ PyBytes_AsString(py_url_utf8), >+ PyBytes_AsString(py_nickname_utf8)) != SECSuccess) { > return set_nspr_error(NULL); > } > >@@ -23712,21 +23808,43 @@ > \n\ > "); > >+#ifdef IS_PY3K >+static struct PyModuleDef py_nss_def = { >+ PyModuleDef_HEAD_INIT, >+ "nss.nss", >+ module_doc, >+ -1, >+ module_methods, >+ NULL, >+ NULL, >+ NULL, >+ NULL >+}; >+ >+PyMODINIT_FUNC >+PyInit_nss(void) >+#else > PyMODINIT_FUNC > initnss(void) >+#endif > { > PyObject *m; > > if (import_nspr_error_c_api() < 0) { >- return; >- } >- >- if ((m = Py_InitModule3("nss.nss", module_methods, module_doc)) == NULL) { >- return; >+ MODINITERROR; >+ } >+ >+#ifdef IS_PY3K >+ m = PyModule_Create(&py_nss_def); >+#else >+ m = Py_InitModule3("nss.nss", module_methods, module_doc); >+#endif >+ if (m == NULL) { >+ MODINITERROR; > } > > if ((empty_tuple = PyTuple_New(0)) == NULL) { >- return; >+ MODINITERROR; > } > Py_INCREF(empty_tuple); > >@@ -23767,8 +23885,8 @@ > TYPE_READY(CertVerifyLogType); > > /* Export C API */ >- if (PyModule_AddObject(m, "_C_API", PyCObject_FromVoidPtr((void *)&nspr_nss_c_api, NULL)) != 0) { >- return; >+ if (PyModule_AddObject(m, "_C_API", PyCapsule_New((void *)&nspr_nss_c_api, NULL, NULL)) != 0) { >+ MODINITERROR; > } > > AddIntConstant(OCTETS_PER_LINE_DEFAULT); >@@ -23889,15 +24007,15 @@ > ***************************************************************************/ > > if ((crl_reason_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((crl_reason_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "crlEntry", crl_reason_name_to_value, crl_reason_value_to_name) < 0) return; >+ "crlEntry", crl_reason_name_to_value, crl_reason_value_to_name) < 0) MODINITERROR; > > ExportConstant(crlEntryReasonUnspecified); > ExportConstant(crlEntryReasonKeyCompromise); >@@ -23917,15 +24035,15 @@ > ***************************************************************************/ > > if ((general_name_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((general_name_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "cert", general_name_name_to_value, general_name_value_to_name) < 0) return; >+ "cert", general_name_name_to_value, general_name_value_to_name) < 0) MODINITERROR; > > ExportConstant(certOtherName); > ExportConstant(certRFC822Name); >@@ -23944,15 +24062,15 @@ > ***************************************************************************/ > > if ((ckm_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((ckm_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "CKM_", ckm_name_to_value, ckm_value_to_name) < 0) return; >+ "CKM_", ckm_name_to_value, ckm_value_to_name) < 0) MODINITERROR; > > ExportConstant(CKM_RSA_PKCS_KEY_PAIR_GEN); > ExportConstant(CKM_RSA_PKCS); >@@ -24302,15 +24420,15 @@ > * Attribute Types > ***************************************************************************/ > if ((cka_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((cka_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "CKA_", cka_name_to_value, cka_value_to_name) < 0) return; >+ "CKA_", cka_name_to_value, cka_value_to_name) < 0) MODINITERROR; > > /* The following attribute types are defined: */ > ExportConstant(CKA_CLASS); >@@ -24446,15 +24564,15 @@ > ***************************************************************************/ > > if ((sec_oid_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((sec_oid_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "SEC_OID_", sec_oid_name_to_value, sec_oid_value_to_name) < 0) return; >+ "SEC_OID_", sec_oid_name_to_value, sec_oid_value_to_name) < 0) MODINITERROR; > > ExportConstant(SEC_OID_UNKNOWN); > ExportConstant(SEC_OID_MD2); >@@ -24879,15 +24997,15 @@ > ***************************************************************************/ > > if ((pkcs12_cipher_name_to_value = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > if ((pkcs12_cipher_value_to_name = PyDict_New()) == NULL) { >- return; >+ MODINITERROR; > } > > #define ExportConstant(constant) \ > if (_AddIntConstantWithLookup(m, #constant, constant, \ >- "PKCS12_", pkcs12_cipher_name_to_value, pkcs12_cipher_value_to_name) < 0) return; >+ "PKCS12_", pkcs12_cipher_name_to_value, pkcs12_cipher_value_to_name) < 0) MODINITERROR; > > ExportConstant(PKCS12_RC2_CBC_40); > ExportConstant(PKCS12_RC2_CBC_128); >@@ -24896,4 +25014,7 @@ > ExportConstant(PKCS12_DES_56); > ExportConstant(PKCS12_DES_EDE3_168); > >-} >+#ifdef IS_PY3K >+ return m; >+#endif >+} >diff -r e1b1afd424c3 src/py_nss.h >--- a/src/py_nss.h Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_nss.h Mon Jul 28 12:32:46 2014 +0200 >@@ -471,13 +471,13 @@ > return -1; > } > >- if (!(PyCObject_Check(c_api_object))) { >+ if (!(PyCapsule_CheckExact(c_api_object))) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; > } > >- if ((api = PyCObject_AsVoidPtr(c_api_object)) == NULL) { >+ if ((api = PyCapsule_GetPointer(c_api_object, NULL)) == NULL) { > Py_DECREF(c_api_object); > Py_DECREF(module); > return -1; >diff -r e1b1afd424c3 src/py_ssl.c >--- a/src/py_ssl.c Fri Jan 31 15:19:48 2014 -0500 >+++ b/src/py_ssl.c Mon Jul 28 12:32:46 2014 +0200 >@@ -35,6 +35,7 @@ > > #define PY_SSIZE_T_CLEAN > #include "Python.h" >+#include "py_2_3_compat.h" > #include "structmember.h" > > #include "py_nspr_common.h" >@@ -312,7 +313,7 @@ > return set_nspr_error(NULL); > } > >- return PyInt_FromLong(value); >+ return PYINTTYPE_FROMLONG(value); > } > > PyDoc_STRVAR(SSLSocket_accept_doc, >@@ -1110,7 +1111,7 @@ > TraceMethodEnter(self); > > data_pending = SSL_DataPending(self->pr_socket); >- return PyInt_FromLong(data_pending); >+ return PYINTTYPE_FROMLONG(data_pending); > } > > PyDoc_STRVAR(SSLSocket_get_security_status_doc, >@@ -1411,7 +1412,7 @@ > return set_nspr_error(NULL); > } > >- py_hostname = PyString_FromString(url); >+ py_hostname = PYSTRTYPE_FROMSTRING(url); > PR_Free(url); > return py_hostname; > } >@@ -1853,8 +1854,7 @@ > } > > static PyTypeObject SSLSocketType = { >- PyObject_HEAD_INIT(NULL) >- 0, /* ob_size */ >+ PyVarObject_HEAD_INIT(NULL, 0) > "nss.ssl.SSLSocket", /* tp_name */ > sizeof(SSLSocket), /* tp_basicsize */ > 0, /* tp_itemsize */ >@@ -2054,7 +2054,7 @@ > if (SSL_OptionGetDefault(option, &value) != SECSuccess) { > return set_nspr_error(NULL); > } >- return PyInt_FromLong(value); >+ return PYINTTYPE_FROMLONG(value); > } > > PyDoc_STRVAR(SSL_set_default_cipher_pref_doc, >@@ -2262,14 +2262,14 @@ > &max_cache_entries, &ssl2_timeout, &ssl3_timeout, &py_directory)) > return NULL; > >- if (PyString_Check(py_directory) || PyUnicode_Check(py_directory)) { >- if (PyString_Check(py_directory)) { >+ if (PyBytes_Check(py_directory) || PyUnicode_Check(py_directory)) { >+ if (PyBytes_Check(py_directory)) { > py_directory_utf8 = py_directory; > Py_INCREF(py_directory_utf8); > } else { > py_directory_utf8 = PyUnicode_AsUTF8String(py_directory); > } >- directory = PyString_AsString(py_directory_utf8); >+ directory = PyBytes_AsString(py_directory_utf8); > } else if (PyNone_Check(py_directory)) { > directory = NULL; > } else { >@@ -2354,14 +2354,14 @@ > &ssl2_timeout, &ssl3_timeout, &py_directory, &py_enable_mp_cache)) > return NULL; > >- if (PyString_Check(py_directory) || PyUnicode_Check(py_directory)) { >- if (PyString_Check(py_directory)) { >+ if (PyBytes_Check(py_directory) || PyUnicode_Check(py_directory)) { >+ if (PyBytes_Check(py_directory)) { > py_directory_utf8 = py_directory; > Py_INCREF(py_directory_utf8); > } else { > py_directory_utf8 = PyUnicode_AsUTF8String(py_directory); > } >- directory = PyString_AsString(py_directory_utf8); >+ directory = PyBytes_AsString(py_directory_utf8); > } else if (PyNone_Check(py_directory)) { > directory = NULL; > } else { >@@ -2438,14 +2438,14 @@ > &max_cache_entries, &ssl2_timeout, &ssl3_timeout, &py_directory)) > return NULL; > >- if (PyString_Check(py_directory) || PyUnicode_Check(py_directory)) { >- if (PyString_Check(py_directory)) { >+ if (PyBytes_Check(py_directory) || PyUnicode_Check(py_directory)) { >+ if (PyBytes_Check(py_directory)) { > py_directory_utf8 = py_directory; > Py_INCREF(py_directory_utf8); > } else { > py_directory_utf8 = PyUnicode_AsUTF8String(py_directory); > } >- directory = PyString_AsString(py_directory_utf8); >+ directory = PyBytes_AsString(py_directory_utf8); > } else if (PyNone_Check(py_directory)) { > directory = NULL; > } else { >@@ -2477,7 +2477,7 @@ > { > TraceMethodEnter(self); > >- return PyInt_FromLong(SSL_GetMaxServerCacheLocks()); >+ return PYINTTYPE_FROMLONG(SSL_GetMaxServerCacheLocks()); > } > > PyDoc_STRVAR(SSL_set_max_server_cache_locks_doc, >@@ -2645,41 +2645,64 @@ > PyDoc_STRVAR(module_doc, > "This module implements the SSL functionality in NSS"); > >+#ifdef IS_PY3K >+static struct PyModuleDef py_ssl_def = { >+ PyModuleDef_HEAD_INIT, >+ "nss.ssl", >+ module_doc, >+ -1, >+ module_methods, >+ NULL, >+ NULL, >+ NULL, >+ NULL >+}; >+ >+PyMODINIT_FUNC >+PyInit_ssl(void) >+#else > PyMODINIT_FUNC > initssl(void) >+#endif > { > PyObject *m; > int i; > > > if (import_nspr_error_c_api() < 0) >- return; >+ MODINITERROR; > > if (import_nspr_io_c_api() < 0) >- return; >+ MODINITERROR; > > if (import_nspr_nss_c_api() < 0) >- return; >+ MODINITERROR; > > SSLSocketType.tp_base = &SocketType; > >- if ((m = Py_InitModule3("nss.ssl", module_methods, module_doc)) == NULL) { >- return; >+#ifdef IS_PY3K >+ m = PyModule_Create(&py_ssl_def); >+#else >+ m = Py_InitModule3("nss.ssl", module_methods, module_doc); >+#endif >+ >+ if (m == NULL) { >+ MODINITERROR; > } > > TYPE_READY(SSLSocketType); > > /* Export C API */ >- if (PyModule_AddObject(m, "_C_API", PyCObject_FromVoidPtr((void *)&nss_ssl_c_api, NULL)) != 0) >- return; >+ if (PyModule_AddObject(m, "_C_API", PyCapsule_New((void *)&nss_ssl_c_api, NULL, NULL)) != 0) >+ MODINITERROR; > > /* SSL_ImplementedCiphers */ > if ((py_ssl_implemented_ciphers = PyTuple_New(SSL_NumImplementedCiphers)) == NULL) { >- return; >+ MODINITERROR; > } > > for (i = 0; i < SSL_NumImplementedCiphers; i++) { >- PyTuple_SetItem(py_ssl_implemented_ciphers, i, PyInt_FromLong(SSL_ImplementedCiphers[i])); >+ PyTuple_SetItem(py_ssl_implemented_ciphers, i, PYINTTYPE_FROMLONG(SSL_ImplementedCiphers[i])); > } > > PyModule_AddObject(m, "ssl_implemented_ciphers", py_ssl_implemented_ciphers); >@@ -2817,4 +2840,7 @@ > AddIntConstant(TLS_ECDH_anon_WITH_AES_128_CBC_SHA); > AddIntConstant(TLS_ECDH_anon_WITH_AES_256_CBC_SHA); > >+#ifdef IS_PY3K >+ return m; >+#endif > } >diff -r e1b1afd424c3 test/run_tests >--- a/test/run_tests Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/run_tests Mon Jul 28 12:32:46 2014 +0200 >@@ -1,4 +1,5 @@ > #!/usr/bin/python >+from __future__ import print_function > > import argparse > import os >@@ -6,6 +7,12 @@ > import unittest > from util import get_build_dir > >+import six >+ >+if six.PY3: >+ import faulthandler >+ faulthandler.enable() >+ > #------------------------------------------------------------------------------- > > def run_tests(): >@@ -58,13 +65,13 @@ > > build_dir = get_build_dir() > if build_dir and os.path.exists(build_dir): >- print "Using local libraries from tree, located here:\n%s\n" % build_dir >+ print("Using local libraries from tree, located here:\n%s\n" % build_dir) > sys.path.insert(0, build_dir) > else: >- print >>sys.stderr, "ERROR: Unable to locate in tree libraries" >+ print("ERROR: Unable to locate in tree libraries", file=sys.stderr) > return 2 > else: >- print "Using installed libraries" >+ print("Using installed libraries") > > num_failures = run_tests() > >diff -r e1b1afd424c3 test/setup_certs.py >--- a/test/setup_certs.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/setup_certs.py Mon Jul 28 12:32:46 2014 +0200 >@@ -10,6 +10,8 @@ > from string import Template > import tempfile > >+import six >+ > #------------------------------------------------------------------------------- > > class CmdError(Exception): >@@ -37,7 +39,8 @@ > stdin=subprocess.PIPE, > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) >- stdout, stderr = p.communicate(input) >+ # TODO: is encoding correct here? >+ stdout, stderr = p.communicate(input.encode('utf-8') if input else None) > returncode = p.returncode > if returncode != 0: > raise CmdError(cmd_args, returncode, >@@ -87,13 +90,14 @@ > os.write(fd, random_data) > os.close(fd) > else: >- with open(options.noise_filename, 'w') as f: >+ with open(options.noise_filename, 'wb') as f: > f.write(random_data) > return > > def create_passwd_file(options): > fd, options.passwd_filename = tempfile.mkstemp() >- os.write(fd, options.db_passwd) >+ # TODO: is encoding right here? >+ os.write(fd, options.db_passwd.encode('utf-8')) > os.close(fd) > > >@@ -431,7 +435,7 @@ > continue > value = getattr(options, key) > # Can't substitue on non-string values >- if not isinstance(value, basestring): >+ if not isinstance(value, six.string_types): > continue > # Don't bother trying to substitute if $ substitution character isn't present > if '$' not in value: >diff -r e1b1afd424c3 test/test_cert_components.py >--- a/test/test_cert_components.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_cert_components.py Mon Jul 28 12:32:46 2014 +0200 >@@ -43,7 +43,7 @@ > try: > callback(*args, **kw) > raise ExceptionNotRaised(exception) >- except exception, e: >+ except exception as e: > if e.errno != errno: > raise ExceptionWrongErrno(exception, errno, e.errno) > >@@ -96,9 +96,9 @@ > cn_ava3 = nss.AVA('cn', self.cn_name+'A') > ou_ava = nss.AVA('ou', self.ou_name) > >- self.assertEqual(cmp(cn_ava1, cn_ava2), 0) >- self.assertEqual(cmp(cn_ava1, ou_ava), -1) >- self.assertEqual(cmp(cn_ava1, cn_ava3), -1) >+ self.assertEqual(cn_ava1, cn_ava2) >+ self.assertTrue(cn_ava1 < ou_ava) >+ self.assertTrue(cn_ava1 < cn_ava3) > > def test_rdn_compare(self): > cn_rdn1 = nss.RDN(nss.AVA('cn', self.cn_name)) >@@ -106,9 +106,9 @@ > cn_rdn3 = nss.RDN(nss.AVA('cn', self.cn_name+'A')) > ou_rdn = nss.RDN(nss.AVA('ou', self.ou_name)) > >- self.assertEqual(cmp(cn_rdn1, cn_rdn2), 0) >- self.assertEqual(cmp(cn_rdn1, ou_rdn), -1) >- self.assertEqual(cmp(cn_rdn1, cn_rdn3), -1) >+ self.assertEqual(cn_rdn1, cn_rdn2) >+ self.assertTrue(cn_rdn1 < ou_rdn) >+ self.assertTrue(cn_rdn1 < cn_rdn3) > > def test_rdn_create(self): > cn_ava = nss.AVA('cn', self.cn_name) >diff -r e1b1afd424c3 test/test_cipher.py >--- a/test/test_cipher.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_cipher.py Mon Jul 28 12:32:46 2014 +0200 >@@ -25,20 +25,20 @@ > # If key was supplied use it, otherwise generate one > if key: > if verbose: >- print "using supplied key data" >- print "key:\n%s" % (key) >+ print("using supplied key data") >+ print("key:\n%s" % (key)) > key_si = nss.SecItem(nss.read_hex(key)) > sym_key = nss.import_sym_key(slot, mechanism, nss.PK11_OriginUnwrap, > nss.CKA_ENCRYPT, key_si) > else: > if verbose: >- print "generating key data" >+ print("generating key data") > sym_key = slot.key_gen(mechanism, None, slot.get_best_key_length(mechanism)) > > # If initialization vector was supplied use it, otherwise set it to None > if iv: > if verbose: >- print "supplied iv:\n%s" % (iv) >+ print("supplied iv:\n%s" % (iv)) > iv_data = nss.read_hex(iv) > iv_si = nss.SecItem(iv_data) > iv_param = nss.param_from_iv(mechanism, iv_si) >@@ -49,8 +49,8 @@ > iv_si = nss.SecItem(iv_data) > iv_param = nss.param_from_iv(mechanism, iv_si) > if verbose: >- print "generated %d byte initialization vector: %s" % \ >- (iv_length, nss.data_to_hex(iv_data, separator=":")) >+ print("generated %d byte initialization vector: %s" % \ >+ (iv_length, nss.data_to_hex(iv_data, separator=":"))) > else: > iv_param = None > >@@ -78,23 +78,24 @@ > > def test_string(self): > if verbose: >- print "Plain Text:\n%s" % (plain_text) >+ print("Plain Text:\n%s" % (plain_text)) > > # Encode the plain text by feeding it to cipher_op getting cipher text back. > # Append the final bit of cipher text by calling digest_final >- cipher_text = self.encoding_ctx.cipher_op(plain_text) >+ cipher_text = self.encoding_ctx.cipher_op(plain_text.encode('utf-8')) > cipher_text += self.encoding_ctx.digest_final() > > if verbose: >- print "Cipher Text:\n%s" % (nss.data_to_hex(cipher_text, separator=":")) >+ print("Cipher Text:\n%s" % (nss.data_to_hex(cipher_text, separator=":"))) > > # Decode the cipher text by feeding it to cipher_op getting plain text back. > # Append the final bit of plain text by calling digest_final > decoded_text = self.decoding_ctx.cipher_op(cipher_text) > decoded_text += self.decoding_ctx.digest_final() >+ decoded_text = decoded_text.decode('utf-8') > > if verbose: >- print "Decoded Text:\n%s" % (decoded_text) >+ print("Decoded Text:\n%s" % (decoded_text)) > > # Validate the encryption/decryption by comparing the decoded text with > # the original plain text, they should match. >@@ -106,11 +107,11 @@ > encrypted_filename = os.path.basename(in_filename) + ".encrypted" > decrypted_filename = os.path.basename(in_filename) + ".decrypted" > >- in_file = open(in_filename, "r") >- encrypted_file = open(encrypted_filename, "w") >+ in_file = open(in_filename, "rb") >+ encrypted_file = open(encrypted_filename, "wb") > > if verbose: >- print "Encrypting file \"%s\" to \"%s\"" % (in_filename, encrypted_filename) >+ print("Encrypting file \"%s\" to \"%s\"" % (in_filename, encrypted_filename)) > > # Encode the data read from a file in chunks > while True: >@@ -128,10 +129,10 @@ > > # Decode the encoded file in a similar fashion > if verbose: >- print "Decrypting file \"%s\" to \"%s\"" % (encrypted_filename, decrypted_filename) >+ print("Decrypting file \"%s\" to \"%s\"" % (encrypted_filename, decrypted_filename)) > >- encrypted_file = open(encrypted_filename, "r") >- decrypted_file = open(decrypted_filename, "w") >+ encrypted_file = open(encrypted_filename, "rb") >+ decrypted_file = open(decrypted_filename, "wb") > while True: > # Read a chunk of data until EOF, encrypt it and write the encrypted data > in_data = encrypted_file.read(chunk_size) >@@ -147,16 +148,16 @@ > > # Validate the encryption/decryption by comparing the decoded text with > # the original plain text, they should match. >- in_data = open(in_filename).read() >- encrypted_data = open(encrypted_filename).read() >- decrypted_data = open(decrypted_filename).read() >+ in_data = open(in_filename, "rb").read() >+ encrypted_data = open(encrypted_filename, "rb").read() >+ decrypted_data = open(decrypted_filename, "rb").read() > if decrypted_data != in_data: > result = 1 >- print "FAILED! decrypted_data != in_data" >+ print("FAILED! decrypted_data != in_data") > > if encrypted_data == in_data: > result = 1 >- print "FAILED! encrypted_data == in_data" >+ print("FAILED! encrypted_data == in_data") > > # clean up > os.unlink(encrypted_filename) >diff -r e1b1afd424c3 test/test_client_server.py >--- a/test/test_client_server.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_client_server.py Mon Jul 28 12:32:46 2014 +0200 >@@ -1,4 +1,5 @@ > #!/usr/bin/python >+from __future__ import print_function > > import os > import sys >@@ -8,6 +9,8 @@ > > import unittest > >+import six >+ > from nss.error import NSPRError > import nss.io as io > import nss.nss as nss >@@ -43,10 +46,10 @@ > return getpass.getpass("Enter password: "); > > def handshake_callback(sock): >- if verbose: print "handshake complete, peer = %s" % (sock.get_peer_name()) >+ if verbose: print("handshake complete, peer = %s" % (sock.get_peer_name())) > > def auth_certificate_callback(sock, check_sig, is_server, certdb): >- if verbose: print "auth_certificate_callback: check_sig=%s is_server=%s" % (check_sig, is_server) >+ if verbose: print("auth_certificate_callback: check_sig=%s is_server=%s" % (check_sig, is_server)) > cert_is_valid = False > > cert = sock.get_peer_certificate() >@@ -69,13 +72,13 @@ > # will be set to the error code matching the reason why the validation failed > # and the strerror attribute will contain a string describing the reason. > approved_usage = cert.verify_now(certdb, check_sig, intended_usage, *pin_args) >- except Exception, e: >- print >>sys.stderr, "auth_certificate_callback: %s" % e >+ except Exception as e: >+ print("auth_certificate_callback: %s" % e, file=sys.stderr) > cert_is_valid = False >- if verbose: print "Returning cert_is_valid = %s" % cert_is_valid >+ if verbose: print("Returning cert_is_valid = %s" % cert_is_valid) > return cert_is_valid > >- if verbose: print "approved_usage = %s" % ', '.join(nss.cert_usage_flags(approved_usage)) >+ if verbose: print("approved_usage = %s" % ', '.join(nss.cert_usage_flags(approved_usage))) > > # Is the intended usage a proper subset of the approved usage > if approved_usage & intended_usage: >@@ -85,7 +88,7 @@ > > # If this is a server, we're finished > if is_server or not cert_is_valid: >- if verbose: print "Returning cert_is_valid = %s" % cert_is_valid >+ if verbose: print("Returning cert_is_valid = %s" % cert_is_valid) > return cert_is_valid > > # Certificate is OK. Since this is the client side of an SSL >@@ -94,17 +97,17 @@ > # man-in-the-middle attacks. > > hostname = sock.get_hostname() >- if verbose: print "verifying socket hostname (%s) matches cert subject (%s)" % (hostname, cert.subject) >+ if verbose: print("verifying socket hostname (%s) matches cert subject (%s)" % (hostname, cert.subject)) > try: > # If the cert fails validation it will raise an exception > cert_is_valid = cert.verify_hostname(hostname) >- except Exception, e: >- print >>sys.stderr, "auth_certificate_callback: %s" % e >+ except Exception as e: >+ print("auth_certificate_callback: %s" % e, file=sys.stderr) > cert_is_valid = False >- if verbose: print "Returning cert_is_valid = %s" % cert_is_valid >+ if verbose: print("Returning cert_is_valid = %s" % cert_is_valid) > return cert_is_valid > >- if verbose: print "Returning cert_is_valid = %s" % cert_is_valid >+ if verbose: print("Returning cert_is_valid = %s" % cert_is_valid) > return cert_is_valid > > def client_auth_data_callback(ca_names, chosen_nickname, password, certdb): >@@ -113,23 +116,23 @@ > try: > cert = nss.find_cert_from_nickname(chosen_nickname, password) > priv_key = nss.find_key_by_any_cert(cert, password) >- if verbose: print "client cert:\n%s" % cert >+ if verbose: print("client cert:\n%s" % cert) > return cert, priv_key >- except NSPRError, e: >- print >>sys.stderr, "client_auth_data_callback: %s" % e >+ except NSPRError as e: >+ print("client_auth_data_callback: %s" % e, file=sys.stderr) > return False > else: > nicknames = nss.get_cert_nicknames(certdb, cert.SEC_CERT_NICKNAMES_USER) > for nickname in nicknames: > try: > cert = nss.find_cert_from_nickname(nickname, password) >- if verbose: print "client cert:\n%s" % cert >+ if verbose: print("client cert:\n%s" % cert) > if cert.check_valid_times(): > if cert.has_signer_in_ca_names(ca_names): > priv_key = nss.find_key_by_any_cert(cert, password) > return cert, priv_key >- except NSPRError, e: >- print >>sys.stderr, "client_auth_data_callback: %s" % e >+ except NSPRError as e: >+ print("client_auth_data_callback: %s" % e, file=sys.stderr) > return False > > # ----------------------------------------------------------------------------- >@@ -138,14 +141,14 @@ > > def client(request): > if use_ssl: >- if info: print "client: using SSL" >+ if info: print("client: using SSL") > ssl.set_domestic_policy() > > # Get the IP Address of our server > try: > addr_info = io.AddrInfo(hostname) >- except Exception, e: >- print >>sys.stderr, "client: could not resolve host address \"%s\"" % hostname >+ except Exception as e: >+ print("client: could not resolve host address \"%s\"" % hostname, file=sys.stderr) > return > > for net_addr in addr_info: >@@ -173,27 +176,27 @@ > sock = io.Socket(net_addr.family) > > try: >- if verbose: print "client trying connection to: %s" % (net_addr) >+ if verbose: print("client trying connection to: %s" % (net_addr)) > sock.connect(net_addr, timeout=io.seconds_to_interval(timeout_secs)) >- if verbose: print "client connected to: %s" % (net_addr) >+ if verbose: print("client connected to: %s" % (net_addr)) > break >- except Exception, e: >+ except Exception as e: > sock.close() >- print >>sys.stderr, "client: connection to: %s failed (%s)" % (net_addr, e) >+ print("client: connection to: %s failed (%s)" % (net_addr, e), file=sys.stderr) > > # Talk to the server > try: >- if info: print "client: sending \"%s\"" % (request) >+ if info: print("client: sending \"%s\"" % (request)) > sock.send(request + '\n') # newline is protocol record separator > buf = sock.readline() > if not buf: >- print >>sys.stderr, "client: lost connection" >+ print("client: lost connection", file=sys.stderr) > sock.close() > return > buf = buf.rstrip() # remove newline record separator >- if info: print "client: received \"%s\"" % (buf) >- except Exception, e: >- print >>sys.stderr, "client: %s" % e >+ if info: print("client: received \"%s\"" % (buf)) >+ except Exception as e: >+ print("client: %s" % e, file=sys.stderr) > try: > sock.close() > except: >@@ -202,15 +205,15 @@ > > try: > sock.shutdown() >- except Exception, e: >- print >>sys.stderr, "client: %s" % e >+ except Exception as e: >+ print("client: %s" % e, file=sys.stderr) > > try: > sock.close() > if use_ssl: > ssl.clear_session_cache() >- except Exception, e: >- print >>sys.stderr, "client: %s" % e >+ except Exception as e: >+ print("client: %s" % e, file=sys.stderr) > > return buf > >@@ -219,14 +222,14 @@ > # ----------------------------------------------------------------------------- > > def server(): >- if verbose: print "starting server:" >+ if verbose: print("starting server:") > > # Initialize > # Setup an IP Address to listen on any of our interfaces > net_addr = io.NetworkAddress(io.PR_IpAddrAny, port) > > if use_ssl: >- if info: print "server: using SSL" >+ if info: print("server: using SSL") > ssl.set_domestic_policy() > nss.set_password_callback(password_callback) > >@@ -263,7 +266,7 @@ > > # Bind to our network address and listen for clients > sock.bind(net_addr) >- if verbose: print "listening on: %s" % (net_addr) >+ if verbose: print("listening on: %s" % (net_addr)) > sock.listen() > > while True: >@@ -272,28 +275,28 @@ > if use_ssl: > client_sock.set_handshake_callback(handshake_callback) > >- if verbose: print "client connect from: %s" % (client_addr) >+ if verbose: print("client connect from: %s" % (client_addr)) > > while True: > try: > # Handle the client connection > buf = client_sock.readline() # newline is protocol record separator > if not buf: >- print >>sys.stderr, "server: lost lost connection to %s" % (client_addr) >+ print("server: lost lost connection to %s" % (client_addr), file=sys.stderr) > break > buf = buf.rstrip() # remove newline record separator > >- if info: print "server: received \"%s\"" % (buf) >+ if info: print("server: received \"%s\"" % (buf)) > reply = "{%s}" % buf # echo embedded inside braces >- if info: print "server: sending \"%s\"" % (reply) >+ if info: print("server: sending \"%s\"" % (reply)) > client_sock.send(reply + '\n') # send echo with record separator > > time.sleep(sleep_time) > client_sock.shutdown() > client_sock.close() > break >- except Exception, e: >- print >>sys.stderr, "server: %s" % e >+ except Exception as e: >+ print("server: %s" % e, file=sys.stderr) > break > break > >@@ -319,16 +322,16 @@ > wait_pid, wait_status = os.waitpid(pid, os.WNOHANG) > if wait_pid == 0: > os.kill(pid, signal.SIGKILL) >- except OSError, e: >+ except OSError as e: > if e.errno == errno.ECHILD: > pass # child already exited > else: >- print >>sys.stderr, "cleanup_server: %s" % e >+ print("cleanup_server: %s" % e, file=sys.stderr) > > class TestSSL(unittest.TestCase): > > def setUp(self): >- print >+ print() > self.server_pid = run_server() > > def tearDown(self): >@@ -339,7 +342,9 @@ > nss.nss_init(db_name) > reply = client(request) > nss.nss_shutdown() >- self.assertEqual("{%s}" % request, reply) >+ # TODO: depending on whether methods of server/client should/shouldn't >+ # return bytes, leave/remove the decoding/encoding here >+ self.assertEqual("{%s}" % request.encode('utf-8'), reply.decode('utf-8')) > > > if __name__ == '__main__': >diff -r e1b1afd424c3 test/test_digest.py >--- a/test/test_digest.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_digest.py Mon Jul 28 12:32:46 2014 +0200 >@@ -26,11 +26,11 @@ > hash_oid_name = nss.oid_str(hash_oid) > > if verbose: >- print 'running test %s: nss_digest_func=%s hash_oid=%s in_filename=%s' % \ >- (name, nss_digest_func.__name__, hash_oid_name, in_filename) >+ print('running test %s: nss_digest_func=%s hash_oid=%s in_filename=%s' % \ >+ (name, nss_digest_func.__name__, hash_oid_name, in_filename)) > > # read the data in from the file >- ref_data = open(in_filename).read() >+ ref_data = open(in_filename, 'rb').read() > > # Run the system hash function to get a reference result. > # Since we're testing the python-nss binding we assume >@@ -42,13 +42,13 @@ > # always convert our results to a hex string via nss.data_to_hex() > proc = subprocess.Popen([ref_cmd, in_filename], stdout=subprocess.PIPE) > status = proc.wait(); >- reference_digest = proc.stdout.read().split()[0] >+ reference_digest = proc.stdout.read().split()[0].decode('utf-8') > if verbose: >- print 'reference_digest\n%s' % (reference_digest) >+ print('reference_digest\n%s' % (reference_digest)) > > # Run the test with convenience digest function (e.g. nss.sha256_digest, etc.). > test_digest = nss.data_to_hex(nss_digest_func(ref_data), separator=None) >- if verbose: print 'nss %s\n%s' % (nss_digest_func.__name__, test_digest) >+ if verbose: print('nss %s\n%s' % (nss_digest_func.__name__, test_digest)) > > self.assertEqual(test_digest, reference_digest, > msg='nss %s test failed reference=%s test=%s' % \ >@@ -56,7 +56,7 @@ > > # Run the test using the generic hash_buf function specifying the hash algorithm. > test_digest = nss.data_to_hex(nss.hash_buf(hash_oid, ref_data), separator=None) >- if verbose: print 'nss.hash_buf %s\n%s' % (hash_oid_name, test_digest) >+ if verbose: print('nss.hash_buf %s\n%s' % (hash_oid_name, test_digest)) > > self.assertEqual(test_digest, reference_digest, > msg='nss.hash_buf %s test failed reference=%s test=%s' % \ >@@ -68,7 +68,7 @@ > context.digest_begin() > context.digest_op(ref_data) > test_digest = nss.data_to_hex(context.digest_final(), separator=None) >- if verbose: print 'nss.digest_context %s\n%s' % (hash_oid_name, test_digest) >+ if verbose: print('nss.digest_context %s\n%s' % (hash_oid_name, test_digest)) > > self.assertEqual(test_digest, reference_digest, > msg='nss.digest_context %s test failed reference=%s test=%s' % \ >@@ -76,7 +76,7 @@ > > # Run the test using the lowest level hashing functions by specifying the hash algorithm > # and feeding 'chunks' of data one at a time to be consumed. >- in_file = open(in_filename, 'r') >+ in_file = open(in_filename, 'rb') > context = nss.create_digest_context(hash_oid) > context.digest_begin() > while True: >@@ -86,7 +86,7 @@ > context.digest_op(in_data) > > test_digest = nss.data_to_hex(context.digest_final(), separator=None) >- if verbose: print 'chunked nss.digest_context %s\n%s' % (hash_oid_name, test_digest) >+ if verbose: print('chunked nss.digest_context %s\n%s' % (hash_oid_name, test_digest)) > > self.assertEqual(test_digest, reference_digest, > msg='chunked nss.digest_context %s test failed reference=%s test=%s' % \ >diff -r e1b1afd424c3 test/test_misc.py >--- a/test/test_misc.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_misc.py Mon Jul 28 12:32:46 2014 +0200 >@@ -4,6 +4,8 @@ > import os > import unittest > >+import six >+ > import nss.nss as nss > > #------------------------------------------------------------------------------- >@@ -26,7 +28,7 @@ > self.assertEqual(isinstance(i, int), True) > self.assertEqual(i, int_value) > >- self.assertEqual(isinstance(s, basestring), True) >+ self.assertEqual(isinstance(s, six.string_types), True) > self.assertEqual(s, str_value) > > self.assertEqual(isinstance(d, dict), True) >diff -r e1b1afd424c3 test/test_pkcs12.py >--- a/test/test_pkcs12.py Fri Jan 31 15:19:48 2014 -0500 >+++ b/test/test_pkcs12.py Mon Jul 28 12:32:46 2014 +0200 >@@ -79,7 +79,7 @@ > try: > stdout, stderr = run_cmd(cmd_args) > except CmdError as e: >- if e.returncode == 255 and 'not found' in e.stderr: >+ if e.returncode == 255 and 'not found' in e.stderr.decode('utf-8'): > return None > else: > raise >@@ -142,7 +142,7 @@ > nss.nss_shutdown() > > def test_read(self): >- if verbose: print "test_read" >+ if verbose: print("test_read") > create_pk12(cert_nickname, pk12_filename) > > slot = nss.get_internal_key_slot() >@@ -173,7 +173,7 @@ > self.assertEqual(cert_bag_count, 2) > > def test_import(self): >- if verbose: print "test_import" >+ if verbose: print("test_import") > delete_cert_from_db(cert_nickname) > self.assertEqual(get_cert_der_from_db(cert_nickname), None) > >@@ -199,15 +199,15 @@ > nss.nss_shutdown() > > def test_export(self): >- if verbose: print "test_export" >+ if verbose: print("test_export") > pkcs12_data = nss.pkcs12_export(cert_nickname, pk12_passwd) >- with open(exported_pk12_filename, 'w') as f: >+ with open(exported_pk12_filename, 'wb') as f: > f.write(pkcs12_data) > >- pk12_listing = list_pk12(pk12_filename) >+ pk12_listing = list_pk12(pk12_filename).decode('utf-8') > pk12_listing = strip_key_from_pk12_listing(pk12_listing) > >- exported_pk12_listing = list_pk12(exported_pk12_filename) >+ exported_pk12_listing = list_pk12(exported_pk12_filename).decode('utf-8') > exported_pk12_listing = strip_key_from_pk12_listing(exported_pk12_listing) > > self.assertEqual(pk12_listing, exported_pk12_listing)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 985290
: 921750