mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-10-06 11:57:29 +02:00
Update utils.str.format to support specifying an 'and' string.
This commit is contained in:
parent
28cb5abc65
commit
9099a1a934
@ -342,7 +342,7 @@ def format(s, *args, **kwargs):
|
|||||||
f: float
|
f: float
|
||||||
b: form of the verb 'to be' (takes an int)
|
b: form of the verb 'to be' (takes an int)
|
||||||
h: form of the verb 'to have' (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)
|
p: pluralize (takes a string)
|
||||||
q: quoted (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))
|
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':
|
elif char == 'h':
|
||||||
return has(args.pop())
|
return has(args.pop())
|
||||||
elif char == 'L':
|
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':
|
elif char == 'p':
|
||||||
return pluralize(args.pop())
|
return pluralize(args.pop())
|
||||||
elif char == 'q':
|
elif char == 'q':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user