From d432d4b46a1733ec4fe7504426ace72d3a498605 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Sat, 29 Jan 2011 13:55:12 +0900 Subject: [PATCH] fix import path on pykakasi --- src/calibre/ebooks/unihandecode/__init__.py | 16 ++++++++-------- src/calibre/ebooks/unihandecode/jadecoder.py | 2 +- src/calibre/ebooks/unihandecode/pykakasi/h2a.py | 2 +- src/calibre/ebooks/unihandecode/pykakasi/j2h.py | 2 +- .../ebooks/unihandecode/pykakasi/jisyo.py | 4 ++-- src/calibre/ebooks/unihandecode/pykakasi/k2a.py | 2 +- .../ebooks/unihandecode/pykakasi/kakasi.py | 11 +++++------ 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/calibre/ebooks/unihandecode/__init__.py b/src/calibre/ebooks/unihandecode/__init__.py index c70f0d8a83..b42b19b6f4 100644 --- a/src/calibre/ebooks/unihandecode/__init__.py +++ b/src/calibre/ebooks/unihandecode/__init__.py @@ -16,24 +16,23 @@ Tranliterate the string from unicode characters to ASCII in Chinese and others. ''' -from calibre.ebooks.unihandecode.unidecoder import Unidecoder -from calibre.ebooks.unihandecode.jadecoder import Jadecoder -from calibre.ebooks.unihandecode.krdecoder import Krdecoder -from calibre.ebooks.unihandecode.vndecoder import Vndecoder - class Unihandecoder(object): preferred_encoding = None decoder = None def __init__(self, lang="zh", encoding='utf-8'): self.preferred_encoding = encoding - if lang is "ja": + if lang is u"ja": + from calibre.ebooks.unihandecode.jadecoder import Jadecoder self.decoder = Jadecoder() - elif lang is "kr": + elif lang is u"kr": + from calibre.ebooks.unihandecode.krdecoder import Krdecoder self.decoder = Krdecoder() - elif lang is "vn": + elif lang is u"vn": + from calibre.ebooks.unihandecode.vndecoder import Vndecoder self.decoder = Vndecoder() else: #zh and others + from calibre.ebooks.unihandecode.unidecoder import Unidecoder self.decoder = Unidecoder() def decode(self, text): @@ -55,5 +54,6 @@ def unidecode(text): ''' backword compatibility to unidecode ''' + from calibre.ebooks.unihandecode.unidecoder import Unidecoder decoder = Unihandecoder() return decoder.decode(text) diff --git a/src/calibre/ebooks/unihandecode/jadecoder.py b/src/calibre/ebooks/unihandecode/jadecoder.py index 7815a09738..0035a39681 100644 --- a/src/calibre/ebooks/unihandecode/jadecoder.py +++ b/src/calibre/ebooks/unihandecode/jadecoder.py @@ -34,7 +34,7 @@ class Jadecoder(Unidecoder): def decode(self, text): try: - dummy = text.encode('euc-jp') # test if text contains only Japanese and ASCII characters. + dummy = text.encode("eucjp") # test if text contains only Japanese and ASCII characters. result=self.kakasi.do(text) return re.sub('[^\x00-\x7f]', lambda x: self.replace_point(x.group()),result) except: diff --git a/src/calibre/ebooks/unihandecode/pykakasi/h2a.py b/src/calibre/ebooks/unihandecode/pykakasi/h2a.py index 4c398d07c7..d4da21ba42 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/h2a.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/h2a.py @@ -25,7 +25,7 @@ # * 02111-1307, USA. # */ -from jisyo import jisyo +from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo class H2a (object): diff --git a/src/calibre/ebooks/unihandecode/pykakasi/j2h.py b/src/calibre/ebooks/unihandecode/pykakasi/j2h.py index d0f6066446..c4adec2d0c 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/j2h.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/j2h.py @@ -25,7 +25,7 @@ # * 02111-1307, USA. # */ -from jisyo import jisyo +from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo import re class J2H (object): diff --git a/src/calibre/ebooks/unihandecode/pykakasi/jisyo.py b/src/calibre/ebooks/unihandecode/pykakasi/jisyo.py index d86c94b545..7f336a6273 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/jisyo.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/jisyo.py @@ -14,10 +14,10 @@ class jisyo (object): def __init__(self): if self.kanwadict is None: - dictpath = os.path.join('unihandecode','pykakasi','kanwadict2.db') + dictpath = os.path.join('calibre','ebooks','unihandecode','pykakasi','kanwadict2.db') self.kanwadict = anydbm.open(dictpath,'r') if self.itaijidict is None: - itaijipath = os.path.join('unihandecode','pykakasi','itaijidict2.pickle') + itaijipath = os.path.join('calibre','ebooks','unihandecode','pykakasi','itaijidict2.pickle') itaiji_pkl = open(itaijipath, 'rb') self.itaijidict = load(itaiji_pkl) diff --git a/src/calibre/ebooks/unihandecode/pykakasi/k2a.py b/src/calibre/ebooks/unihandecode/pykakasi/k2a.py index 61592fe920..409c67bc33 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/k2a.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/k2a.py @@ -25,7 +25,7 @@ # * 02111-1307, USA. # */ -from jisyo import jisyo +from calibre.ebooks.unihandecode.pykakasi.jisyo import jisyo class K2a (object): diff --git a/src/calibre/ebooks/unihandecode/pykakasi/kakasi.py b/src/calibre/ebooks/unihandecode/pykakasi/kakasi.py index 26a1b1f4de..94eba36e59 100644 --- a/src/calibre/ebooks/unihandecode/pykakasi/kakasi.py +++ b/src/calibre/ebooks/unihandecode/pykakasi/kakasi.py @@ -27,9 +27,9 @@ import re import sys, os -from j2h import J2H -from h2a import H2a -from k2a import K2a +from calibre.ebooks.unihandecode.pykakasi.j2h import J2H +from calibre.ebooks.unihandecode.pykakasi.h2a import H2a +from calibre.ebooks.unihandecode.pykakasi.k2a import K2a class kakasi(object): @@ -37,12 +37,11 @@ class kakasi(object): h2a = None k2a = None - def __init__(self, mode="-J2a -H2a -K2a"): - #now we don't allow mode selection + def __init__(self): self.j2h = J2H() self.h2a = H2a() self.k2a = K2a() - return + def do(self, text): otext = ''