1 # -*- coding: utf-8 -*-
3 """Module for testing kanjidic2.
5 Added when testing on Debian Lenny (stable). The latest Python is
6 2.5.2, which seems to not run the kanjidic2 console tester due to
7 relative import problems.
11 from __future__
import absolute_import
13 from jbparse
.kanjidic2
import Parser
, encode_or_else
17 if __name__
== "__main__":
19 # This is horrid, but it seems like in Python 2.x there doesn't
20 # exist an alternative accepted method that's transparent to the
23 sys
.setdefaultencoding(locale
.getpreferredencoding())
26 dfname
, args
= sys
.argv
[1], sys
.argv
[2:]
28 except (IndexError, AssertionError):
29 print _(u
"Syntax: %s <dict_file> <character [...]>") % sys
.argv
[0]
35 print _(u
"Could not create Kanjidic2Parser: %s") % unicode(e
)
47 print u
"%d characters found" % len(p
.characters
)
49 for i
, kanji
in enumerate(p
.search("".join(args
).decode(charset
))):
50 kstr
= encode_or_else(unicode(kanji
))
51 print _(u
"Entry %d:\n%s\n") % (i
+1, kstr
)