diff options
| author | Tomaz Solc <tomaz.solc@tablix.org> | 2015-11-17 11:47:25 +0100 |
|---|---|---|
| committer | Tomaz Solc <tomaz.solc@tablix.org> | 2015-11-17 11:47:25 +0100 |
| commit | dcf0f972de878319fd103ba28d3e6795bc34da00 (patch) | |
| tree | e687c7c66b75826e4780a944d7fcf050925d71dd | |
| parent | be04113429619571dc3f639bdf6db4f05a1e6fd3 (diff) | |
| download | unidecode-dcf0f972de878319fd103ba28d3e6795bc34da00.tar.gz | |
Rename unidecode_fast to unidecode_expect_ascii
Also, add unidecode_expect_nonascii. "unidecode" is now an alias for
"unidecode_expect_ascii"
| -rw-r--r-- | README.rst | 6 | ||||
| -rw-r--r-- | tests/test_unidecode.py | 6 | ||||
| -rw-r--r-- | unidecode/__init__.py | 12 |
3 files changed, 14 insertions, 10 deletions
@@ -55,10 +55,10 @@ Python 3.x):: 'Bei Jing ' For use cases where most strings passed are ASCII and only some occassional -non-ASCII ones, use the `unidecode_fast` function:: +non-ASCII ones, use the `unidecode_expect_ascii` function:: - >>> from unidecode import unidecode_fast - >>> unidecode_fast(u'Hello world!') + >>> from unidecode import unidecode_expect_ascii + >>> unidecode_expect_ascii(u'Hello world!') 'Hello world!' This function about five times faster if the string only contains ASCII diff --git a/tests/test_unidecode.py b/tests/test_unidecode.py index 0980fe3..1b72ef0 100644 --- a/tests/test_unidecode.py +++ b/tests/test_unidecode.py @@ -2,7 +2,7 @@ # vim:ts=4 sw=4 expandtab softtabstop=4 import unittest import sys -from unidecode import unidecode, unidecode_fast +from unidecode import unidecode, unidecode_expect_ascii import warnings # workaround for Python < 2.7 @@ -505,11 +505,11 @@ class TestUnidecode(unittest.TestCase): class TestUnidecodeFast(unittest.TestCase): def test_ascii_fast(self): - out = unidecode_fast(_u('Hello, World!')) + out = unidecode_expect_ascii(_u('Hello, World!')) self.assertEqual(out, 'Hello, World!') def test_nonascii_fast(self): - out = unidecode_fast(_u('příliš žluťoučký kůň pěl ďábelské ódy')) + out = unidecode_expect_ascii(_u('příliš žluťoučký kůň pěl ďábelské ódy')) self.assertEqual(out, 'prilis zlutoucky kun pel dabelske ody') diff --git a/unidecode/__init__.py b/unidecode/__init__.py index 94dd970..13fc950 100644 --- a/unidecode/__init__.py +++ b/unidecode/__init__.py @@ -28,7 +28,7 @@ def _warn_if_not_unicode(string): RuntimeWarning, 2) -def unidecode_fast(string): +def unidecode_expect_ascii(string): """ Try to transliterate using ASCII codec. If it fails, fall back to transliteration using the character tables. @@ -41,20 +41,24 @@ def unidecode_fast(string): try: bytestring = string.encode('ASCII') except UnicodeEncodeError: - return unidecode(string) + return _unidecode(string) if version_info[0] >= 3: return string else: return bytestring +def unidecode_expect_nonascii(string): + _warn_if_not_unicode(string) + return _unidecode(string) + +unidecode = unidecode_expect_ascii -def unidecode(string): +def _unidecode(string): """Transliterate an Unicode object into an ASCII string >>> unidecode(u"\u5317\u4EB0") "Bei Jing " """ - _warn_if_not_unicode(string) retval = [] |
