diff options
author | Tomaz Solc <tomaz.solc@tablix.org> | 2020-12-20 12:45:47 +0100 |
---|---|---|
committer | Tomaz Solc <tomaz.solc@tablix.org> | 2020-12-20 12:49:04 +0100 |
commit | c42c39d0f128c7e495b38deed0364da2fba48402 (patch) | |
tree | 24b0b68215a4cf7b22295835d5d9401b6da1f61c | |
parent | 3044bf6fd3fe5a186cbdc3f2831d700dc25b449d (diff) | |
download | unidecode-c42c39d0f128c7e495b38deed0364da2fba48402.tar.gz |
Rename argument replace_char -> replace_str
-rw-r--r-- | README.rst | 4 | ||||
-rw-r--r-- | tests/test_unidecode.py | 4 | ||||
-rw-r--r-- | unidecode/__init__.py | 18 |
3 files changed, 13 insertions, 13 deletions
@@ -68,9 +68,9 @@ You can also specify an *errors* argument to ``unidecode()`` that determines what Unidecode does with characters that are not present in its transliteration tables. The default is ``'ignore'`` meaning that Unidecode will ignore those characters (replace them with an empty string). ``'strict'`` will raise a -`UnidecodeError`. The exception object will contain an *index* attribute that +``UnidecodeError``. The exception object will contain an *index* attribute that can be used to find the offending character. ``'replace'`` will replace them -with ``'?'`` (or another string, specified in the *replacement_char* argument). +with ``'?'`` (or another string, specified in the *replace_str* argument). ``'preserve'`` will keep the original, non-ASCII character in the string. Note that if ``'preserve'`` is used the string returned by ``unidecode()`` will not be ASCII-encodable! diff --git a/tests/test_unidecode.py b/tests/test_unidecode.py index 42bb678..5fadf46 100644 --- a/tests/test_unidecode.py +++ b/tests/test_unidecode.py @@ -514,8 +514,8 @@ class BaseTestUnidecode(): self.assertEqual('test ? test', o) @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") - def test_errors_replace_char(self): - o = self.unidecode(u"test \U000f0000 test", errors='replace', replace_char='[?] ') + def test_errors_replace_str(self): + o = self.unidecode(u"test \U000f0000 test", errors='replace', replace_str='[?] ') self.assertEqual('test [?] test', o) @unittest.skipIf(sys.maxunicode < 0x10000, "narrow build") diff --git a/unidecode/__init__.py b/unidecode/__init__.py index 7b4bcfa..54c543d 100644 --- a/unidecode/__init__.py +++ b/unidecode/__init__.py @@ -37,7 +37,7 @@ def _warn_if_not_unicode(string): RuntimeWarning, 2) -def unidecode_expect_ascii(string, errors='ignore', replace_char='?'): +def unidecode_expect_ascii(string, errors='ignore', replace_str='?'): """Transliterate an Unicode object into an ASCII string >>> unidecode(u"\u5317\u4EB0") @@ -54,7 +54,7 @@ def unidecode_expect_ascii(string, errors='ignore', replace_char='?'): errors specifies what to do with characters that have not been found in replacement tables. The default is 'ignore' which ignores the character. 'strict' raises an UnidecodeError. 'replace' - substitutes the character with replace_char (default is '?'). + substitutes the character with replace_str (default is '?'). 'preserve' keeps the original character. 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='?'): try: bytestring = string.encode('ASCII') except UnicodeEncodeError: - return _unidecode(string, errors, replace_char) + return _unidecode(string, errors, replace_str) if version_info[0] >= 3: return string else: return bytestring -def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'): +def unidecode_expect_nonascii(string, errors='ignore', replace_str='?'): """Transliterate an Unicode object into an ASCII string >>> unidecode(u"\u5317\u4EB0") @@ -81,11 +81,11 @@ def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'): """ _warn_if_not_unicode(string) - return _unidecode(string, errors, replace_char) + return _unidecode(string, errors, replace_str) unidecode = unidecode_expect_ascii -def _get_repl_char(char): +def _get_repl_str(char): codepoint = ord(char) if codepoint < 0x80: @@ -121,11 +121,11 @@ def _get_repl_char(char): else: return None -def _unidecode(string, errors, replace_char): +def _unidecode(string, errors, replace_str): retval = [] for index, char in enumerate(string): - repl = _get_repl_char(char) + repl = _get_repl_str(char) if repl is None: if errors == 'ignore': @@ -134,7 +134,7 @@ def _unidecode(string, errors, replace_char): raise UnidecodeError('no replacement found for character %r ' 'in position %d' % (char, index), index) elif errors == 'replace': - repl = replace_char + repl = replace_str elif errors == 'preserve': repl = char else: |