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

Rename argument replace_char -> replace_str · NorthIsUp/unidecode@c42c39d · GitHub

Repository navigation

Commit c42c39d

Browse files
committed
Rename argument replace_char -> replace_str
1 parent 3044bf6 commit c42c39d

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

‎README.rst‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ You can also specify an *errors* argument to ``unidecode()`` that determines
6868
what Unidecode does with characters that are not present in its transliteration
6969
tables. The default is ``'ignore'`` meaning that Unidecode will ignore those
7070
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
7272
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).
7474
``'preserve'`` will keep the original, non-ASCII character in the string. Note
7575
that if ``'preserve'`` is used the string returned by ``unidecode()`` will not
7676
be ASCII-encodable!

‎tests/test_unidecode.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ def test_errors_replace(self):
514514
self.assertEqual('test ? test', o)
515515

516516
@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='[?] ')
519519
self.assertEqual('test [?] test', o)
520520

521521
@unittest.skipIf(sys.maxunicode < 0x10000, "narrow build")

‎unidecode/__init__.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _warn_if_not_unicode(string):
3737
RuntimeWarning, 2)
3838

3939

40-
def unidecode_expect_ascii(string, errors='ignore', replace_char='?'):
40+
def unidecode_expect_ascii(string, errors='ignore', replace_str='?'):
4141
"""Transliterate an Unicode object into an ASCII string
4242
4343
>>> unidecode(u"\u5317\u4EB0")
@@ -54,7 +54,7 @@ def unidecode_expect_ascii(string, errors='ignore', replace_char='?'):
5454
errors specifies what to do with characters that have not been
5555
found in replacement tables. The default is 'ignore' which ignores
5656
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 '?').
5858
'preserve' keeps the original character.
5959
6060
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='?'):
6565
try:
6666
bytestring = string.encode('ASCII')
6767
except UnicodeEncodeError:
68-
return _unidecode(string, errors, replace_char)
68+
return _unidecode(string, errors, replace_str)
6969
if version_info[0] >= 3:
7070
return string
7171
else:
7272
return bytestring
7373

74-
def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'):
74+
def unidecode_expect_nonascii(string, errors='ignore', replace_str='?'):
7575
"""Transliterate an Unicode object into an ASCII string
7676
7777
>>> unidecode(u"\u5317\u4EB0")
@@ -81,11 +81,11 @@ def unidecode_expect_nonascii(string, errors='ignore', replace_char='?'):
8181
"""
8282

8383
_warn_if_not_unicode(string)
84-
return _unidecode(string, errors, replace_char)
84+
return _unidecode(string, errors, replace_str)
8585

8686
unidecode = unidecode_expect_ascii
8787

88-
def _get_repl_char(char):
88+
def _get_repl_str(char):
8989
codepoint = ord(char)
9090

9191
if codepoint < 0x80:
@@ -121,11 +121,11 @@ def _get_repl_char(char):
121121
else:
122122
return None
123123

124-
def _unidecode(string, errors, replace_char):
124+
def _unidecode(string, errors, replace_str):
125125
retval = []
126126

127127
for index, char in enumerate(string):
128-
repl = _get_repl_char(char)
128+
repl = _get_repl_str(char)
129129

130130
if repl is None:
131131
if errors == 'ignore':
@@ -134,7 +134,7 @@ def _unidecode(string, errors, replace_char):
134134
raise UnidecodeError('no replacement found for character %r '
135135
'in position %d' % (char, index), index)
136136
elif errors == 'replace':
137-
repl = replace_char
137+
repl = replace_str
138138
elif errors == 'preserve':
139139
repl = char
140140
else:

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL