FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Rename unidecode_fast to unidecode_expect_ascii · Python-Repository-Hub/unidecode@dcf0f97 · GitHub

Repository navigation

Commit dcf0f97

Browse files
committed
Rename unidecode_fast to unidecode_expect_ascii
Also, add unidecode_expect_nonascii. "unidecode" is now an alias for "unidecode_expect_ascii"
1 parent be04113 commit dcf0f97

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

‎README.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ Python 3.x)::
5555
'Bei Jing '
5656

5757
For use cases where most strings passed are ASCII and only some occassional
58-
non-ASCII ones, use the `unidecode_fast` function::
58+
non-ASCII ones, use the `unidecode_expect_ascii` function::
5959

60-
>>> from unidecode import unidecode_fast
61-
>>> unidecode_fast(u'Hello world!')
60+
>>> from unidecode import unidecode_expect_ascii
61+
>>> unidecode_expect_ascii(u'Hello world!')
6262
'Hello world!'
6363

6464
This function about five times faster if the string only contains ASCII

‎tests/test_unidecode.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# vim:ts=4 sw=4 expandtab softtabstop=4
33
import unittest
44
import sys
5-
from unidecode import unidecode, unidecode_fast
5+
from unidecode import unidecode, unidecode_expect_ascii
66
import warnings
77

88
# workaround for Python < 2.7
@@ -505,11 +505,11 @@ def test_unicode_text_converter(self):
505505

506506
class TestUnidecodeFast(unittest.TestCase):
507507
def test_ascii_fast(self):
508-
out = unidecode_fast(_u('Hello, World!'))
508+
out = unidecode_expect_ascii(_u('Hello, World!'))
509509
self.assertEqual(out, 'Hello, World!')
510510

511511
def test_nonascii_fast(self):
512-
out = unidecode_fast(_u('příliš žluťoučký kůň pěl ďábelské ódy'))
512+
out = unidecode_expect_ascii(_u('příliš žluťoučký kůň pěl ďábelské ódy'))
513513
self.assertEqual(out, 'prilis zlutoucky kun pel dabelske ody')
514514

515515

‎unidecode/__init__.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def _warn_if_not_unicode(string):
2828
RuntimeWarning, 2)
2929

3030

31-
def unidecode_fast(string):
31+
def unidecode_expect_ascii(string):
3232
"""
3333
Try to transliterate using ASCII codec. If it fails, fall back to
3434
transliteration using the character tables.
@@ -41,20 +41,24 @@ def unidecode_fast(string):
4141
try:
4242
bytestring = string.encode('ASCII')
4343
except UnicodeEncodeError:
44-
return unidecode(string)
44+
return _unidecode(string)
4545
if version_info[0] >= 3:
4646
return string
4747
else:
4848
return bytestring
4949

50+
def unidecode_expect_nonascii(string):
51+
_warn_if_not_unicode(string)
52+
return _unidecode(string)
53+
54+
unidecode = unidecode_expect_ascii
5055

51-
def unidecode(string):
56+
def _unidecode(string):
5257
"""Transliterate an Unicode object into an ASCII string
5358
5459
>>> unidecode(u"\u5317\u4EB0")
5560
"Bei Jing "
5661
"""
57-
_warn_if_not_unicode(string)
5862

5963
retval = []
6064

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL