Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #32 from miurahr/universal_with_six
Browse files Browse the repository at this point in the history
Use six for compatibility
  • Loading branch information
miurahr authored Mar 25, 2018
2 parents c65193c + ff22a5b commit c33c514
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 41 deletions.
5 changes: 1 addition & 4 deletions pykakasi/a2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
# Copyright 2014 Hiroshi Miura <[email protected]>
#

try:
unicode
except: #Python3
unichr = chr
from six import unichr

class a2 (object):
_table_1 = [ u"\u3000",u"\uff01",u"\uff02",u"\uff03",u"\uff04",u"\uff05",u"\uff06",
Expand Down
6 changes: 1 addition & 5 deletions pykakasi/h2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
# * 02111-1307, USA.
# */

try:
xrange
except:
# Python3.x
xrange = range
from six.moves import xrange
from .jisyo import jisyo
from .exceptions import UnsupportedRomanRulesException

Expand Down
8 changes: 2 additions & 6 deletions pykakasi/h2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
# * 02111-1307, USA.
# */

try:
xrange
except:
# Python3.x
xrange = range
unichr = chr
from six import unichr
from six.moves import xrange

class H2K (object):

Expand Down
8 changes: 2 additions & 6 deletions pykakasi/itaiji.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
#
import re
from pkg_resources import resource_filename

try: # pragma: no cover
import cPickle as pickle
except: # pragma: no cover
import pickle
from six.moves.cPickle import load

class itaiji (object):

Expand All @@ -28,7 +24,7 @@ def __init__(self):
if self._itaijidict is None:
itaijipath = resource_filename(__name__, 'itaijidict2.pickle')
itaiji_pkl = open(itaijipath, 'rb')
(self._itaijidict, self._itaijidict_len) = pickle.load(itaiji_pkl)
(self._itaijidict, self._itaijidict_len) = load(itaiji_pkl)

def haskey(self, key):
return key in self._itaijidict
Expand Down
7 changes: 2 additions & 5 deletions pykakasi/jisyo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
# jisyo.py
#
# Copyright 2011,2014 Hiroshi Miura <[email protected]>
# Copyright 2011-2018 Hiroshi Miura <[email protected]>
from pkg_resources import resource_filename
try: #python2
from cPickle import load
except: #python3
from pickle import load
from six.moves.cPickle import load

class jisyo (object):
_dict = None
Expand Down
11 changes: 3 additions & 8 deletions pykakasi/k2h.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@
# * 02111-1307, USA.
# */

try:
xrange
except:
# Python3.x
xrange = range
unichr = chr
from six import unichr
from six.moves import range

class K2H (object):

Expand All @@ -46,11 +42,10 @@ def convert(self, text):
Hstr = ""
max_len = 0
r = len(text)
for x in xrange(r):
for x in range(r):
if self.isRegion(text[x]):
Hstr = Hstr + unichr(ord(text[x]) - self._diff)
max_len = max_len + 1
else:
break
return (Hstr, max_len)

6 changes: 3 additions & 3 deletions pykakasi/kanwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from zlib import decompress
from pkg_resources import resource_filename
from marshal import loads
import six

try:
import anydbm as dbm
Expand All @@ -30,11 +31,10 @@ def __init__(self):
self._kanwadict = dbm.open(dictpath,'r')

def load(self, char):
try:#python2
if six.PY2:
key = "%04x"%ord(unicode(char))
except:#python3
else:
key = "%04x"%ord(char)

try: #already exist?
table = self._jisyo_table[key]
except:
Expand Down
7 changes: 3 additions & 4 deletions pykakasi/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
----------------------------------------------------------
'''

import six

class sym2 (object):
# U3000 - 301F
# \u3000、。〃〄〆〈〉《》「」『』【】〒〓〔〕〖〗〘〙
Expand Down Expand Up @@ -93,10 +95,7 @@ def convert(self, text):
elif (0x03b1 <= c and c <= 0x03c9):
return self._table_4[c-0x03b1]
elif (0xff10 <= c and c < 0xff20):
try:
return unichr(c - 0xff10 + ord('0'))
except:
return chr(c - 0xff10 + ord('0'))
return six.unichr(c - 0xff10 + ord('0'))
else:
return None # pragma: no cover

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setuptools
wheel
nose
six

0 comments on commit c33c514

Please sign in to comment.