Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions eblib.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ def hook_end_keyword(self, container):
eb = EBTest(sys.argv[1])
if argc == 2:
for subbook in eb.subbook_list():
print "#%d. %s (%s)" % (subbook,
print ("#%d. %s (%s)" % (subbook,
eb.subbook_title(subbook),
eb.subbook_directory(subbook))
eb.subbook_directory(subbook)))
else:
eb.set_subbook(int(sys.argv[2]))
word = sys.argv[3]
Expand All @@ -274,9 +274,9 @@ def hook_end_keyword(self, container):
else:
func = eb.search_exactword
for hit in func(word):
print "-" * 40
print hit.heading()
print hit.text()
print ("-" * 40)
print (hit.heading())
print (hit.text())
eb_finalize_library()

if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions examples/chujiten.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# chujiten.py - an add-on program for xyaku
# Tamito KAJIYAMA <12 September 2001>
Expand Down
30 changes: 15 additions & 15 deletions examples/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
def get_content(book, appendix, hookset, folded, packed):
buffer = []
while 1:
data = eb_read_text(book, appendix, hookset, None)
data = eb_read_text(book, appendix, hookset, None).decode('euc-jp', errors='ignore')
if not data:
break
data = string.replace(data, "→§", "")
data = string.replace(data, "=→", "=")
data = string.replace(data, "⇒→", "⇒")
data = string.replace(data, "⇔→", "⇔")
data = data.replace("→§", "")
data = data.replace("=→", "=")
data = data.replace("⇒→", "⇒")
data = data.replace("⇔→", "⇔")
buffer.append(data)
data = string.join(buffer, "")
data = "".join(buffer)
if packed:
data = string.replace(data, "\n", "") + "\n"
data = data.replace("\n", "") + "\n"
if folded < 0:
return data
i = end = 0
Expand Down Expand Up @@ -150,29 +150,29 @@ def main():
(EB_HOOK_WIDE_FONT, hook_font)))
try:
eb_bind(book, dictdir)
except EBError, (error, message):
code = eb_error_string(error)
sys.stderr.write("Error: %s: %s\n" % (code, message))
except EBError as exc:
code = eb_error_string(exc.args[0])
sys.stderr.write("Error: %s: %s\n" % (code, exc.args[1]))
sys.exit(1)
eb_set_subbook(book, 0)
if len(args) == 0:
word = string.strip(sys.stdin.read())
word = sys.stdin.read().strip()
else:
word = string.join(args)
for word in make_candidates(word):
found = 0
eb_search_exactword(book, unicode(word,'utf-8').encode('euc-jp'))
eb_search_exactword(book, word.encode('euc-jp'))
while 1:
hitlist = eb_hit_list(book)
if not hitlist:
break
found = 1
for heading, text in hitlist:
eb_seek_text(book, text)
content = get_content(book, appendix, hookset, folded, packed)
if string.strip(content):
content = get_content(book, appendix, hookset, folded, packed).strip()
if content:
#sys.stdout.write(unicode(content,'euc-jp',errors='ignore'))
print(unicode(content,'euc-jp',errors='ignore'))
print(content)
if found:
break
eb_finalize_library()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
INCLUDE_DIRS = ['/usr/local/include', './src']
LIBRARY_DIRS = None

setup (name = 'ebmodule',
setup (name = 'eb',
version = '2.3',
description = 'A wrapper module of the EB library',
author = 'Tamito KAJIYAMA',
author_email = 'kajiyama@grad.sccs.chukyo-u.ac.jp',
url = 'http://pseudo.grad.sccs.chukyo-u.ac.jp/~kajiyama/python/',
py_modules = ['eblib'],
ext_modules = [
Extension('ebmodule', [EBMODULE_C],
Extension('eb', [EBMODULE_C],
include_dirs=INCLUDE_DIRS,
library_dirs=LIBRARY_DIRS,
#library_dirs=['/home/plateau/src/ebmodule-2.0/src/eb/.libs','/home/plateau/src/ebmodule-2.0/src/eb_lib/zlib/.libs'],
Expand Down
80 changes: 61 additions & 19 deletions src/ebmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ static char *version = ""
static PyObject *EBError;
static PyObject *CallbackContext;

#if PY_MAJOR_VERSION >= 3
#define PyInt_FromLong PyLong_FromLong
#endif

#if PY_MAJOR_VERSION >= 3
#define PyInt_Check PyLong_Check
#endif

#if PY_MAJOR_VERSION >= 3
#define PyInt_AsLong PyLong_AsLong
#endif

#if PY_MAJOR_VERSION >= 3
#define PyString_FromStringAndSize PyUnicode_FromStringAndSize
#endif

#if PY_MAJOR_VERSION >= 3
#define PyString_FromString PyUnicode_FromString
#endif

#if PY_MAJOR_VERSION >= 3
#define PyString_AsString PyUnicode_AsUTF8
#endif

#if PY_MAJOR_VERSION >= 3
#define PyString_Check PyUnicode_Check
#endif

#define error_object(status) \
Py_BuildValue("(is)", status, eb_error_message(status))

Expand Down Expand Up @@ -77,7 +105,7 @@ static struct PyMethodDef Book_methods[] = {
{NULL, NULL} /* sentinel */
};

staticforward PyTypeObject BookType;
static PyTypeObject BookType;

static BookObject *
book_new(void)
Expand All @@ -101,7 +129,7 @@ book_dealloc(BookObject *self)
static PyObject *
book_getattr(BookObject *self, char *name)
{
return Py_FindMethod(Book_methods, (PyObject *)self, name);
return PyObject_GenericGetAttr((PyObject *) self, PyString_FromString(name));
}

/*static PyMemberDef Book_members[] = {*/
Expand All @@ -113,8 +141,7 @@ static char BookType__doc__[] =
"A data structure for representing Book objects.";

static PyTypeObject BookType = {
PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
0, /*ob_size*/
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"EB_Book", /*tp_name*/
sizeof(BookObject), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand All @@ -123,7 +150,6 @@ static PyTypeObject BookType = {
(printfunc)0, /*tp_print*/
(getattrfunc)book_getattr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
Expand Down Expand Up @@ -154,7 +180,7 @@ static struct PyMethodDef Appendix_methods[] = {
{NULL, NULL} /* sentinel */
};

staticforward PyTypeObject AppendixType;
static PyTypeObject AppendixType;

static AppendixObject *
appendix_new(void)
Expand All @@ -178,15 +204,14 @@ appendix_dealloc(AppendixObject *self)
static PyObject *
appendix_getattr(AppendixObject *self, char *name)
{
return Py_FindMethod(Appendix_methods, (PyObject *)self, name);
return PyObject_GenericGetAttr((PyObject *) self, PyString_FromString(name));
}

static char AppendixType__doc__[] =
"A data structure for representing Appendix objects.";

static PyTypeObject AppendixType = {
PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
0, /*ob_size*/
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"EB_Appendix", /*tp_name*/
sizeof(AppendixObject), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand All @@ -195,7 +220,6 @@ static PyTypeObject AppendixType = {
(printfunc)0, /*tp_print*/
(getattrfunc)appendix_getattr,/*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
Expand Down Expand Up @@ -223,7 +247,7 @@ static struct PyMethodDef Hookset_methods[] = {
{NULL, NULL} /* sentinel */
};

staticforward PyTypeObject HooksetType;
static PyTypeObject HooksetType;

static HooksetObject *
hookset_new(void)
Expand All @@ -249,15 +273,14 @@ hookset_dealloc(HooksetObject *self)
static PyObject *
hookset_getattr(HooksetObject *self, char *name)
{
return Py_FindMethod(Hookset_methods, (PyObject *)self, name);
return PyObject_GenericGetAttr((PyObject *) self, PyString_FromString(name));
}

static char HooksetType__doc__[] =
"A data type for representing Hookset objects.";

static PyTypeObject HooksetType = {
PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
0, /*ob_size*/
PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0)
"EB_Hookset", /*tp_name*/
sizeof(HooksetObject), /*tp_basicsize*/
0, /*tp_itemsize*/
Expand All @@ -266,7 +289,6 @@ static PyTypeObject HooksetType = {
(printfunc)0, /*tp_print*/
(getattrfunc)hookset_getattr, /*tp_getattr*/
(setattrfunc)0, /*tp_setattr*/
(cmpfunc)0, /*tp_compare*/
(reprfunc)0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
Expand Down Expand Up @@ -522,7 +544,7 @@ py_eb_search_exactword(PyObject *self, PyObject *args)
const char *query;
int status;

if (!PyArg_ParseTuple(args, "O!s", &BookType, &book, &query))
if (!PyArg_ParseTuple(args, "O!y", &BookType, &book, &query))
return NULL;
status = eb_search_exactword(&book->book, query);
if (status != EB_SUCCESS) {
Expand Down Expand Up @@ -1700,7 +1722,7 @@ py_eb_read_text(PyObject *self, PyObject *args)
PyErr_SetObject(EBError, error_object(status));
return NULL;
}
return PyString_FromStringAndSize(buffer, len);
return PyBytes_FromStringAndSize(buffer, len);
}

static char py_eb_read_heading__doc__[] = "eb_read_heading(book, appendix, hookset) => string Read a data chunk of the entry heading. In order to read all the data chunks, applications have to call this function several times until it returns a null string. Raise EBError if failed.";
Expand Down Expand Up @@ -1731,7 +1753,7 @@ py_eb_read_heading(PyObject *self, PyObject *args)
PyErr_SetObject(EBError, error_object(status));
return NULL;
}
return PyString_FromStringAndSize(buffer, len);
return PyBytes_FromStringAndSize(buffer, len);
}

static char py_eb_read_rawtext__doc__[] = "eb_read_rawtext(book, int) => string Return the given number of raw characters read from the current file position. Raise EBError if failed.";
Expand All @@ -1754,7 +1776,7 @@ py_eb_read_rawtext(PyObject *self, PyObject *args)
PyErr_SetObject(EBError, error_object(status));
return NULL;
}
string = PyString_FromStringAndSize(buffer, len);
string = PyBytes_FromStringAndSize(buffer, len);
free(buffer);
return string;
}
Expand Down Expand Up @@ -3084,14 +3106,33 @@ static struct PyMethodDef eb_module_methods[] = {

static char eb_module_documentation[] = "";

#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC
PyInit_eb(void)
#else
void
initeb(void)
#endif
{
PyObject *m, *d;

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"eb", /* m_name */
eb_module_documentation, /* m_doc */
-1, /* m_size */
eb_module_methods /* m_methods */
};
#endif

#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
#else
/* Create the module and add the functions */
m = Py_InitModule4("eb", eb_module_methods, eb_module_documentation,
(PyObject*)NULL, PYTHON_API_VERSION);
#endif

/* Add some symbolic constants to the module */
d = PyModule_GetDict(m);
Expand Down Expand Up @@ -3320,4 +3361,5 @@ initeb(void)
/* Check for errors */
if (PyErr_Occurred())
Py_FatalError("can't initialize the eb module");
return m;
}