Update utils.str.format to support specifying an 'and' string.

This commit is contained in:
James Vega 2005-01-31 13:29:28 +00:00
parent 28cb5abc65
commit 9099a1a934

View File

@ -342,7 +342,7 @@ def format(s, *args, **kwargs):
f: float
b: form of the verb 'to be' (takes an int)
h: form of the verb 'to have' (takes an int)
L: commaAndify (takes a list of strings)
L: commaAndify (takes a list of strings or a tuple of ([strings], and))
p: pluralize (takes a string)
q: quoted (takes a string)
n: nItems (takes a 2-tuple of (n, item) or a 3-tuple of (n, between, item))
@ -365,7 +365,17 @@ def format(s, *args, **kwargs):
elif char == 'h':
return has(args.pop())
elif char == 'L':
return commaAndify(args.pop())
t = args.pop()
if isinstance(t, list):
return commaAndify(t)
elif isinstance(t, tuple) and len(t) == 2:
if not isinstance(t[0], list):
raise ValueError, 'Invalid list for %%L in format: %s' % t
if not isinstance(t[1], basestring):
raise ValueError, 'Invalid string for %%L in format: %s' % t
return commaAndify(t[0], And=t[1])
else:
raise ValueError, 'Invalid value for %%L in format: %s' % t
elif char == 'p':
return pluralize(args.pop())
elif char == 'q':