Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Commit

Permalink
support py3k
Browse files Browse the repository at this point in the history
  • Loading branch information
mapix committed Jul 8, 2016
1 parent 0788c31 commit ba06618
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Usage

>>> from pinyin import Pinyin
>>> pinyin = Pinyin()
>>> ' '.join(p.get_pinyin('银行行长潘玮柏长了一头乌黑的白发, 睡觉睡的很晚, 道行很深', failure=''))
>>> ' '.join(pinyin.get_pinyin('银行行长潘玮柏长了一头乌黑的白发, 睡觉睡的很晚, 道行很深', failure=''))
>>> u'yin hang hang zhang pan wei bo zhang le yi tou wu hei de bai fa shui jiao shui de hen wan dao heng hen shen'

>>> for i in pinyin.get_pinyin_all('自行车'): print list(i)
Expand Down
9 changes: 5 additions & 4 deletions pinyin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import unicode_literals
from builtins import object
# -*- coding: utf-8 -*-

import jieba
Expand All @@ -6,13 +8,12 @@

from pinyin.config import FILE_WORDS, FILE_WORD, FILE_TERM, FILE_USER_DICT, CHINESE_RE
from pinyin.utils import Singleton
from future.utils import with_metaclass

__all__ = ["Pinyin"]


class Pinyin(object):

__metaclass__ = Singleton
class Pinyin(with_metaclass(Singleton, object)):

def __init__(self):

Expand Down Expand Up @@ -50,7 +51,7 @@ def get_pinyin(self, text, failure=None):
return [pinyin for pinyin_list in pinyin_list_iter for pinyin in pinyin_list]

def get_pinyin_all(self, text, max_return=None, failure=None):
if not isinstance(text, unicode):
if not isinstance(text, str):
text = text.decode("utf-8", "ignore")
rs = [self.word_to_pinyins.get(word, [word if failure is None else failure]) for word in text]
pinyin_all_iter = product(*rs)
Expand Down
1 change: 1 addition & 0 deletions pinyin/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
import re
from os.path import join, abspath, dirname

Expand Down
1 change: 1 addition & 0 deletions pinyin/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-


from __future__ import unicode_literals
class Singleton(type):

_instances = {}
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from setuptools import setup, find_packages

extra = {}
Expand All @@ -9,7 +10,7 @@

setup(
name='smart_pinyin',
version='0.3.2',
version='0.4.0',
description='Smart Chinese-to-Pinyin converter.',
author='mapix',
author_email='mapix.me@gmail.com',
Expand All @@ -21,6 +22,11 @@
'data/*',
]
},
classifiers=[
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
],
install_requires=['distribute', 'jieba'],
**extra
)

0 comments on commit ba06618

Please sign in to comment.