mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Update iter_to_string with handling for list size of 2
This commit is contained in:
parent
0bd7860974
commit
e6733ba7ff
3 changed files with 13 additions and 9 deletions
|
|
@ -66,6 +66,7 @@ Up requirements to Django 3.2+
|
|||
into a more consistent structure for overriding. Expanded webpage documentation considerably.
|
||||
- REST API list-view was shortened (#2401). New CSS/HTML. Add ReDoc for API autodoc page.
|
||||
- Update and fix dummyrunner with cleaner code and setup.
|
||||
- Made `iter_to_str` format prettier strings
|
||||
|
||||
### Evennia 0.9.5 (2019-2020)
|
||||
|
||||
|
|
|
|||
|
|
@ -72,10 +72,11 @@ class TestListToString(TestCase):
|
|||
def test_list_to_string(self):
|
||||
self.assertEqual("1, 2, 3", utils.list_to_string([1, 2, 3], endsep=""))
|
||||
self.assertEqual('"1", "2", "3"', utils.list_to_string([1, 2, 3], endsep="", addquote=True))
|
||||
self.assertEqual("1, 2 and 3", utils.list_to_string([1, 2, 3]))
|
||||
self.assertEqual("1, 2, and 3", utils.list_to_string([1, 2, 3]))
|
||||
self.assertEqual(
|
||||
'"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
|
||||
'"1", "2", and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
|
||||
)
|
||||
self.assertEqual("1 and 2", utils.list_to_string([1, 2]))
|
||||
|
||||
|
||||
class TestMLen(TestCase):
|
||||
|
|
|
|||
|
|
@ -381,15 +381,13 @@ def iter_to_str(initer, endsep="and", addquote=False):
|
|||
>>> list_to_string([1,2,3], endsep='')
|
||||
'1, 2, 3'
|
||||
>>> list_to_string([1,2,3], ensdep='and')
|
||||
'1, 2 and 3'
|
||||
'1, 2, and 3'
|
||||
>>> list_to_string([1,2,3], endsep='and', addquote=True)
|
||||
'"1", "2" and "3"'
|
||||
'"1", "2", and "3"'
|
||||
```
|
||||
|
||||
"""
|
||||
if not endsep:
|
||||
endsep = ","
|
||||
else:
|
||||
if endsep:
|
||||
endsep = " " + endsep
|
||||
if not initer:
|
||||
return ""
|
||||
|
|
@ -397,11 +395,15 @@ def iter_to_str(initer, endsep="and", addquote=False):
|
|||
if addquote:
|
||||
if len(initer) == 1:
|
||||
return '"%s"' % initer[0]
|
||||
return ", ".join('"%s"' % v for v in initer[:-1]) + "%s %s" % (endsep, '"%s"' % initer[-1])
|
||||
elif len(initer) == 2:
|
||||
return '"%s"' % ('"%s "' % endsep).join(str(v) for v in initer)
|
||||
return ", ".join('"%s"' % v for v in initer[:-1]) + ",%s %s" % (endsep, '"%s"' % initer[-1])
|
||||
else:
|
||||
if len(initer) == 1:
|
||||
return str(initer[0])
|
||||
return ", ".join(str(v) for v in initer[:-1]) + "%s %s" % (endsep, initer[-1])
|
||||
elif len(initer) == 2:
|
||||
return ("%s " % endsep).join(str(v) for v in initer)
|
||||
return ", ".join(str(v) for v in initer[:-1]) + ",%s %s" % (endsep, initer[-1])
|
||||
|
||||
|
||||
# legacy aliases
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue