| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,10 +55,10 @@ Python 3.x):: | |||
| 55 | 55 | 'Bei Jing ' | |
| 56 | 56 | ||
| 57 | 57 | 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:: | ||
| 59 | 59 | ||
| 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!') | ||
| 62 | 62 | 'Hello world!' | |
| 63 | 63 | ||
| 64 | 64 | This function about five times faster if the string only contains ASCII | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | # vim:ts=4 sw=4 expandtab softtabstop=4 | |
| 3 | 3 | import unittest | |
| 4 | 4 | import sys | |
| 5 | - from unidecode import unidecode, unidecode_fast | ||
| 5 | + from unidecode import unidecode, unidecode_expect_ascii | ||
| 6 | 6 | import warnings | |
| 7 | 7 | ||
| 8 | 8 | # workaround for Python < 2.7 | |
@@ -505,11 +505,11 @@ def test_unicode_text_converter(self): | |||
| 505 | 505 | ||
| 506 | 506 | class TestUnidecodeFast(unittest.TestCase): | |
| 507 | 507 | def test_ascii_fast(self): | |
| 508 | - out = unidecode_fast(_u('Hello, World!')) | ||
| 508 | + out = unidecode_expect_ascii(_u('Hello, World!')) | ||
| 509 | 509 | self.assertEqual(out, 'Hello, World!') | |
| 510 | 510 | ||
| 511 | 511 | 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')) | ||
| 513 | 513 | self.assertEqual(out, 'prilis zlutoucky kun pel dabelske ody') | |
| 514 | 514 | ||
| 515 | 515 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ def _warn_if_not_unicode(string): | |||
| 28 | 28 | RuntimeWarning, 2) | |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | - def unidecode_fast(string): | ||
| 31 | + def unidecode_expect_ascii(string): | ||
| 32 | 32 | """ | |
| 33 | 33 | Try to transliterate using ASCII codec. If it fails, fall back to | |
| 34 | 34 | transliteration using the character tables. | |
@@ -41,20 +41,24 @@ def unidecode_fast(string): | |||
| 41 | 41 | try: | |
| 42 | 42 | bytestring = string.encode('ASCII') | |
| 43 | 43 | except UnicodeEncodeError: | |
| 44 | - return unidecode(string) | ||
| 44 | + return _unidecode(string) | ||
| 45 | 45 | if version_info[0] >= 3: | |
| 46 | 46 | return string | |
| 47 | 47 | else: | |
| 48 | 48 | return bytestring | |
| 49 | 49 | ||
| 50 | + def unidecode_expect_nonascii(string): | ||
| 51 | + _warn_if_not_unicode(string) | ||
| 52 | + return _unidecode(string) | ||
| 53 | + | ||
| 54 | + unidecode = unidecode_expect_ascii | ||
| 50 | 55 | ||
| 51 | - def unidecode(string): | ||
| 56 | + def _unidecode(string): | ||
| 52 | 57 | """Transliterate an Unicode object into an ASCII string | |
| 53 | 58 | ||
| 54 | 59 | >>> unidecode(u"\u5317\u4EB0") | |
| 55 | 60 | "Bei Jing " | |
| 56 | 61 | """ | |
| 57 | - _warn_if_not_unicode(string) | ||
| 58 | 62 | ||
| 59 | 63 | retval = [] | |
| 60 | 64 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments