| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,9 +68,9 @@ You can also specify an *errors* argument to ``unidecode()`` that determines | |||
| 68 | 68 | what Unidecode does with characters that are not present in its transliteration | |
| 69 | 69 | tables. The default is ``'ignore'`` meaning that Unidecode will ignore those | |
| 70 | 70 | characters (replace them with an empty string). ``'strict'`` will raise a | |
| 71 | - `UnidecodeError`. The exception object will contain an *index* attribute that | ||
| 71 | + ``UnidecodeError``. The exception object will contain an *index* attribute that | ||
| 72 | 72 | can be used to find the offending character. ``'replace'`` will replace them | |
| 73 | - with ``'?'`` (or another string, specified in the *replacement_char* argument). | ||
| 73 | + with ``'?'`` (or another string, specified in the *replace_str* argument). | ||
| 74 | 74 | ``'preserve'`` will keep the original, non-ASCII character in the string. Note | |
| 75 | 75 | that if ``'preserve'`` is used the string returned by ``unidecode()`` will not | |
| 76 | 76 | be ASCII-encodable! | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -514,8 +514,8 @@ def test_errors_replace(self): | |||
| 514 | 514 | self.assertEqual('test ? test', o) | |
| 515 | 515 | ||
| 516 | 516 | @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") | |
| 517 | - def test_errors_replace_char(self): | ||
| 518 | - o = self.unidecode(u"test \U000f0000 test", errors='replace', replace_char='[?] ') | ||
| 517 | + def test_errors_replace_str(self): | ||
| 518 | + o = self.unidecode(u"test \U000f0000 test", errors='replace', replace_str='[?] ') | ||
| 519 | 519 | self.assertEqual('test [?] test', o) | |
| 520 | 520 | ||
| 521 | 521 | @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ def _warn_if_not_unicode(string): | |||
| 37 | 37 | RuntimeWarning, 2) | |
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | - def unidecode_expect_ascii(string, errors='ignore', replace_char='?'): | ||
| 40 | + def unidecode_expect_ascii(string, errors='ignore', replace_str='?'): | ||
| 41 | 41 | """Transliterate an Unicode object into an ASCII string | |
| 42 | 42 | ||
| 43 | 43 | >>> unidecode(u"\u5317\u4EB0") | |
@@ -54,7 +54,7 @@ def unidecode_expect_ascii(string, errors='ignore', replace_char='?'): | |||
| 54 | 54 | errors specifies what to do with characters that have not been | |
| 55 | 55 | found in replacement tables. The default is 'ignore' which ignores | |
| 56 | 56 | the character. 'strict' raises an UnidecodeError. 'replace' | |
| 57 | - substitutes the character with replace_char (default is '?'). | ||
| 57 | + substitutes the character with replace_str (default is '?'). | ||
| 58 | 58 | 'preserve' keeps the original character. | |
| 59 | 59 | ||
| 60 | 60 | Note that if 'preserve' is used the returned string might not be | |
@@ -65,13 +65,13 @@ def unidecode_expect_ascii(string, errors='ignore', replace_char='?'): | |||
| 65 | 65 | try: | |
| 66 | 66 | bytestring = string.encode('ASCII') | |
| 67 | 67 | except UnicodeEncodeError: | |
| 68 | - return _unidecode(string, errors, replace_char) | ||
| 68 | + return _unidecode(string, errors, replace_str) | ||
| 69 | 69 | if version_info[0] >= 3: | |
| 70 | 70 | return string | |
| 71 | 71 | else: | |
| 72 | 72 | return bytestring | |
| 73 | 73 | ||
| 74 | - def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'): | ||
| 74 | + def unidecode_expect_nonascii(string, errors='ignore', replace_str='?'): | ||
| 75 | 75 | """Transliterate an Unicode object into an ASCII string | |
| 76 | 76 | ||
| 77 | 77 | >>> unidecode(u"\u5317\u4EB0") | |
@@ -81,11 +81,11 @@ def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'): | |||
| 81 | 81 | """ | |
| 82 | 82 | ||
| 83 | 83 | _warn_if_not_unicode(string) | |
| 84 | - return _unidecode(string, errors, replace_char) | ||
| 84 | + return _unidecode(string, errors, replace_str) | ||
| 85 | 85 | ||
| 86 | 86 | unidecode = unidecode_expect_ascii | |
| 87 | 87 | ||
| 88 | - def _get_repl_char(char): | ||
| 88 | + def _get_repl_str(char): | ||
| 89 | 89 | codepoint = ord(char) | |
| 90 | 90 | ||
| 91 | 91 | if codepoint < 0x80: | |
@@ -121,11 +121,11 @@ def _get_repl_char(char): | |||
| 121 | 121 | else: | |
| 122 | 122 | return None | |
| 123 | 123 | ||
| 124 | - def _unidecode(string, errors, replace_char): | ||
| 124 | + def _unidecode(string, errors, replace_str): | ||
| 125 | 125 | retval = [] | |
| 126 | 126 | ||
| 127 | 127 | for index, char in enumerate(string): | |
| 128 | - repl = _get_repl_char(char) | ||
| 128 | + repl = _get_repl_str(char) | ||
| 129 | 129 | ||
| 130 | 130 | if repl is None: | |
| 131 | 131 | if errors == 'ignore': | |
@@ -134,7 +134,7 @@ def _unidecode(string, errors, replace_char): | |||
| 134 | 134 | raise UnidecodeError('no replacement found for character %r ' | |
| 135 | 135 | 'in position %d' % (char, index), index) | |
| 136 | 136 | elif errors == 'replace': | |
| 137 | - repl = replace_char | ||
| 137 | + repl = replace_str | ||
| 138 | 138 | elif errors == 'preserve': | |
| 139 | 139 | repl = char | |
| 140 | 140 | else: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments