Skip to content

Commit

Permalink
small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lxyu committed Jun 4, 2014
1 parent 31a4ca0 commit b956dd1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: python
python:
- "2.6"
- "2.7"
- "3.2"
- "3.3"
# command to install dependencies
install: "python setup.py install"
# command to run tests
script: python test_pinyin.py
- 2.6
- 2.7
- 3.2
- 3.3
- pypy
install:
- pip install .
script:
- python test_pinyin.py
18 changes: 7 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
Pinyin
======

.. image:: https://badge.fury.io/py/pinyin.png
:target: http://badge.fury.io/py/pinyin
.. image:: http://img.shields.io/pypi/v/pinyin.svg?style=flat
:target: https://pypi.python.org/pypi/pinyin

.. image:: https://travis-ci.org/lxyu/pinyin.png?branch=master
.. image:: http://img.shields.io/travis/lxyu/pinyin/master.svg?style=flat
:target: https://travis-ci.org/lxyu/pinyin

.. image:: https://pypip.in/d/pinyin/badge.png
:target: https://crate.io/packages/pinyin/

.. image:: https://d2weczhvl823v0.cloudfront.net/lxyu/pinyin/trend.png
:alt: Bitdeli badge
:target: https://bitdeli.com/free
.. image:: http://img.shields.io/pypi/dm/pinyin.svg?style=flat
:target: https://pypi.python.org/pypi/pinyin


Translate chinese chars to pinyin based on Mandarin.dat
Expand All @@ -30,7 +26,7 @@ Usage
.. code:: python
>>> import pinyin
>>> pinyin.get(u'你好')
>>> pinyin.get('你好')
'nihao'
>>> pinyin.get_initial(u'你好')
>>> pinyin.get_initial('你好')
'n h'
7 changes: 3 additions & 4 deletions pinyin/compat.py → pinyin/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
str_type = unicode

def u(s):
if isinstance(s, unicode):
return s
else:
return unicode(s, "utf-8")
if not isinstance(s, unicode):
s = unicode(s, "utf-8")
return s

else:
str_type = str
Expand Down
4 changes: 2 additions & 2 deletions pinyin/cmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
from pinyin import get

from pinyin import compat
from pinyin._compat import u


def pinyin():
Expand All @@ -13,4 +13,4 @@ def pinyin():
parser.print_help()
return

print(get(compat.u(args.chars)))
print(get(u(args.chars)))
8 changes: 3 additions & 5 deletions pinyin/pinyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pinyin_dict[k] = v.lower().split(" ")[0][:-1]


from . import compat
from ._compat import u


def _pinyin_generator(chars):
Expand All @@ -27,8 +27,7 @@ def _pinyin_generator(chars):
def get(s, delimiter=''):
"""Return pinyin of string, the string must be unicode
"""
s = compat.u(s)
return delimiter.join(_pinyin_generator(s))
return delimiter.join(_pinyin_generator(u(s)))


def get_pinyin(s):
Expand All @@ -42,5 +41,4 @@ def get_pinyin(s):
def get_initial(s, delimiter=' '):
"""Return the 1st char of pinyin of string, the string must be unicode
"""
s = compat.u(s)
return delimiter.join([p[0] for p in _pinyin_generator(s)])
return delimiter.join([p[0] for p in _pinyin_generator(u(s))])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
package_data={'': ['LICENSE'], 'pinyin': ['Mandarin.dat'], },
entry_points={"console_scripts": ["pinyin = pinyin.cmd:pinyin", ]},
url='http://lxyu.github.io/pinyin/',
license=open('LICENSE').read(),
license="BSD",
long_description=open('README.rst').read(),
)
2 changes: 1 addition & 1 deletion test_pinyin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest

import pinyin
from pinyin.compat import u
from pinyin._compat import u


class BasicTestSuite(unittest.TestCase):
Expand Down

0 comments on commit b956dd1

Please sign in to comment.