This commit is contained in:
Kovid Goyal 2019-03-13 13:31:24 +05:30
commit 7fd5940ef8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
8 changed files with 278 additions and 89 deletions

View File

@ -115,6 +115,8 @@ static PyObject* get_devices(PyObject *self, PyObject *args) {
return ans; return ans;
} }
static char libusb_doc[] = "Interface to libusb.";
static PyMethodDef libusb_methods[] = { static PyMethodDef libusb_methods[] = {
{"get_devices", get_devices, METH_VARARGS, {"get_devices", get_devices, METH_VARARGS,
"get_devices()\n\nGet the list of USB devices on the system." "get_devices()\n\nGet the list of USB devices on the system."
@ -123,26 +125,55 @@ static PyMethodDef libusb_methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
CALIBRE_MODINIT_FUNC #if PY_MAJOR_VERSION >= 3
initlibusb(void) { #define INITERROR return NULL
#define INITMODULE PyModule_Create(&libusb_module)
static struct PyModuleDef libusb_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "libusb",
/* m_doc */ libusb_doc,
/* m_size */ -1,
/* m_methods */ libusb_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_libusb(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("libusb", libusb_methods, libusb_doc)
CALIBRE_MODINIT_FUNC initlibusb(void) {
#endif
PyObject *m; PyObject *m;
// We deliberately use the default context. This is the context used by // We deliberately use the default context. This is the context used by
// libmtp and we want to ensure that the busnum/devnum numbers are the same // libmtp and we want to ensure that the busnum/devnum numbers are the same
// here and for libmtp. // here and for libmtp.
if(libusb_init(NULL) != 0) return; if(libusb_init(NULL) != 0) {
INITERROR;
}
Error = PyErr_NewException("libusb.Error", NULL, NULL); Error = PyErr_NewException("libusb.Error", NULL, NULL);
if (Error == NULL) return; if (Error == NULL) {
INITERROR;
}
cache = PyDict_New(); cache = PyDict_New();
if (cache == NULL) return; if (cache == NULL) {
INITERROR;
}
m = Py_InitModule3("libusb", libusb_methods, "Interface to libusb."); m = INITMODULE;
if (m == NULL) return; if (m == NULL) {
INITERROR;
}
PyModule_AddObject(m, "Error", Error); PyModule_AddObject(m, "Error", Error);
PyModule_AddObject(m, "cache", cache); PyModule_AddObject(m, "cache", cache);
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -204,43 +204,42 @@ static PyGetSetDef Device_getsetters[] = {
PyTypeObject wpd::DeviceType = { // {{{ PyTypeObject wpd::DeviceType = { // {{{
PyObject_HEAD_INIT(NULL) PyVarObject_HEAD_INIT(NULL, 0)
0, /*ob_size*/ /* tp_name */ "wpd.Device",
"wpd.Device", /*tp_name*/ /* tp_basicsize */ sizeof(Device),
sizeof(Device), /*tp_basicsize*/ /* tp_itemsize */ 0,
0, /*tp_itemsize*/ /* tp_dealloc */ (destructor)dealloc,
(destructor)dealloc, /*tp_dealloc*/ /* tp_print */ 0,
0, /*tp_print*/ /* tp_getattr */ 0,
0, /*tp_getattr*/ /* tp_setattr */ 0,
0, /*tp_setattr*/ /* tp_compare */ 0,
0, /*tp_compare*/ /* tp_repr */ 0,
0, /*tp_repr*/ /* tp_as_number */ 0,
0, /*tp_as_number*/ /* tp_as_sequence */ 0,
0, /*tp_as_sequence*/ /* tp_as_mapping */ 0,
0, /*tp_as_mapping*/ /* tp_hash */ 0,
0, /*tp_hash */ /* tp_call */ 0,
0, /*tp_call*/ /* tp_str */ 0,
0, /*tp_str*/ /* tp_getattro */ 0,
0, /*tp_getattro*/ /* tp_setattro */ 0,
0, /*tp_setattro*/ /* tp_as_buffer */ 0,
0, /*tp_as_buffer*/ /* tp_flags */ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/ /* tp_doc */ "Device",
"Device", /* tp_doc */ /* tp_traverse */ 0,
0, /* tp_traverse */ /* tp_clear */ 0,
0, /* tp_clear */ /* tp_richcompare */ 0,
0, /* tp_richcompare */ /* tp_weaklistoffset */ 0,
0, /* tp_weaklistoffset */ /* tp_iter */ 0,
0, /* tp_iter */ /* tp_iternext */ 0,
0, /* tp_iternext */ /* tp_methods */ Device_methods,
Device_methods, /* tp_methods */ /* tp_members */ 0,
0, /* tp_members */ /* tp_getset */ Device_getsetters,
Device_getsetters, /* tp_getset */ /* tp_base */ 0,
0, /* tp_base */ /* tp_dict */ 0,
0, /* tp_dict */ /* tp_descr_get */ 0,
0, /* tp_descr_get */ /* tp_descr_set */ 0,
0, /* tp_descr_set */ /* tp_dictoffset */ 0,
0, /* tp_dictoffset */ /* tp_init */ (initproc)init,
(initproc)init, /* tp_init */ /* tp_alloc */ 0,
0, /* tp_alloc */ /* tp_new */ 0,
0, /* tp_new */
}; // }}} }; // }}}

View File

@ -161,6 +161,8 @@ wpd_device_info(PyObject *self, PyObject *args) {
return ans; return ans;
} // }}} } // }}}
static char wpd_doc[] = "Interface to the WPD windows service.";
static PyMethodDef wpd_methods[] = { static PyMethodDef wpd_methods[] = {
{"init", wpd_init, METH_VARARGS, {"init", wpd_init, METH_VARARGS,
"init(name, major_version, minor_version, revision)\n\n Initializes this module. Call this method *only* in the thread in which you intend to use this module. Also remember to call uninit before the thread exits." "init(name, major_version, minor_version, revision)\n\n Initializes this module. Call this method *only* in the thread in which you intend to use this module. Also remember to call uninit before the thread exits."
@ -181,33 +183,60 @@ static PyMethodDef wpd_methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
#if PY_MAJOR_VERSION >= 3
#define INITERROR return NULL
#define INITMODULE PyModule_Create(&wpd_module)
static struct PyModuleDef wpd_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "wpd",
/* m_doc */ wpd_doc,
/* m_size */ -1,
/* m_methods */ wpd_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_wpd(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("wpd", wpd_methods, wpd_doc)
CALIBRE_MODINIT_FUNC initwpd(void) {
#endif
CALIBRE_MODINIT_FUNC
initwpd(void) {
PyObject *m; PyObject *m;
wpd::DeviceType.tp_new = PyType_GenericNew; wpd::DeviceType.tp_new = PyType_GenericNew;
if (PyType_Ready(&wpd::DeviceType) < 0) if (PyType_Ready(&wpd::DeviceType) < 0)
return; return;
m = Py_InitModule3("wpd", wpd_methods, "Interface to the WPD windows service."); m = INITMODULE;
if (m == NULL) return; if (m == NULL) {
INITERROR;
}
WPDError = PyErr_NewException("wpd.WPDError", NULL, NULL); WPDError = PyErr_NewException("wpd.WPDError", NULL, NULL);
if (WPDError == NULL) return; if (WPDError == NULL) {
INITERROR;
}
PyModule_AddObject(m, "WPDError", WPDError); PyModule_AddObject(m, "WPDError", WPDError);
NoWPD = PyErr_NewException("wpd.NoWPD", NULL, NULL); NoWPD = PyErr_NewException("wpd.NoWPD", NULL, NULL);
if (NoWPD == NULL) return; if (NoWPD == NULL) {
INITERROR;
}
PyModule_AddObject(m, "NoWPD", NoWPD); PyModule_AddObject(m, "NoWPD", NoWPD);
WPDFileBusy = PyErr_NewException("wpd.WPDFileBusy", NULL, NULL); WPDFileBusy = PyErr_NewException("wpd.WPDFileBusy", NULL, NULL);
if (WPDFileBusy == NULL) return; if (WPDFileBusy == NULL) {
INITERROR;
}
PyModule_AddObject(m, "WPDFileBusy", WPDFileBusy); PyModule_AddObject(m, "WPDFileBusy", WPDFileBusy);
Py_INCREF(&DeviceType); Py_INCREF(&DeviceType);
PyModule_AddObject(m, "Device", (PyObject *)&DeviceType); PyModule_AddObject(m, "Device", (PyObject *)&DeviceType);
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -457,6 +457,8 @@ end:
return ans; return ans;
} }
static char usbobserver_doc[] = "USB interface glue for OSX.";
static PyMethodDef usbobserver_methods[] = { static PyMethodDef usbobserver_methods[] = {
{"get_usb_devices", usbobserver_get_usb_devices, METH_VARARGS, {"get_usb_devices", usbobserver_get_usb_devices, METH_VARARGS,
"Get list of connected USB devices. Returns a list of tuples. Each tuple is of the form (vendor_id, product_id, bcd, manufacturer, product, serial number)." "Get list of connected USB devices. Returns a list of tuples. Each tuple is of the form (vendor_id, product_id, bcd, manufacturer, product, serial number)."
@ -483,7 +485,31 @@ static PyMethodDef usbobserver_methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
CALIBRE_MODINIT_FUNC #if PY_MAJOR_VERSION >= 3
initusbobserver(void) { #define INITERROR return NULL
(void) Py_InitModule("usbobserver", usbobserver_methods); #define INITMODULE PyModule_Create(&usbobserver_module)
static struct PyModuleDef usbobserver_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "usbobserver",
/* m_doc */ usbobserver_doc,
/* m_size */ -1,
/* m_methods */ usbobserver_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_usbobserver(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("usbobserver", usbobserver_methods, usbobserver_doc)
CALIBRE_MODINIT_FUNC initusbobserver(void) {
#endif
PyObject *m = NULL;
m = INITMODULE;
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -190,7 +190,9 @@ cpalmdoc_compress(PyObject *self, PyObject *args) {
return ans; return ans;
} }
static PyMethodDef cPalmdocMethods[] = { static char cPalmdoc_doc[] = "Compress and decompress palmdoc strings.";
static PyMethodDef cPalmdoc_methods[] = {
{"decompress", cpalmdoc_decompress, METH_VARARGS, {"decompress", cpalmdoc_decompress, METH_VARARGS,
"decompress(bytestring) -> decompressed bytestring\n\n" "decompress(bytestring) -> decompressed bytestring\n\n"
"Decompress a palmdoc compressed byte string. " "Decompress a palmdoc compressed byte string. "
@ -203,11 +205,34 @@ static PyMethodDef cPalmdocMethods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
CALIBRE_MODINIT_FUNC #if PY_MAJOR_VERSION >= 3
initcPalmdoc(void) { #define INITERROR return NULL
#define INITMODULE PyModule_Create(&cPalmdoc_module)
static struct PyModuleDef cPalmdoc_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "cPalmdoc",
/* m_doc */ cPalmdoc_doc,
/* m_size */ -1,
/* m_methods */ cPalmdoc_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_cPalmdoc(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("cPalmdoc", cPalmdoc_methods, cPalmdoc_doc)
CALIBRE_MODINIT_FUNC initcPalmdoc(void) {
#endif
PyObject *m; PyObject *m;
m = Py_InitModule3("cPalmdoc", cPalmdocMethods, m = INITMODULE;
"Compress and decompress palmdoc strings." if (m == NULL) {
); INITERROR;
if (m == NULL) return; }
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -208,8 +208,9 @@ static PyObject* remove_system_font(PyObject *self, PyObject *args) {
return Py_BuildValue("O", ok); return Py_BuildValue("O", ok);
} }
static static char winfonts_doc[] = "Windows font API";
PyMethodDef winfonts_methods[] = {
static PyMethodDef winfonts_methods[] = {
{"enum_font_families", enum_font_families, METH_VARARGS, {"enum_font_families", enum_font_families, METH_VARARGS,
"enum_font_families()\n\n" "enum_font_families()\n\n"
"Enumerate all regular (not italic/bold/etc. variants) font families on the system. Note there will be multiple entries for every family (corresponding to each charset of the font)." "Enumerate all regular (not italic/bold/etc. variants) font families on the system. Note there will be multiple entries for every family (corresponding to each charset of the font)."
@ -239,14 +240,32 @@ PyMethodDef winfonts_methods[] = {
}; };
CALIBRE_MODINIT_FUNC #if PY_MAJOR_VERSION >= 3
initwinfonts(void) { #define INITERROR return NULL
#define INITMODULE PyModule_Create(&winfonts_module)
static struct PyModuleDef winfonts_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "winfonts",
/* m_doc */ winfonts_doc,
/* m_size */ -1,
/* m_methods */ winfonts_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_winfonts(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("winfonts", winfonts_methods, winfonts_doc)
CALIBRE_MODINIT_FUNC initwinfonts(void) {
#endif
PyObject *m; PyObject *m;
m = Py_InitModule3( m = INITMODULE;
"winfonts", winfonts_methods, if (m == NULL) {
"Windows font API" INITERROR;
); }
if (m == NULL) return;
PyModule_AddIntMacro(m, FW_DONTCARE); PyModule_AddIntMacro(m, FW_DONTCARE);
PyModule_AddIntMacro(m, FW_THIN); PyModule_AddIntMacro(m, FW_THIN);
@ -263,4 +282,8 @@ initwinfonts(void) {
PyModule_AddIntMacro(m, FW_ULTRABOLD); PyModule_AddIntMacro(m, FW_ULTRABOLD);
PyModule_AddIntMacro(m, FW_HEAVY); PyModule_AddIntMacro(m, FW_HEAVY);
PyModule_AddIntMacro(m, FW_BLACK); PyModule_AddIntMacro(m, FW_BLACK);
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -387,8 +387,9 @@ winutil_strftime(PyObject *self, PyObject *args)
return NULL; return NULL;
} }
static char winutil_doc[] = "Defines utility methods to interface with windows.";
static PyMethodDef WinutilMethods[] = { static PyMethodDef winutil_methods[] = {
{"special_folder_path", winutil_folder_path, METH_VARARGS, {"special_folder_path", winutil_folder_path, METH_VARARGS,
"special_folder_path(csidl_id) -> path\n\n" "special_folder_path(csidl_id) -> path\n\n"
"Get paths to common system folders. " "Get paths to common system folders. "
@ -461,13 +462,33 @@ be a unicode string. Returns unicode strings."
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
CALIBRE_MODINIT_FUNC #if PY_MAJOR_VERSION >= 3
initwinutil(void) { #define INITERROR return NULL
#define INITMODULE PyModule_Create(&winutil_module)
static struct PyModuleDef winutil_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "winutil",
/* m_doc */ winutil_doc,
/* m_size */ -1,
/* m_methods */ winutil_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_winutil(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("winutil", winutil_methods, winutil_doc)
CALIBRE_MODINIT_FUNC initwinutil(void) {
#endif
PyObject *m; PyObject *m;
m = Py_InitModule3("winutil", WinutilMethods, m = INITMODULE;
"Defines utility methods to interface with windows."
); if (m == NULL) {
if (m == NULL) return; INITERROR;
}
PyModule_AddIntConstant(m, "CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS); PyModule_AddIntConstant(m, "CSIDL_ADMINTOOLS", CSIDL_ADMINTOOLS);
PyModule_AddIntConstant(m, "CSIDL_APPDATA", CSIDL_APPDATA); PyModule_AddIntConstant(m, "CSIDL_APPDATA", CSIDL_APPDATA);
@ -491,4 +512,7 @@ initwinutil(void) {
PyModule_AddIntConstant(m, "CSIDL_STARTUP", CSIDL_STARTUP); PyModule_AddIntConstant(m, "CSIDL_STARTUP", CSIDL_STARTUP);
PyModule_AddIntConstant(m, "CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP); PyModule_AddIntConstant(m, "CSIDL_COMMON_STARTUP", CSIDL_COMMON_STARTUP);
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }

View File

@ -393,6 +393,8 @@ exit:
// }}} // }}}
static char lzma_binding_doc[] = "Bindings to the LZMA (de)compression C code";
static PyMethodDef lzma_binding_methods[] = { static PyMethodDef lzma_binding_methods[] = {
{"decompress2", decompress2, METH_VARARGS, {"decompress2", decompress2, METH_VARARGS,
"Decompress an LZMA2 encoded block, of unknown compressed size (reads till LZMA2 EOS marker)" "Decompress an LZMA2 encoded block, of unknown compressed size (reads till LZMA2 EOS marker)"
@ -417,24 +419,54 @@ static PyMethodDef lzma_binding_methods[] = {
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
#if PY_MAJOR_VERSION >= 3
#define INITERROR return NULL
#define INITMODULE PyModule_Create(&lzma_binding_module)
static struct PyModuleDef lzma_binding_module = {
/* m_base */ PyModuleDef_HEAD_INIT,
/* m_name */ "lzma_binding",
/* m_doc */ lzma_binding_doc,
/* m_size */ -1,
/* m_methods */ lzma_binding_methods,
/* m_slots */ 0,
/* m_traverse */ 0,
/* m_clear */ 0,
/* m_free */ 0,
};
CALIBRE_MODINIT_FUNC PyInit_lzma_binding(void) {
#else
#define INITERROR return
#define INITMODULE Py_InitModule3("lzma_binding", lzma_binding_methods, lzma_binding_doc)
CALIBRE_MODINIT_FUNC initlzma_binding(void) {
#endif
CALIBRE_MODINIT_FUNC
initlzma_binding(void) {
PyObject *m = NULL, *preset_map = NULL, *temp = NULL; PyObject *m = NULL, *preset_map = NULL, *temp = NULL;
int i = 0; int i = 0;
init_crc_table(); init_crc_table();
LZMAError = PyErr_NewException("lzma_binding.error", NULL, NULL); LZMAError = PyErr_NewException("lzma_binding.error", NULL, NULL);
if (!LZMAError) return; if (!LZMAError) {
m = Py_InitModule3("lzma_binding", lzma_binding_methods, "Bindings to the LZMA (de)compression C code"); INITERROR;
if (m == NULL) return; }
m = INITMODULE;
if (m == NULL) {
INITERROR;
}
preset_map = PyTuple_New(10); preset_map = PyTuple_New(10);
if (preset_map == NULL) return; if (preset_map == NULL) {
INITERROR;
}
for (i = 0; i < 10; i++) { for (i = 0; i < 10; i++) {
temp = get_lzma2_properties(i); temp = get_lzma2_properties(i);
if (temp == NULL) return; if (temp == NULL) {
INITERROR;
}
PyTuple_SET_ITEM(preset_map, i, temp); PyTuple_SET_ITEM(preset_map, i, temp);
} }
PyModule_AddObject(m, "preset_map", preset_map); PyModule_AddObject(m, "preset_map", preset_map);
Py_INCREF(LZMAError); Py_INCREF(LZMAError);
PyModule_AddObject(m, "error", LZMAError); PyModule_AddObject(m, "error", LZMAError);
#if PY_MAJOR_VERSION >= 3
return m;
#endif
} }