rename fixPrint->_fix_print and add a docstring
This commit is contained in:
parent
1da06800cf
commit
8a4c75ee7f
3 changed files with 16 additions and 11 deletions
|
|
@ -2966,16 +2966,21 @@ def removeNonprintable(value):
|
|||
# expects raw-encoded string, not unicode
|
||||
return value.translate(None, NONPRINTABLE_CHARS)
|
||||
|
||||
def fixPrint(value):
|
||||
if not value:
|
||||
return str('')
|
||||
elif six.PY2 and isinstance(value, six.text_type):
|
||||
|
||||
def _fix_print(value):
|
||||
"""Fix a string so it is suitable to print
|
||||
|
||||
In python2, this means we return a utf8 encoded str
|
||||
In python3, this means we return unicode
|
||||
"""
|
||||
if six.PY2 and isinstance(value, six.text_type):
|
||||
return value.encode('utf8')
|
||||
elif six.PY3 and isinstance(value, six.binary_type):
|
||||
return value.decode('utf8')
|
||||
else:
|
||||
return value
|
||||
|
||||
|
||||
def fixEncoding(value, fallback='iso8859-15', remove_nonprintable=False):
|
||||
"""
|
||||
Convert value to a 'str' object encoded as UTF-8.
|
||||
|
|
|
|||
|
|
@ -62,8 +62,8 @@ def formatChangelog(entries):
|
|||
%s
|
||||
|
||||
""" % (_changelogDate(entry['date']),
|
||||
koji.fixPrint(entry['author']),
|
||||
koji.fixPrint(entry['text']))
|
||||
koji._fix_print(entry['author']),
|
||||
koji._fix_print(entry['text']))
|
||||
return result
|
||||
|
||||
DATE_RE = re.compile(r'(\d+)-(\d+)-(\d+)')
|
||||
|
|
|
|||
|
|
@ -46,15 +46,15 @@ class FixEncodingTestCase(unittest.TestCase):
|
|||
self.assertEqual(koji.fixEncoding(d, remove_nonprintable=True), b)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
def test_fixPrint(self, stdout):
|
||||
"""Test the fixPrint function"""
|
||||
def test_fix_print(self, stdout):
|
||||
"""Test the _fix_print function"""
|
||||
expected = ''
|
||||
for a, b in self.simple_values:
|
||||
if six.PY3:
|
||||
self.assertEqual(koji.fixPrint(b), a)
|
||||
self.assertEqual(koji._fix_print(b), a)
|
||||
else:
|
||||
self.assertEqual(koji.fixPrint(b), b)
|
||||
print(koji.fixPrint(b))
|
||||
self.assertEqual(koji._fix_print(b), b)
|
||||
print(koji._fix_print(b))
|
||||
if six.PY3:
|
||||
expected = expected + a + '\n'
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue